You are on page 1of 41

C Program for BANK OPERATION

#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 finding COS THETA 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();
}

C Program for Exponential value

#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();
}
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);
}
else
{
return((x)*(fact(x-1)));
}
}

C Program for fibanacci series using recursion.

#include<stdio.h>
#include<conio.h>
int fib(int);
void main()
{
int a,b,i,c;
clrscr();
printf("Enter the N value");
scanf("%d",&a);
for(i=0;i<a;i++)
{
printf("\n%d",fib(i));
}
getch();
}
int fib(int x)
{
if(x==0)
return(0);
if(x<=1)
{
return(1);
}
else
{
return(fib(x-1)+(fib(x-2)));
}
}

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();
}

C Program for Library Operation.

#include<stdio.h>
#include<conio.h>
int i=0;
void add();
void search();
void sort();
void sorta();
struct book

{
char bookname[50];
char author[50];
double price;
int nocopy;
}book[50];
void main()
{
int ch;
while(1)
{
clrscr();
printf("********************");
printf("\nLIBRARY MANAGEMENT");
printf("\n******************");
printf("\n1-ADD TO LIBRARY");
printf("\n2-SEARCH A BOOK");
printf("\n3-SORT BY BOOK NAME");
printf("\n4-SORT BY AUTHOR NAME");
printf("\n5-EXIT");
printf("\nEnter your choice:");
scanf("%d",&ch);
switch(ch)
{
case 1: add();
break;
case 2: search();
break;
case 3: sort();
break;
case 4: sorta();
break;
case 5: exit(0);
default: puts("Please enter 1-5 only");
getch();
}
}
}
void add()
{
printf("\n\nADD TO LIBRARY");
printf("\nEnter the Bookname: ");
fflush(stdin);
gets(book[i].bookname);
printf("\nEnter the Author name: ");
fflush(stdin);
gets(book[i].author);
printf("\nEnter the Price of the Book: ");
scanf("%ld",&book[i].price);
printf("\nEnter no of copies : ");
scanf("%d",&book[i].nocopy);
printf("STORED");
printf("\nBOOK NAME: %s",book[i].bookname);
printf("\nAUTHOR : %s",book[i].author);
printf("\nPRICE : %d",book[i].price);
printf("\nNO OF COPIES: %d",book[i].nocopy);
i++;
getch();
}
void search()
{
int f=0,y,j,x;
char bookn[50],authorname[50];
printf("\n Enter the Book Name: ");
fflush(stdin);
gets(bookn);
printf("\n Enter the Author Name: ");
fflush(stdin);
gets(authorname);
printf("\nThe Given Search");
printf("\nThe Book Name is: %s",bookn);
printf("\nThe Author Name is : %s",authorname);
for(j=0;j<i;j++)
{
x= strcmp(book[j].bookname,bookn);
y=strcmp(book[j].author,authorname);
if(x==0&&y==0)
{
printf("\nBOOK IS FOUND");
getch();
f=1;
}
}
if(f==0)
{
printf("\nBOOK NOT FOUND");
getch();
}
getch();
}
void sort()
{
int j,k,x;
char t[50];
for(j=0;j<i;j++)
{
for(k=0;k<j;k++)
{
x = (strcmp(book[k].bookname,book[k+1].bookname));
if(x>0)
{
strcpy(t,book[k].bookname);
strcpy(book[k].bookname ,book[k+1].bookname);
strcpy(book[k+1].bookname, t);
}
}
}
printf("\nSORTED BY BOOK NAME");
for(j=0;j<i;j++)
{
printf("\nThe BookName is:%s - %s",book[j].bookname,book[j].author);
}
getch();
}
void sorta()
{
int j,k,x;
char t[50];
for(j=0;j<i;j++)
{
for(k=0;k<j;k++)
{
x = (strcmp(book[k].author,book[k+1].author));
if(x>0)
{
strcpy(t,book[k].author);
strcpy(book[k].author ,book[k+1].author);
strcpy(book[k+1].author, t);
}
}
}
printf("\nSORTED BY AUTHOR NAME");
for(j=0;j<i;j++)
{
printf("\nThe AUTHOR NAME is:%s - %s",book[j].author,book[j].bookname);
}
getch();
}

C PROGRAM FOR PASCAL TRIANGLE.

