Friday, November 28, 2014

C using swap, array pro



Swap Numbers                     

#include
#include
void main ()
{
int b,r,n,r1,r2;
clrscr ();
printf ("Enter the Value: ");
scanf ("%d",&n);
r=n%10;
n=n/10;
r1=n%10;
n=n/10;
r2=n%10;
n=n/10;
b=(r*100)*(r2*10)+(r2);
printf ("%d%d%d",r,r1,r2);
getch ();
}

Sum of array

#include
#include
void main ()
{
int no[5],i,sum;
clrscr ();
for (i=0;i<=4;i++)
{
printf ("Enter Element: ");
scanf ("%d",&no[i]);
}
sum=no[0]+no[1]+no[2]+no[3]+no[4];
printf ("\nSum of five Elements: %d",sum);
getch ();
}

Sum, Sub, Product, Division

#include
#include
void main ()
{
int a,b,c,d,e,f;
clrscr();
printf ("Enter A: ");
scanf ("%d",&a);
printf ("Enter B: ");
scanf ("%d",&b);
c=a+b;
d=a-b;
e=a*b;
f=a/b;
printf ("\nSum is : %d",c);
printf ("\nSubtraction is : %d",d);
printf ("\nMultiplication is : %d",e);
printf ("\nDivision is : %d",f);
getch ();
}

Wap to reverse words

#include
#include
#include
const int opt = 50;
int main(){
int i=0,j=0,c=0,vali[opt] = {0};
char str1[opt],str2[opt]="",str3[opt]="",ch;
printf("please enter your sentence :");
gets(str1);
for(i=0;str1[i] != '\0';i++)

{
if(str1[i] == ' ')

{
vali[j+1] = i;
j++;
}
}
c = j;
for(i=0;i<=j && c!=0;i++)

{
strcat(str2,&str1[vali[c]+1]);
strcpy(&str1[vali[c]],str3);
strcat(str2," ");
c--;
}
strcat(str2,str1);
printf("\nyour reversed sentence is :");
puts(str2);
getch();
return 0;
}

No comments:

Post a Comment