pgm to deals with one account holder info ( C programs)
1./*pgm to deals with one account holder info*/
#include<stdio.h>
#include<conio.h>
void main()
{
struct Bank
{
int acno;
char name[15];
float balance;
};
struct Bank info;
clrscr();
printf("enter acno,name,balance:");
scanf("%d %s %f",&info.acno,info.name,&info.balance);
printf("entered account info:");
printf("%d %s %f",info.acno,info.name,info.balance);
getch();
}
2. /*pgm to deals with one account holder info*/
#include<stdio.h>
#include<conio.h>
void main()
{
struct Bank
{
int acno;
char name[15];
float balance;
};
struct Bank info;
clrscr();
printf("enter acno,name,balance:");
scanf("%d %s %f",&info.acno,info.name,&info.balance);
printf("entered account info:");
printf("%d %s %f",info.acno,info.name,info.balance);
getch();
}
3. /*pgm to find area and peri of a circle
by using call by reference */
#include<stdio.h>
#include<conio.h>
void areaperi(float *a,float *p,float r);
void main()
{
float rad,area,peri;
clrscr();
printf("enter radius of a circle:");
scanf("%f",&rad);
areaperi(&area,&peri,rad);
printf("area of a circle:%f",area);
printf("\nperimeter of a circle:%f",peri);
getch();
}
void areaperi(float *a,float *p,float r)
{
*a=3.14*r*r;
*p=2*3.14*r;
}
4. /*pgm to perform arithametic operations*/
#include<stdio.h>
#include<conio.h>
int sum(int x,int y);
void sub(int,int);
int mul(int m,int);
float div(int n,int d);
int mod(int,int t);
void main()
{
int a=12,b=5,c,choice;
clrscr();
printf("1.add\n2.sub\n3.mul");
printf("\n4.div\n5.mod\n");
printf("enter ur choice:");
scanf("%d",&choice);
switch(choice)
{
case 1:
c=sum(a,b);
printf("addition=%d",c);
break;
case 2:
sub(12,5);
break;
case 3:
printf("product=%d",mul(a,b));
break;
case 4:
printf("%f",div(a,5));
break;
case 5:
c=mod(a,b);
printf("modulo=%d",c);
break;
default:
printf("invalid choice");
};
getch();
}
int mul(int m,int n)
{
return m*n;
}
int sum(int x,int y)
{
int z;
z=x+y;
return z;
}
void sub(int x,int y)
{
printf("\ndifference=%d",x-y);
}
float div(int n,int d)
{
return (float)n/d;
}
int mod(int s,int t)
{
int r;
r=s%t;
return (r);
}
5. /*pgm to deals with 10 students info
by using array of instances */
#include<stdio.h>
#include<conio.h>
struct student
{
int sno;
char sname[15];
int rank;
};
void main()
{
struct student stud[10];
int i,n;
clrscr();
printf("\nenter how many students ? ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter student %d sno,sname,rank:",i+1);
scanf("%d %s %d", &stud[i].sno,stud[i].sname,&stud[i].rank);
}
clrscr();
printf("SNO\tSNAME\tRANK");
for(i=0;i<n;i++)
{
printf("\n%d\t%s\t%d",stud[i].sno,stud[i].sname,stud[i].rank);
}
getch();
}/*pgm to deals with 10 students info
by using array of instances */
#include<stdio.h>
#include<conio.h>
struct student
{
int sno;
char sname[15];
int rank;
};
void main()
{
struct student stud[10];
int i,n;
clrscr();
printf("\nenter how many students ? ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter student %d sno,sname,rank:",i+1);
scanf("%d %s %d", &stud[i].sno,stud[i].sname,&stud[i].rank);
}
clrscr();
printf("SNO\tSNAME\tRANK");
for(i=0;i<n;i++)
{
printf("\n%d\t%s\t%d",stud[i].sno,stud[i].sname,stud[i].rank);
}
getch();
}/*pgm to deals with 10 students info
by using array of instances */
#include<stdio.h>
#include<conio.h>
struct student
{
int sno;
char sname[15];
int rank;
};
void main()
{
struct student stud[10];
int i,n;
clrscr();
printf("\nenter how many students ? ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter student %d sno,sname,rank:",i+1);
scanf("%d %s %d", &stud[i].sno,stud[i].sname,&stud[i].rank);
}
clrscr();
printf("SNO\tSNAME\tRANK");
for(i=0;i<n;i++)
{
printf("\n%d\t%s\t%d",stud[i].sno,stud[i].sname,stud[i].rank);
}
getch();
}
6. //pgm on array of pointers
#include<stdio.h>
#include<conio.h>
void main()
{
int *ptr[5];
int num[5]={11,22,33,44,55},i;
clrscr();
for(i=0;i<5;i++)
{
ptr[i]=&num[i];
}
printf("the array elements with indirect access:");
for(i=0;i<5;i++)
{
printf("\n%d",*ptr[i]);
}
getch();
}
7. //pgm on array of pointers
#include<stdio.h>
#include<conio.h>
void main()
{
int *ptr[5];
int num[5]={11,22,33,44,55},i;
clrscr();
for(i=0;i<5;i++)
{
ptr[i]=&num[i];
}
printf("the array elements with indirect access:");
for(i=0;i<5;i++)
{
printf("\n%d",*ptr[i]);
}
getch();
}
8. /*pgm to swap two values by using
call by ref */
#include<stdio.h>
#include<conio.h>
void swapr(int *x,int *y);
void main()
{
int a=10,b=20;
clrscr();
printf("\tBefore %d\t%d",a,b);
swapr(&a,&b);
printf("\n\tAfter %d\t%d",a,b);
getch();
}
void swapr(int *x,int *y)
{
int temp;
temp=*x;
*x=*y;
*y=temp;
// printf("\n%d\t%d",*x,*y);
}
9. /*pgm to swap two values by using
call by value */
#include<stdio.h>
#include<conio.h>
void swapv(int x,int y);
void main()
{
int a=10,b=20;
clrscr();
printf("Before Swap %d\t%d",a,b);
swapv(a,b);
printf("\nAfter Swap\t %d\t%d",a,b);
getch();
}
void swapv(int x,int y)
{
int temp;
temp=x;
x=y;
y=temp;
// printf("\n%d\t%d",x,y);
}
10. /*pgm to compare two strings with strcmp*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str1[15],str2[15];
int cmp;
clrscr();
puts("enter two strings:");
gets(str1);
gets(str2);
cmp=strcmp(str1,str2);
if(cmp==0)
{
puts("both strings are equal");
}
else if(cmp>0)
{
puts("str1 is greater than str2");
}
else
{
puts("str2 is greater than str1");
}
getch();
}
11. /*pgm on strcpy strcat strrev */
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str1[15];
char dest[15],src[15];
char first[30],second[15];
clrscr();
puts("enter a string to be reverse");
gets(str1);
puts("the reverse of a string");
puts(strrev(str1));
puts("enter a string to be copied");
gets(src);
strcpy(dest,src);
puts("the copied string");
puts(dest);
puts("enter first string:");
gets(first);
puts("enter second string:");
gets(second);
strcat(first,second);
puts("concatenated string");
puts(first);
getch();
}
12. /*pgm to copy string by using user defined function */
#include<stdio.h>
#include<conio.h>
void cpystr(char src[]);
void main()
{
char source[15];
clrscr();
puts("enter a string:");
gets(source);
cpystr(source);
cpystr("abcxyz");
getch();
}
void cpystr(char src[])
{
char dest[15];
int i=0;
while(src[i]!='\0')
{
dest[i]=src[i];
i++;
}
dest[i]='\0';
puts("the copied string");
puts(dest);
}
13. /*pgm on ternary operator*/
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
void main()
{
char str[15],ch;
int i=0;
clrscr();
puts("enter a string with mixed case");
gets(str);
while(str[i]!='\0')
{
ch=islower(str[i])?toupper(str[i]):tolower(str[i]);
printf("%c",ch);
i++;
}
getch();
}
14. /* pgm on calloc() */
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
void main()
{
int *ptr,n,i;
clrscr();
printf("enter no.of elements:");
scanf("%d",&n);
ptr=(int *)calloc(n,sizeof(int));
printf("the default values:");
for(i=0;i<n;i++)
{
printf("%d\t",*(ptr+i));
}
for(i=0;i<n;i++)
{
printf("\nenter %d value:",i+1);
scanf("%d",ptr+i);
}
printf("entered values:");
for(i=0;i<n;i++)
{
printf("%d\t",*(ptr+i));
}
getch();
}
15. /* pgm on malloc function */
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
void main()
{
int *ptr,n,i;
clrscr();
printf("enter no.of elements:");
scanf("%d",&n);
ptr=(int *)malloc(n*sizeof(int));
printf("the default values:");
for(i=0;i<n;i++)
{
printf("%d\t",*(ptr+i));
}
for(i=0;i<n;i++)
{
printf("\nenter %d value:",i+1);
scanf("%d",ptr+i);
}
printf("entered values:");
for(i=0;i<n;i++)
{
printf("%d\t",*(ptr+i));
}
getch();
}
16. /*pgm to deals with one employee info */
#include<stdio.h>
#include<conio.h>
struct employee
{
int eno;
char ename[15];
float esal;
};
void main()
{
struct employee emp;
clrscr();
printf("enter eno,ename,esal:");
scanf("%d %s %f",&emp.eno,emp.ename,&emp.esal);
printf("entered employee info:");
printf("%d %s %f",emp.eno,emp.ename,emp.esal);
getch();
}
17. /* employee info dma */
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
struct employee
{
int eno;
char ename[15];
};
void main()
{
struct employee *ptr;
int n,i;
clrscr();
printf("enter no.of employees:");
scanf("%d",&n);
ptr=(struct employee *)malloc(n*sizeof(struct employee));
for(i=0;i<n;i++)
{
printf("enter %d employee eno,ename:",i+1);
scanf("%d %s",(ptr+i)->eno,(ptr+i)->ename);
}
printf("entered employee info:");
printf("ENO\tENAME");
for(i=0;i<n;i++)
{
printf("\n%d\t%s",(ptr+i)->eno,(ptr+i)->ename);
}
getch();
}
18. /*pgm to find factorial of a number*/
#include<stdio.h>
#include<conio.h>
int factorial(int num);
void main()
{
int n,fact;
clrscr();
printf("enter a number:");
scanf("%d",&n);
fact=factorial(n);
printf("factorial of %d is %d",n,fact);
getch();
}
int factorial(int num)
{
int a=1,fac=1;
while(a<=num)
{
fac=fac*a;
a++;
}
return fac;
}
19. /*pgm to find factorial of number */
#include<stdio.h>
#include<conio.h>
void main()
{
int num,fact=1,a;
clrscr();
printf("enter a number:");
scanf("%d",&num);
a=num;
while(a>=1)
{
fact=fact*a;
a--;
}
printf("the factorial of %d is %d",num,fact);
getch();
}
20. /* febonacii series */
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,lt;
clrscr();
printf("enter how many no:");
scanf("%d",<);
a=0;
b=1;
printf("\n%d\n%d",a,b);
lt=lt-2;
while(lt>=1)
{
c=a+b;
printf("\n%d",c);
a=b;
b=c;
lt--;
}
getch();
}
21./* pgm on functions*/
#include<stdio.h>
#include<conio.h>
void abc();
void main()
{
void xyz();
clrscr();
abc();
xyz();
getch();
}
void abc()
{
printf("\nabc function");
}
void xyz()
{
printf("\nxyz function");
abc();
}
22. /* pgm to find length of a string */
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str[15];
int len;
clrscr();
puts("enter enter a string:");
gets(str);
len=strlen(str);
printf("the length of :%s is %d",str,len);
getch();
}
23. /*pgm to find the length without
using strlen*/
#include<stdio.h>
#include<conio.h>
void main()
{
char str[15];
int len=0;
clrscr();
puts("enter a string:");
gets(str);
while(str[len]!='\0')
{
len++;
}
printf("length of %s is %d",str,len);
getch();
}
24. /*pgm on strlwr and strupr */
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str1[15],str2[15];
clrscr();
puts("enter a string in upper case:");
gets(str1);
puts("the converted lower case string");
puts(strlwr(str1));
puts("enter a string in lower case:");
gets(str2);
puts("converted upper case string");
puts(strupr(str2));
getch();
}
25. /*pgm to multiply two matrices */
#include<stdio.h>
#include<conio.h>
void main()
{
int r1,c1,r2,c2,i,j,k;
int A[10][10],B[10][10],C[10][10];
clrscr();
printf("enter rows and cols of A:");
scanf("%d %d",&r1,&c1);
printf("enter rows and cols of B:");
scanf("%d %d",&r2,&c2);
if(c1==r2)
{
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
printf("enter A[%d][%d]:",i+1,j+1);
scanf("%d",&A[i][j]);
}
}
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
printf("enter B[%d][%d]:",i+1,j+1);
scanf("%d",&B[i][j]);
}
}
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
C[i][j]=0;
for(k=0;k<c1;k++)
{
C[i][j]=C[i][j]+A[i][k]*B[k][j];
}
}
}
printf("the resultant matrix:");
for(i=0;i<r1;i++)
{
printf("\n");
for(j=0;j<c2;j++)
{
printf("%d\t",C[i][j]);
}
}
}
else
{
printf("matrices cannot be multiplied");
}
getch();
}
27. /*pgm to add two matrices */
#include<stdio.h>
#include<conio.h>
void main()
{
int r1,c1,r2,c2,i,j;
int A[10][10],B[10][10],C[10][10];
clrscr();
printf("enter rows and cpls of A:");
scanf("%d %d",&r1,&c1);
printf("enter rows and cols of B:");
scanf("%d %d",&r2,&c2);
if(r1==r2&&c1==c2)
{
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
printf("enter A[%d][%d]:",i+1,j+1);
scanf("%d",&A[i][j]);
}
}
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
printf("enter B[%d][%d]:",i+1,j+1);
scanf("%d",&B[i][j]);
}
}
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
C[i][j]=A[i][j]+B[i][j];
}
}
for(i=0;i<r1;i++)
{
printf("\n");
for(j=0;j<c1;j++)
{
printf("%d\t",C[i][j]);
}
}
}
else
{
printf("matrices cannot be added");
}
getch();
}
28. //pgm to deals with an mca student marks
#include<stdio.h>
#include<conio.h>
void main()
{
int marks[3][2][5][2],i,j,k,l;
int subsum,semsum,yearsum,grandtotal=0;
clrscr();
for(i=0;i<3;i++)
{
yearsum=0;
for(j=0;j<2;j++)
{
semsum=0;
for(k=0;k<5;k++)
{
subsum=0;
for(l=0;l<2;l++)
{
printf("enter %d yr %d sem %d sub %d marks",i+1,j+1,k+1,l+1);
scanf("%d",&marks[i][j][k][l]);
subsum=subsum+marks[i][j][k][l];
}
semsum=semsum+subsum;
}
yearsum=yearsum+semsum;
}
grandtotal=grandtotal+yearsum;
}
printf("GRAND TOTAL=%d",grandtotal);
getch();
}
29. /* pgm to find min and max among 10 numbers */
#include>stdio.h>
#include<conio.h>
void main()
{
int num[10],min,max,i;
clrscr();
for(i=0;i<10;i++)
{
printf("enter num[%d]:",i+1);
scanf("%d",&num[i]);
}
min=max=num[0];
for(i=1;i<9;i++)
{
if(min>num[i])
min=num[i];
if(max<num[i])
max=num[i];
}
printf("\nminimum value:%d",min);
printf("\nmaximum value:%d",max);
getch();
}
29.
0 comments:
Comment here / Ask your Query !!