#include<stdio.h>
#include<conio.h>
void main()
{
int i=1,j,num,x=1;
clrscr();
printf("Please Enter the Number :");
scanf("%d",&num);
printf("\n\n");
printf("OUTPUT:\n");
printf("------");
printf("\n\n");
printf("The Pascal triangle is\n");
printf("**********************\n");
for(i=1;i<=num;i++)
{
for(j=1;j<=i;j++)
{
if(j==1)
{
x=1;
printf("%d",x);
}
else
{
x=(x*(i-j+1)/(j-1));
printf("%d",x);
}
}
printf("\n");
}
getch();
}

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();
}

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();
}

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();
}

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();
}

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();
}

C Program for STUDENT MARKLIST.

#include<stdio.h>
#include<conio.h>
int k=0;
struct stud
{
int rn;
char name[30];
int m1,m2,m3,total;
float avg;
char grade,result;
}s[30];
void main()
{
int no,roll=101,i;
clrscr();
printf("Enter NO of Students:");
scanf("%d",&no);
for(i=0;i<no;i++)
{
clrscr();
s[k].rn=roll;
printf("\nEnter the Student Roll Number: %d ",s[k].rn);
printf("\nEnter the Student Name:");
fflush(stdin);
gets(s[k].name);
printf("\nEnter the Three Marks");
scanf("%d",&s[k].m1);
scanf("%d",&s[k].m2);
scanf("%d",&s[k].m3);
if(s[k].m1>=35 && s[k].m2>=35 && s[k].m3>=35)
{
s[k].result='P';
}
else
{
s[k].result = 'F';
}
s[k].total = s[k].m1+s[k].m2+s[k].m3;
printf("The Total is : %d",s[k].total);
s[k].avg=s[k].total/3;
if(s[k].avg>=60)
{
if(s[k].result == 'P')
{
s[k].grade = 'A';
}
else
{
s[k].grade = 'N';
}
}
else if(s[k].avg>=50)
{
if(s[k].result == 'P')
{
s[k].grade = 'B';
}
else
{
s[k].grade = 'N';
}
}
else if(s[k].avg>=35)
{
if(s[k].result == 'P')
{
s[k].grade = 'C';
}
else
{
s[k].grade = 'N';
}
}
getch();
k++;
roll++;
}
printf("\n*******************************************************");
printf("\n STUDENT MARKLIST ");
printf("\n*******************************************************");
printf("\nROLL \tNAME MARK1 MARK2 MARK3 TOTAL RESULT Average GRADE");
for(i=0;i<no;i++)
{
printf("\n%d\t%s %d %d %d %d %c %0.1f
%c",s[i].rn,s[i].name,s[i].m1,s[i].m2,s[i].m3,s[i].total,s[i].result,s[i].avg,s[i].grad
e);
}
getch();
}

C Program for SubString.

#include<stdio.h>
#include<conio.h>
void main()
{
char a[30],b[30];
int i,j,l1,l2,c,f;
clrscr();
printf("OUTPUT\n");
printf("------\n");
printf("\n\n");
printf("\nEnter First String:");
scanf("%s",a);
printf("\nEnter String to Search:");
scanf("%s",b);
l1=strlen(a);
l2=strlen(b);
j=0;
c=0;
f=0;
for(i=0;i<l1;i++)
{
x:
if(b[j]==a[i])
{
c++;
f=1;
j++;
if(c==l2)goto y;
}
else
{
if(f==1)
{
j=0;
c=0;
f=0;
goto x;
}
}
}
y:
if(c==l2)
printf("\n\t\tWord Found");
else
printf("\n\t\tWord Not Found");
getch();
}

C Program For to find largest and smallest value in two dimension matrix.

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,r,c,a[10][10],largest=0,smallest,z=1,t;
clrscr();
printf("Enter the r and c value:");
scanf("%d%d",&r,&c);
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
printf("a[%d][%d]=",i,j);
scanf("%d",&a[i][j]);
}
}
largest=0;
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
if(largest
{
largest=a[i][j];
}
}
}
t=a[1][1];
a[1][1]=smallest;
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
if(smallest>a[i][j])
{
smallest=a[i][j];
}
else
{
z++;
}
if(z==(r*c))
{
smallest=t;
}
}
}
printf("largest elemement=%d\n",largest);
printf("smallest element=%d\n",smallest);
getch();
}

C Program For Matrix addition.

