Program For
#include<stdio.h>
#include<conio.h>
void creation();
void deposit();
void withdraw();
void bal();
int a=0,i = 101;
struct bank
{
int no;
char name[20];
float bal;
float dep;
}s[20];
void main()
{
int ch;
while(1)
{
clrscr();
printf("\n*********************");
printf("\n BANKING ");
printf("\n*********************");
printf("\n1-Creation");
printf("\n2-Deposit");
printf("\n3-Withdraw");
printf("\n4-Balance Enquiry");
printf("\n5-Exit");
printf("\nEnter your choice");
scanf("%d",&ch);
switch(ch)
{
case 1: creation();
break;
case 2: deposit();
break;
case 3: withdraw();
break;
case 4: bal();
break;
case 5: exit(0);
defalut: printf("Enter 1-5 only");
getch();
}
}
}
void creation()
{
printf("\n*************************************");
printf("\n ACCOUNT CREATION ");
printf("\n*************************************");
printf("\nYour Account Number is :%d",i);
s[a].no = i;
printf("\nEnter your Name:");
scanf("%s",s[a].name);
printf("\nYour Deposit is Minimum Rs.500");
s[a].dep=500;
a++;
i++;
getch();
}
void deposit()
{
int no,b=0,m=0;
float aa;
printf("\n*************************************");
printf("\n DEPOSIT ");
printf("\n*************************************");
printf("\nEnter your Account Number");
scanf("%d",&no);
for(b=0;b<i;b++)
{
if(s[b].no == no)
m = b;
}
if(s[m].no == no)
{
printf("\n Account Number : %d",s[m].no);
printf("\n Name : %s",s[m].name);
printf("\n Deposit : %f",s[m].dep);
printf("\n How Much Deposited Now:");
scanf("%f",&aa);
s[m].dep+=aa;
printf("\nDeposit Amount is :%f",s[m].dep);
getch();
}
else
{
printf("\nACCOUNT NUMBER IS INVALID");
getch();
}
}
void withdraw()
{
int no,b=0,m=0;
float aa;
printf("\n*************************************");
printf("\n WITHDRAW ");
printf("\n*************************************");
printf("\nEnter your Account Number");
scanf("%d",&no);
for(b=0;b<i;b++)
{
if(s[b].no == no)
m = b;
}
if(s[m].no == no)
{
printf("\n Account Number : %d",s[m].no);
printf("\n Name : %s",s[m].name);
printf("\n Deposit : %f",s[m].dep);
printf("\n How Much Withdraw Now:");
scanf("%f",&aa);
if(s[m].dep<aa+500)
{
printf("\nCANNOT WITHDRAW YOUR ACCOUNT HAS MINIMUM BALANCE");
getch();
}
else
{
s[m].dep-=aa;
printf("\nThe Balance Amount is:%f",s[m].dep);
}
}
else
{
printf("INVALID");
getch();
}
getch();
}
void bal()
{ int no,b=0,m=0;
float aa;
printf("\n*************************************");
printf("\n BALANCE ENQUIRY ");
printf("\n*************************************");
printf("\nEnter your Account Number");
scanf("%d",&no);
for(b=0;b<i;b++)
{
if(s[b].no == no)
m = b;
}
if(s[m].no==no)
{
printf("\n Account Number : %d",s[m].no);
printf("\n Name : %s",s[m].name);
printf("\n Deposit : %f",s[m].dep);
getch();
}
else
{
printf("INVALID");
getch();
}
}
C Program for factorial using recursion.
#include<stdio.h>
#include<conio.h>
int fact(int);
void main()
{
int a,b=0,c;
clrscr();
printf("Enter the N value:");
scanf("%d",&a);
while(a<0)
{printf("\n\Enter only positive number.\n");
printf("Enter N value:");
scanf("%d",&a);
}
b=fact(a);
printf("%d",b);
getch();
}
int fact(int x)
{
if(x==0)
{
return(1);}
1. Bank operation
2.Cos Value
3.Exponent Value
4. Recursion
5.Fibonacci series
6.String length
7.Replace A string
8.String Reverse
9.sine series
10.Salesman Problem
C Program For String Reverse.
#include<stdio.h>
#include<conio.h>
void main()
{
char n[50],j,i=0;
clrscr();
printf("OUTPUT\n");
printf("------");
printf("Enter String:\n");
printf("The Reverse Of The Given String is\n");
printf("**********************************");
while((n[i]=getchar())!='\n')i++;
for(j=i-1;j>=0;j--)
{
printf("%c",n[j]);
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
char n[50],j,i=0;
clrscr();
printf("OUTPUT\n");
printf("------");
printf("Enter String:\n");
printf("The Reverse Of The Given String is\n");
printf("**********************************");
while((n[i]=getchar())!='\n')i++;
for(j=i-1;j>=0;j--)
{
printf("%c",n[j]);
}
getch();
}
2)
C Program for salesman problem.
#include<stdio.h>
#include<conio.h>
void main()
{
int ss[50][50]={0};
int x,y,sale,i,a,b,t=0;
clrscr();
printf("\nEnter the How many sales man:");
scanf("%d",&sale);
printf("\nEnter the How many Items:");
scanf("%d",&i);
for(a=0;a<sale;a++)
{
for(b=0;b<i;b++)
{
printf("Sales man [%d] item [%d]:",a+1,b+1);
scanf("%d",&ss[a][b]);
}
}
clrscr();
printf("\n**********************************************************");
printf("\n*********************SALES REPORT*************************");
printf("\n**********************************************************\n");
printf("\n\t\t");
for(b=0;b<i;b++)
{
printf("item[%d] ",b+1);
}
printf(" Total");
for(a=0;a<sale;a++)
{
printf("\nSales man [%d]",a+1);
for(b=0;b<i;b++)
{
printf(" %d\t",ss[a][b]);
t+=ss[a][b];
}
printf(" %d",t);
t=0;
}
printf("\n********************************************************\n");
printf("TOTAL :");
printf("\t\t");
x=0,y=0;
for(a=0;a<i;a++)
{
for(b=0;b<sale;b++)
{
x=x+ss[b][a];
}
y=y+x;
printf(" %d\t",x);
x=0;
}
printf(" %d\t",y);
printf("\n********************************************************");
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int ss[50][50]={0};
int x,y,sale,i,a,b,t=0;
clrscr();
printf("\nEnter the How many sales man:");
scanf("%d",&sale);
printf("\nEnter the How many Items:");
scanf("%d",&i);
for(a=0;a<sale;a++)
{
for(b=0;b<i;b++)
{
printf("Sales man [%d] item [%d]:",a+1,b+1);
scanf("%d",&ss[a][b]);
}
}
clrscr();
printf("\n**********************************************************");
printf("\n*********************SALES REPORT*************************");
printf("\n**********************************************************\n");
printf("\n\t\t");
for(b=0;b<i;b++)
{
printf("item[%d] ",b+1);
}
printf(" Total");
for(a=0;a<sale;a++)
{
printf("\nSales man [%d]",a+1);
for(b=0;b<i;b++)
{
printf(" %d\t",ss[a][b]);
t+=ss[a][b];
}
printf(" %d",t);
t=0;
}
printf("\n********************************************************\n");
printf("TOTAL :");
printf("\t\t");
x=0,y=0;
for(a=0;a<i;a++)
{
for(b=0;b<sale;b++)
{
x=x+ss[b][a];
}
y=y+x;
printf(" %d\t",x);
x=0;
}
printf(" %d\t",y);
printf("\n********************************************************");
getch();
}
3)
C Program for sine series.
#include<stdio.h> #include<conio.h> #include<math.h> #define ACC 0.000001 #define PI 3.14 void main() { int x,i; float x1,x2,sine=0,term; clrscr(); printf("Enter the X value:"); scanf("%d",&x); x1=(x*PI)/180; x2=x1*x1; term=x1; sine=term; for(i=3;fabs(term)>ACC;i=i+2) { term = (x2*(-term))/(i*(i-1)); sine = sine+term; } printf("\n%f",sine); getch(); }
4)
Bank operation:
|
---|
#include<conio.h>
void creation();
void deposit();
void withdraw();
void bal();
int a=0,i = 101;
struct bank
{
int no;
char name[20];
float bal;
float dep;
}s[20];
void main()
{
int ch;
while(1)
{
clrscr();
printf("\n*********************");
printf("\n BANKING ");
printf("\n*********************");
printf("\n1-Creation");
printf("\n2-Deposit");
printf("\n3-Withdraw");
printf("\n4-Balance Enquiry");
printf("\n5-Exit");
printf("\nEnter your choice");
scanf("%d",&ch);
switch(ch)
{
case 1: creation();
break;
case 2: deposit();
break;
case 3: withdraw();
break;
case 4: bal();
break;
case 5: exit(0);
defalut: printf("Enter 1-5 only");
getch();
}
}
}
void creation()
{
printf("\n*************************************");
printf("\n ACCOUNT CREATION ");
printf("\n*************************************");
printf("\nYour Account Number is :%d",i);
s[a].no = i;
printf("\nEnter your Name:");
scanf("%s",s[a].name);
printf("\nYour Deposit is Minimum Rs.500");
s[a].dep=500;
a++;
i++;
getch();
}
void deposit()
{
int no,b=0,m=0;
float aa;
printf("\n*************************************");
printf("\n DEPOSIT ");
printf("\n*************************************");
printf("\nEnter your Account Number");
scanf("%d",&no);
for(b=0;b<i;b++)
{
if(s[b].no == no)
m = b;
}
if(s[m].no == no)
{
printf("\n Account Number : %d",s[m].no);
printf("\n Name : %s",s[m].name);
printf("\n Deposit : %f",s[m].dep);
printf("\n How Much Deposited Now:");
scanf("%f",&aa);
s[m].dep+=aa;
printf("\nDeposit Amount is :%f",s[m].dep);
getch();
}
else
{
printf("\nACCOUNT NUMBER IS INVALID");
getch();
}
}
void withdraw()
{
int no,b=0,m=0;
float aa;
printf("\n*************************************");
printf("\n WITHDRAW ");
printf("\n*************************************");
printf("\nEnter your Account Number");
scanf("%d",&no);
for(b=0;b<i;b++)
{
if(s[b].no == no)
m = b;
}
if(s[m].no == no)
{
printf("\n Account Number : %d",s[m].no);
printf("\n Name : %s",s[m].name);
printf("\n Deposit : %f",s[m].dep);
printf("\n How Much Withdraw Now:");
scanf("%f",&aa);
if(s[m].dep<aa+500)
{
printf("\nCANNOT WITHDRAW YOUR ACCOUNT HAS MINIMUM BALANCE");
getch();
}
else
{
s[m].dep-=aa;
printf("\nThe Balance Amount is:%f",s[m].dep);
}
}
else
{
printf("INVALID");
getch();
}
getch();
}
void bal()
{ int no,b=0,m=0;
float aa;
printf("\n*************************************");
printf("\n BALANCE ENQUIRY ");
printf("\n*************************************");
printf("\nEnter your Account Number");
scanf("%d",&no);
for(b=0;b<i;b++)
{
if(s[b].no == no)
m = b;
}
if(s[m].no==no)
{
printf("\n Account Number : %d",s[m].no);
printf("\n Name : %s",s[m].name);
printf("\n Deposit : %f",s[m].dep);
getch();
}
else
{
printf("INVALID");
getch();
}
}
5)
Cos Value
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define ACC 0.0001
#define PI 3.14
void main()
{
int x,i;
float x1,x2,cosz=0,term;
clrscr();
printf("Enter the X value:");
scanf("%d",&x);
x1=(x*PI)/180;
// printf("%f",cos(x1));
x2=x1*x1;
term=1;
cosz=term;
for(i=2;fabs(term)>ACC;i=i+2)
{
term = (x2*(-term))/(i*(i-1));
cosz = cosz+term;
}
printf("\nNew Value%f",cosz);
getch();
}
#include<conio.h>
#include<math.h>
#define ACC 0.0001
#define PI 3.14
void main()
{
int x,i;
float x1,x2,cosz=0,term;
clrscr();
printf("Enter the X value:");
scanf("%d",&x);
x1=(x*PI)/180;
// printf("%f",cos(x1));
x2=x1*x1;
term=1;
cosz=term;
for(i=2;fabs(term)>ACC;i=i+2)
{
term = (x2*(-term))/(i*(i-1));
cosz = cosz+term;
}
printf("\nNew Value%f",cosz);
getch();
}
6)
Exponent values :
#include<stdio.h>
#include<conio.h> void main() { double term=1,expo=1; float x; int i; clrscr(); printf("Enter the exp value of x: "); scanf("%f",&x); for(i=1;term>=0.00001;i++) { term *= x/i; expo+=term; } printf("\Our Exp = %f %f\n",x,expo); getch(); } |
---|
#include<stdio.h>
#include<conio.h>
int fact(int);
void main()
{
int a,b=0,c;
clrscr();
printf("Enter the N value:");
scanf("%d",&a);
while(a<0)
{printf("\n\Enter only positive number.\n");
printf("Enter N value:");
scanf("%d",&a);
}
b=fact(a);
printf("%d",b);
getch();
}
int fact(int x)
{
if(x==0)
{
return(1);}
8)
C Program for String Length.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,c=0;
char a[50];
clrscr();
printf("OUTPUT\n");
printf("------");
printf("\n\n");
printf("Please Enter a String:\n");
printf("*********************");
scanf("%s",a);
for(i=0;a[i]!='\0';i++)
{
c=c+1;
}
printf("\n\n");
printf("Length Of The Given String is=%d\n",c);
printf("*****************************");
getch();}
#include<stdio.h>
#include<conio.h>
void main()
{
int i,c=0;
char a[50];
clrscr();
printf("OUTPUT\n");
printf("------");
printf("\n\n");
printf("Please Enter a String:\n");
printf("*********************");
scanf("%s",a);
for(i=0;a[i]!='\0';i++)
{
c=c+1;
}
printf("\n\n");
printf("Length Of The Given String is=%d\n",c);
printf("*****************************");
getch();}
9)
C Program for Prime Number Generation.
#include<stdio.h>
#include<conio.h>
void main()
{
int n,j,a=0,i;
clrscr();
printf(" Please Enter a number :");
scanf("%d",&n);
printf("\n\n");
printf("OUTPUT:\n");
printf("------");
printf("\n\n");
printf("The Prime Number series is\n");
printf("**************************");
for(j=1;j<=n;j++)
{
for(i=2;i<j;i++)
{
if(j%i==0)
{
a=1;
goto x;
}
}
if((a==0)&&(j!=1))
{
printf("\n%d",j);
}
x:
a=0;
}
getch();}
#include<stdio.h>
#include<conio.h>
void main()
{
int n,j,a=0,i;
clrscr();
printf(" Please Enter a number :");
scanf("%d",&n);
printf("\n\n");
printf("OUTPUT:\n");
printf("------");
printf("\n\n");
printf("The Prime Number series is\n");
printf("**************************");
for(j=1;j<=n;j++)
{
for(i=2;i<j;i++)
{
if(j%i==0)
{
a=1;
goto x;
}
}
if((a==0)&&(j!=1))
{
printf("\n%d",j);
}
x:
a=0;
}
getch();}
10)
C Program For REPLACE OF STRING.
#include<stdio.h>
#include<conio.h>
void main()
{
char a[100],b[100],c[100],d[100];
int i,j,k,l1,l2,l3,m,count=-1;
clrscr();
printf("\t\t\t REPLACE OF STRING ");
printf("\n\t\t\t ********************");
printf("\n\n\tINPUT");
printf("\n\t*******");
printf("\n\nEnter the first String:");
scanf("%[a-z ]s",a);
printf("\nEnter the substring:");
scanf("%s",b);
printf("\nEnter the replace string:");
scanf("%s",c);
printf("\n\n\tOUTPUT");
printf("\n\t*******");
for(i=0;a[i]!='\0';i++)
l1=i;
for(i=0;b[i]!='\0';i++)
l2=i;
for(i=0;c[i]!='\0';i++)
l3=i;
for(i=0;a[i]!='\0';i++)
d[i]=a[i];
d[i]='\0';
if(l1>=l2)
{
do
{
for(i=0,j=0;a[i]!='\0' && b[j]!='\0';i++ )
{
if(a[i]==b[j])
{
count++;
j++;
}
else
{
count=-1;
if(j>0)
i--;
j=0;
}
}
m=i;
if(count==l2)
{
i=i-j;
for(k=0;c[k]!='\0';i++,k++)
a[i]=c[k];
if(l2!=l3)
{
for( ;d[m]!='\0';m++,i++)
{
a[i]=d[m];
}
}
//a[i]='\0';
//printf("\nReplaced string:%s",a);
}
else
break;
//printf("\nThe substring is not there");
}while(a[i]!='\0');
printf("\nReplaced string:%s",a);
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
char a[100],b[100],c[100],d[100];
int i,j,k,l1,l2,l3,m,count=-1;
clrscr();
printf("\t\t\t REPLACE OF STRING ");
printf("\n\t\t\t ********************");
printf("\n\n\tINPUT");
printf("\n\t*******");
printf("\n\nEnter the first String:");
scanf("%[a-z ]s",a);
printf("\nEnter the substring:");
scanf("%s",b);
printf("\nEnter the replace string:");
scanf("%s",c);
printf("\n\n\tOUTPUT");
printf("\n\t*******");
for(i=0;a[i]!='\0';i++)
l1=i;
for(i=0;b[i]!='\0';i++)
l2=i;
for(i=0;c[i]!='\0';i++)
l3=i;
for(i=0;a[i]!='\0';i++)
d[i]=a[i];
d[i]='\0';
if(l1>=l2)
{
do
{
for(i=0,j=0;a[i]!='\0' && b[j]!='\0';i++ )
{
if(a[i]==b[j])
{
count++;
j++;
}
else
{
count=-1;
if(j>0)
i--;
j=0;
}
}
m=i;
if(count==l2)
{
i=i-j;
for(k=0;c[k]!='\0';i++,k++)
a[i]=c[k];
if(l2!=l3)
{
for( ;d[m]!='\0';m++,i++)
{
a[i]=d[m];
}
}
//a[i]='\0';
//printf("\nReplaced string:%s",a);
}
else
break;
//printf("\nThe substring is not there");
}while(a[i]!='\0');
printf("\nReplaced string:%s",a);
}
getch();
}
0 comments:
Post a Comment