fibonacci series
#include<stdio.h>
#include<conio.h>
void main()
{
int a=0,b=1,i,n,c;
printf("enter the number of terms");
scanf("%d",&n);
printf("\n%d\t%d\t",a,b);
for(i=2;i<=n;i++)
{
c=a+b;
a=b;
b=c;
printf("%d\t",c);
}
getch();
}
switch program to add and multiply two matrices
#include<stdio.h>
#include<conio.h>
#include<process.h>
void main()
{
int ch,a[10][10],b[10][10],c[10][10],m,n,i,j,k,p,q,x;
clrscr();
do
{
printf("menu\nselect\n");
printf("1:matrix addition \n2:matrix multiplication\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
{
printf("enter ordr");
scanf("%d%d",&m,&n);
printf("enter elements of m1");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
printf("matrix1:");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("\n");
printf("%d\t",a[i][j]);
}
printf("enter elements of m2");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&b[i][j]);
for(i=0;i<m;i++)
for(j=0;j<n;j++)
c[i][j]=a[i][j]+b[i][j];
printf("sum matrix is...\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%d",c[i][j]);
printf("\t");
}
printf("\n");
}
}
break;
case 2:
{
printf("enter ordr");
scanf("%d%d",&m,&n);
printf("enter elements of m1\n");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
printf("enter the order of m2\t");
scanf("%d%d",&p,&q);
if(n!=p)
{
printf("multiplication is not possivle");
exit(0);
}
printf("enter elements of m2\n");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&b[i][j]);
for(i=0;i<m;i++)
for(j=0;j<n;j++)
for(c[i][j]=0,k=0;k<n;k++)
c[i][j]+=(a[i][k])*(b[k][j]);
printf("the product matrix is....\n");
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<q;j++)
printf("\t%d",c[i][j]);
}
}
break;
case 3:
exit(0);
break;
default:printf("wrong entry");
}
printf("do u wanna continue??\n");
printf("3:yes\n4:no\n");
scanf("%d",&x);
}while(x==3);
getch();
}
switch program to sort an array in ascending and descending order
#include<stdio.h>
#include<conio.h>
#include<process.h>
void main()
{
int a[15],n,i,j,s,ch;
clrscr();
do
{
printf("menu\nselect");
printf("1:ascending order\n2:descending order");
scanf("%d",&ch);
switch(ch)
{
case 1:
{
printf("enter numbers");
scanf("%d",&n);
printf("enter set of numbers");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("sorting in ascending order:");
for(i=0;i<n;i++)
for(j=0;j<n-1;j++)
if(a[j]>a[j+1])
{
s=a[j];
a[j]=a[j+1];
a[j+1]=s;
}
printf("\nsorted array in ascending order follows...");
for(i=0;i<n;i++)
printf("\t %d",a[i]);
}
break;
case 2:
{
printf("enter numbers");
scanf("%d",&n);
printf("enter set of numbers");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("sorting in descending order:");
for(i=0;i<n;i++)
for(j=0;j<n-1;j++)
if(a[j]<a[j+1])
{
s=a[j];
a[j]=a[j+1];
a[j+1]=s;
}
printf("\nsorted array in descending order follows...");
for(i=0;i<n;i++)
printf("\t %d",a[i]);
}
break;
case 3:
exit(0);
break;
default:printf("wrong entry");
}
printf("do you want to continue?");
printf("3:yes;\n4:no");
}
getch();
}
program to print multiplication table
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,c;
clrscr();
printf("enter the number");
scanf("%d",&n);
for(i=1;i<=12;i++)
{
c=n*i;
printf("\n%d*%d=%d",n,i,c);
}
getch();
}