#include<stdio.h>
#include<conio.h>
void main()
{
int r,c,a[10][10],i,j,m,n,b[10][10],z[10][10];
clrscr();
printf("Enter r and c value:");
scanf("%d%d",&r,&c);
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
printf("a[%d][%d]=",i,j);
scanf("%d",&a[i][j]);
}
}
for(m=1;m<=r;m++)
{
for(n=1;n<=c;n++)
{
printf("b[%d][%d]=",m,n);
scanf("%d",&b[m][n]);
}
}
// z[i][j]=0;
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
z[i][j]=(a[i][j]+b[i][j]);
}
}
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
printf("%d\t",z[i][j]);
}
printf("\n");
}
getch();
}

C Program For ARMSTRONG NUMBER.

#include<stdio.h>
#include<conio.h>
void main()
{
int n,t,s=0,k;
clrscr();
printf("Enter the n value:");
scanf("%d",&k);
n=k;
while(n>0)
{
t=n%10;
s=s+t*t*t;
n=n/10;
}
if(k==s)
{
printf("given %d is armstrong number",k);
}
else
{
printf("not armstrong number");
}
getch();
}

C Program For FINDING ONE DIMENSIONAL ARRAY BIG AND SMALL


ELEMENT.

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,a[10],max,min;
clrscr();
printf("Enter the n value");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("Enter the a[%d]=",i);
scanf("%d",&a[i]);
}
max=0;
for(i=1;i<=n;i++)
{
if(a[i]>max)
{
max=a[i];
}
if(a[i]<min)
{
min=a[i];
}
}
printf("maximum is =%d",max);
printf("minimum is=%d",min);
getch();
}
C Program For FIBINACCI SERIES USING ARRAY.

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,a[20];
clrscr();
printf("Enter the n value:");
scanf("%d",&n);
a[0]=0;
a[1]=1;
printf("%d\n",a[0]);
printf("%d\n",a[1]);
for(i=2;i<n;i++)
{
a[i]=a[i-1]+a[i-2];
printf("%d\n",a[i]);
}
getch();
}

C Program For ARRAY REVERSE.

#include<stdio.h>
#include<conio.h>
void main()
{
int a[20],i,n;
clrscr();
printf("Enter the n value");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("enter the a[%d]=",i);
scanf("%d",&a[i]);
}
for(i=n;i>0;i--)
{
printf("%d\n",a[i]);
}
getch();
}
C Program For ASCII VALUE.

#include<stdio.h>
#include<conio.h>
void main()
{
int t,k,n;
clrscr();
printf("Enter the password");
scanf("%d",&n);
while(n>0)
{
t=n%10;
t=t+1;
printf("%c\n",t);
//printf("%d\n",t);
n=n/10;
}
getch();
}

C Program For BINARY SEARCH.

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,search,f=0,low,high,mid,a[20];
clrscr();
printf("Enter the n value:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("Enter the number in ascending order a[%d]=",i);
scanf("%d",&a[i]);
}
printf("Enter the search element:");
scanf("%d",&search);
low=1;
high=n;
while(low<=high)
{
mid=(low+high)/2;
if(search<a[mid])
{
high=mid-1;
}
else if(search>a[mid])
{
low=mid+1;
}
else
{
f=1;
printf("obtainedin the position %d:",mid);
getch();
exit();
}
}
if(f==0)
{
printf("not present");
}
getch();
}

C Program For SUM OF DIAGONAL ELEMENTS IN MATRIX.

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,r,c,a[10][10],z=0;
clrscr();
printf("Enter the r and c");
scanf("%d%d",&r,&c);
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
printf("a[%d][%d]=",i,j);
scanf("%d",&a[i][j]);
}
}
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
printf("%d",a[i][j]);
}
printf("\n");
}
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
if(i==j)
{
z=z+a[i][j];
}
}
}
printf("sum of digonal elements=%d",z);
getch();
}

C Program For TRANSPOSE MATRIX.

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,r,c,a[10][10];
clrscr();
printf("Enter r and c value:");
scanf("%d%d",&r,&c);
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
printf("a[%d][%d]=",i,j);
scanf("%d",&a[i][j]);
}
}
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
printf("%d",a[i][j]);
}
printf("\n");
}
printf("\n\n");
if(r==c)
{
printf("transpose matrix");
printf("\n");
for(i=1;i<=c;i++)
{
for(j=1;j<=r;j++)
{
printf("%d",a[j][i]);
}
printf("\n");
}
}
else
{
printf("not possible");
}
getch();
}

