C Program Page 5

C Program Page 5

C Program and Page 5
To view other topics related to Computer. Click Here.

The array of 5 element in the main function and call a function to sort the given the array and the sorted list will be displayed in the main function

Main()

{

int n[5],I;

for(i=0;i<=4;i++)

{

printf(“Enter the number\n”);

scanf(“%d”,&n[i]);

}

sorting(n[0]);

printf(“The sorted list\n”);

for(i=0;i<=4;i++)

printf(“%d\n”,n[i]);

getch();

}

sorting (int *k)

{

int I,j,t;

for(i=0;i<4;i++)

for(j=i+1 ;j<=4 ;j++)

if(*(k+i)>* (k+j ))

{

t=*(k+I );

*(k+i)=*(k+j);

*(k+j )=t;

}

}

Program to find sum of 10 numbers

main()

{

int l[10] ,I ,j, s;

for(i=0; < 10 ;i++)

{

printf(“Enter a number \n”);

scanf(“%d”,&l[i]);

s= summation (&l[0]);

printf(“sum=%d\n”,s);

}

summation (int *p)

{

int j,sum=0;

for(i=0 ;j<10 ;j++)

sum +=*(p+j);

return( sum);

}

Program to find sum of square to two numbers

main()

{

int n,m,c;

printf(“Enter two number \n”);

scanf( “%d %d “,&n, &m);

c=addition (&n, &m);

printf(sum of squares =%d”,c);

}

addition ( int* p1 ,int *p2)

{

intr ;

r=* p1 *p2 +p2 *p2;

return ( r);

}

Palindrome

main()

{

char ch [10];

int I, l;

printf(“Enter string \n”);

gets ( ch);

l= strlen (ch);

printf(“In reverse order \n”);

for( i=l; i>=0; i- -)

printf(“%c\n”,ch [i]);

}

Declare pointer of pointer

Example

Main()

{int x=20;

int *px;

px =&x;

print{“%d”,*px);

}

Proto typing

Int *a ,b ,c;

B=10;

A=&b;

C=*a;

Pointer to function

Example

Main()

{

int display ( );

func-ptr =display ;

printf(“address of function display is %, fun-ptr”);

}

int display ( )

{

puts (“Wasim javed \n”);

}

Swap Function

(1) Function swap(int a, int b);

{

int temp;

temp =a;

a =b;

b= temp;

}

(2) function swap (int*a, int*bb);

{

int temp;

temp =*a;

*a =*b;

*b = temp;

}

Program to concatenate two strings

Main()

{

char source [ ] = “folks”, target[30] =”Hello”;

strcat( target ,source)

printf(source =%s\n”, source );

printf(“target =%s \n”,target);

}

Program to copy string

Main()

{

char source [ ] =”Hello”;

char target [20];

strcpy (target , source);

printf(%s %s “, source , target );

}

Program to show use of strlen.

Main()

{

char arr[ ] =”Wasim”

int l 1, l2;

l 1=strlen (arr);

l 2=strlen(Hello How are you\n”);

printf(“string =%s length =%d\n”,arr [11]);

printf(“string =%s length =%d\n”, Hello How are you [l 2]);

}

To remove a specified character.

Main()

{

char s[80];

int p;

printf(“Type string and position to removed \n”);

gets ( s );

scanf(“%d”,&p);

strcpy (&s[p], &[p+1] );

puts (s);

}

Write a program to read a sentence and print all lower case to upper case and upper case to lower case

Main()

{

char s[32];

int I,l;

printf(“Enter Sentence\n”);

gets( s);

l=strlen( s);

for(i=0 ;i<= l;i++)

{

if (( s[i]>=’a’ && (s[i]<=’z’)

s[i]- =32;

s[i]+=32;

}

puts(s);

}

Post a Comment

Previous Post Next Post