1) Swap Two Nos. Using Call by Value /: #Include #Include
1) Swap Two Nos. Using Call by Value /: #Include #Include
#include<stdio.h>
#include<conio.h>
main()
int x,y;
scanf("%d%d",&x,&y);
swap(x,y);
getch();
int temp;
temp=a;
a=b;
b=temp;
#include<stdio.h>
#include<conio.h>
main()
int x,y;
scanf("%d%d",&x,&y);
swap(&x,&y);
getch();
}
int temp;
temp=*a;
*a=*b;
*b=temp;
#include<stdio.h>
#include<conio.h>
int main()
char str[1000],ch;
int count=0,i;
scanf("%c",&ch);
for(i=0;str[i]!='\0';i++)
if(ch==str[i])
count++;
getch();
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
char str[20];
int i,len,flag=0;
scanf("%s",str);
len=strlen(str);
for(i=0;i<len/2;i++)
if(str[i]!=str[len-i-1])
flag=1;
break;
if(flag)
else
printf("\n\t %s is palindrome",str);
getch();
}
Run1:
Run2
Run3:
#include<stdio.h>
typedef struct
float real;
float imag;
}complex;
main()
complex cnum1,cnum2,sum;
scanf("%f%f",&cnum1.real,&cnum1.imag);
scanf("%f%f",&cnum2.real,&cnum2.imag);
sum.real=cnum1.real+cnum2.real;
sum.imag=cnum1.imag+cnum2.imag;
#include<stdio.h>
typedef struct complex
float real;
float imag;
}complex;
main()
complex n1,n2,result;
scanf("%f %f",&n1.real,&n1.imag);
scanf("%f %f",&n2.real,&n2.imag);
result=add(n1,n2);
}
complex add(complex n1,complex n2)
complex temp;
temp.real=n1.real+n2.real;
temp.imag=n1.imag+n2.imag;
return (temp);
/* 7) Array of structure */
#include<stdio.h>
#include<string.h>
struct student
{
int id;
char name[30];
float percentage;
};
int main()
int i;
record[0].id=1;
strcpy(record[0].name,"Raju");
record[0].percentage=86.5;
record[1].id=2;
strcpy(record[1].name,"Priyanka");
record[1].percentage=90.0;
record[2].id=3;
strcpy(record[2].name,"Ajay");
record[2].percentage=81.5;
int j;
for(i=0,j=1;i<3;i++,j++)
printf("Id: %d\n",record[i].id);
printf("Name: %s\n",record[i].name);
printf("Percentage: %f\n",record[i].percentage);
/* Array of structure2 */
#include<stdio.h>
#include<string.h>
struct student
int id;
char name[30];
float percentage;
};
int main()
int i;int j;
for(i=0;i<3;i++)
scanf("%d %s %f",&record[i].id,&record[i].name,&record[i].percentage);
for(i=0,j=1;i<3;i++,j++)
printf("Id: %d\n",record[i].id);
printf("Name: %s\n",record[i].name);
printf("Percentage: %f\n",record[i].percentage);
}