C Program For MAKING NUMBER SERIES .

#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,t=0,a[10];
clrscr();
printf("Enter the n value");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("Enter the a[%d]=",i);
scanf("%d",&a[i]);
}
for(i=1;i<=n;i++)
{
t=t*10+a[i];
}
printf("the series is=%d",t);
getch();
}
C Program For ORDER OF NUMBERS.

/* N=321 AND RESULT=123*/

#include<stdio.h>
#include<conio.h>
void main()
{
int n,t,z=1,i,j,a[20];
clrscr();
printf("Enter any number:");
scanf("%d",&n);
while(n>0)
{
t=n%10;
a[z]=t;
z++;
n=n/10;
}
for(i=1;i<=z;i++)
{
for(j=i+1;j<=z;j++)
{
if(a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
for(i=2;i<=z;i++)
{
printf("%d",a[i]);
}
getch();
}

C Program For PALINDROME OF NUMBER.


#include<stdio.h>
#include<conio.h>
void main()
{
int k,n,t,s=0;
clrscr();
printf("Enter the n value:");
scanf("%d",&k);
n=k;
while(n>0)
{
t=n%10;
s=s*10+t;
n=n/10;
}
if(k==s)
{
printf("given %d number is palindrome",k);
}
else
{
printf("not palindrome");
}
getch();
}

C Program For PERFECT NUMBER.

#include<stdio.h>
#include<conio.h>
void main()
{
int c=0,n,i;
clrscr();<br>
printf("Enter n value:");
scanf("%d",&n);
for(i=1;i<n;i++)
{
if(n%i==0)
{
c=c+i;
}
}
if(n==c)
{
printf("given number %d is perfect number",c);
}
else
{
printf("not perfect number");
}
getch();
}

PRIME NUMBER FINDING

#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,c=0,j,a,b;
clrscr();
printf("Enter any number:");
scanf("%d%d",&a,&b);
for(i=a;i<=b;i++)
{
c=0;
for(j=1;j<=i;j++)
{
if(i%j==0)
{
c++;
//printf("i=%d and j=%d and c=%d\n",i,j,c);
}
}
if(c==2)
{
printf("%d\n",i);
}
}
getch();
}

C Program For UPPER TRIANGULAR MATRIX.

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,r,c,a[10][10];
clrscr();
printf("Enter the r and c value:");
scanf("%d%d",&r,&c);
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
printf("a[%d][%d]=",i,j);
scanf("%d",&a[i][j]);
}
}
printf("given matrix");
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
printf("%d",a[i][j]);
}
printf("\n");
}
for(i=1;i<=r;i++)
{
printf("\n");
for(j=1;j<=c;j++)
{
if(i>=j)
{
printf("%d",a[i][j]);
}
else
{
printf("\t");
}
// printf("\n");
}
}
printf("\n\n");
for(i=1;i<=r;i++)
{
printf("\n");
for(j=1;j<=c;j++)
{
if(j>=i)
{
printf("%d",a[i][j]);
}
else
{
//printf("\t");
}
// printf("\n");
}
}
getch();
}

C Program For SWAPPING VALUES.

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("Enter the a and b value");
scanf("%d%d",&a,&b);
printf("%d %d",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("%d %d",a,b);
getch();
}

C Program For SUM OF DIGITS.

#include<stdio.h>
#include<conio.h>
void main()
{
int n,t,s=0;
clrscr();
printf("Enter the digit");
scanf("%d",&n);
while(n>0)
{
t=n%10;
s=s+t;
n=n/10;
}
printf("sum =%d",s);
getch();
}

C Program For PRIME SERIES.

#include<stdio.h>
#include<conio.h>
void main()
{
int r,a,b,c=0;
clrscr();
printf("Enter the n value:");
scanf("%d",&r);
a=1;
while(a<=r)//for(i=1;i<=n;i++)
{
b=1;c=0;
while(b<=a)
{
if(a%b==0)
c=c+1;
b++;
}//end of while
if(c==2)
printf("%d",a);
a++;
}
getch();
}

C Program For DUPLICATE ELIMNATION.

#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,a[20],z=1,b[20],j,k,m;
clrscr();
printf("Enter the n value:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf(" a[%d]=",i);
scanf("%d",&a[i]);
}
for(i=1;i<=n;i++)
{
for(j=i+1;j<=n;j++)
{
if(a[i]==a[j])
{
a[j]=0;
}
}
}
for(k=1;k<=n;k++)
{
if(a[k]!=0)
{
b[z]=a[k];
z++;
}
}
for(m=1;m<z;m++)
{
printf("%d\n",b[m]);
}
getch();
}

C Program For INSERTION SORTING.

#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,a[20],m=1,j,t;
clrscr();
printf("Enter the n value:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("a[%d]=",i);
scanf("%d",&a[i]);
}
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
t=a[i];
if(a[i]>a[j])
{
a[m]=a[j];
a[j]=t;
}
}
m++;
}
for(i=n;i>0;i--)
{
printf("%d\n",a[i]);
}
getch();
}

C Program For BUBBLE SORTING.

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,j,t,a[20];
clrscr();
printf("Enter the n value:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("a[%d]=",i);
scanf("%d",&a[i]);
}
for(i=1;i<=n;i++)
{
for(j=i+1;j<=n;j++)
{
if(a[i]>=a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
for(i=1;i<=n;i++)
{
printf("%d\n",a[i]);
}
getch();
}

C Program For DECIMAL TO BINARY.

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int n,z=0,i,a[20];
clrscr();
printf("Enter the n value");
scanf("%d",&n);
while(n>0)
{
a[z]=n%2;
z++;
n=n/2;
}
for(i=z;i>=0;i--)
{
printf("%d",a[i]);
}
getch();
}

C Program For BINARY TO DECIMAL.

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int s=0,z=0,n,t;
clrscr();
printf("Enter the n value");
scanf("%d",&n);
while(n>0)
{
t=n%10;
s=s+(t*pow(2,z++));
printf("s=%d\n",s);
n=n/10;
}
printf("given number is=%d",s);
getch();
}

C Program For NCR VALUE BY RECURSIVE FUNCTION.

#include<stdio.h>
#include<conio.h>
void main()
{
int n,r,ncr;
clrscr();
printf("Enter the n and r value:");
scanf("%d%d",&n,&r);
ncr=fact(n)/((fact(r))*(fact(n-r)));
printf("n=%d\n",fact(n));
printf("r=%d\n",fact(r));
printf("n-r=%d\n",fact(n-r));
printf("the ncr =%d\n",ncr);
getch();
}
int fact(int a)
{
int c=1,i;
for(i=1;i<=a;i++)
{
c=c*i;
}
return(c);
}

C Program For FINDING POWER VALUE OF GIVEN NUMBER.


#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,r,c=1;
clrscr();
printf("Enter the n value:");
scanf("%d",&n);
printf("Enter the r value:");
scanf("%d",&r);
for(i=1;i<=r;i++)
{
c=c*n;
}
printf("the power value is=%d",c);
getch();
}

C Program For FACTORIAL USING RECURSION.

#include<stdio.h>
#include<conio.h>
void main()
{
int n,f;
clrscr();
printf("Enter the n value:");
scanf("%d",&n);
f=fact(n);
printf("factorial value is=%d",f);
getch();
}
int fact(int a)
{
int c=1;
if(a==1)
{
return(1);
}
else
{
a=a*fact(a-1);
//printf("%d\n",c);
return (a);
}
}

C Program For SELECTION SORTING.

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,a[20],j,z;
clrscr();
printf("Enter the n value:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("a[%d]=",i);
scanf("%d",&a[i]);
}
i=1;
while(i<=n)
{
for(j=i+1;j<=n;j++)
{
z=a[i];
if(a[i]>a[j])
{
a[i]=a[j];
a[j]=z;
}
}
i++;
}
for(i=1;i<=n;i++)
{
printf("%d\n",a[i]);
}
getch();
}
C Program For FIBANACCI SERIES USING RECURSION.

#include<stdio.h>
#include<conio.h>
void main()
{
int i,n;
clrscr();
printf("Enter the n value:");
scanf("%d",&n);
printf("the fibinacci series is\n");
for(i=0;i<n;i++)
{
printf("%d\n",fib(i));
}
getch();
}
int fib(int n)
{
if(n==0)
{
return(0);
}
if(n==1)
{
return(1);
}
else
{
return(fib(n-1)+fib(n-2));
}
}