* 01
Write a
program to find factorial of any given number.
Answer :
#include<stdio.h>
main()
{
int i,n,f;
f=1;
printf("Enter
the wanted factorial number :?\b\n");
scanf("%d",&n);
if(n<0)
printf("This
is not possible try again\n");
else
{
for(i=1;i<=n;i++)
f=f*i;
printf("%d",f);
}
printf("Thank
you")
}
* 02.Write a program to find Fibonacci number.
Answer :
#include<stdio.h>
main()
{
int i,n1,n2,n,N;
n1=1;
n2=0;
printf("Enter
the length of the Fibonacci number.=?\b");
scanf("%d",&n);
printf("Fibonacci Number");
for(i=0;i<=n;i++)
{
N=n1+n2;
printf(" %d
",N);
n1=n2;
n2=N;
}
}
* 03.
Write a
program to convert Decimal to any given base number.
Answer :
#include<stdio.h>
main()
{ int
d,i=0,b,j,index[10];
printf("Enter
the decimal number=?\b");
scanf("%d",&d);
printf("Enter
yhe base=?\b");
scanf("%d",&b);
printf("The answer=");
while(d>0)
{ index[i]=d%b;
d=d/b;
i++;}
for(j=i-1;j>=0;j--)
{
if(index[j]<10) printf("%d",index[j]);
if(index[j]==10) printf("A");
if(index[j]==11) printf("B");
if(index[j]==12) printf("C");
if(index[j]==13) printf("D");
if(index[j]==14) printf("E");
if(index[j]==15) printf("F");
}}
* 04.
Write a
program to Multiply to matrix.
Answer :
#include<stdio.h>
main()
{
int
i,j,k,m,p,n,a[5][5],b[5][5],c[5][5];
printf("How
many rows in first / colums in second matrix =");
scanf("%d",&p);
printf("How
many colums in first matrix =");
scanf("%d",&m);
printf("How
many row in second matrix = ");
scanf("%d",&n);
printf("Enter
the first matrix(%d x %d)\n",p,m);
for(i=0;i<m;i++)
{
for(j=0;j<p;j++)
scanf("%d",&a[i][j]);
}
printf("Enter
second matrix(%d x %d)",n,p);
for(i=0;i<p;i++)
{
for(j=0;j<n;j++)
scanf("%d",&b[i][j]);
}
printf("\nFirst
matrix..........\n");
for(i=0;i<m;i++)
{
for(j=0;j<p;j++)
{
printf("%5d",a[i][j]);
}
printf("\n");
}
printf("\nsecond matrix..........\n");
for(i=0;i<p;i++)
{
for(j=0;j<n;j++)
{
printf("%5d",b[i][j]);
}
printf("\n");
}
printf("\nMATRIX MULTIPLICATION....\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
c[i][j]=0;
for(k=0;k<p;k++)
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%5d",c[i][j]);
}
printf("\n");
}
}
*05.Write a program to add two matrix.
Answer :
#include<stdio.h>
main()
{
int
i,j,k,l,s,d,t,a[5][5],b[5][5],c[5][5];
printf("Enter
the matrix [a] ROW AND COLLUM \n");
scanf("%d%d",&s,&d);
printf("Row=%d \nColum=%d",s,d);
printf("Enter
the value\n");
for(i=0;i<=s-1;i++)
{
for(j=0;j<=d-1;j++)
scanf("%d",&a[i][j]);
}
for(i=0;i<=s-1;i++)
{
printf("\n");
for(j=0;j<=d-1;j++)
printf("%d",a[i][j]);
}
{
printf("\n\nEnter the matrix [b] ROW AND COLLUM \n");
scanf("%d%d",&s,&d);
printf("Row=%d \nColum=%d",s,d);
printf("Enter
the value\n");
for(i=0;i<=s-1;i++)
{
for(j=0;j<=d-1;j++)
scanf("%d",&b[i][j]);
}
for(i=0;i<=s-1;i++)
{
printf("\n");
for(j=0;j<=d-1;j++)
printf("%d",b[i][j]);
}
}
printf("\n");
{
for(i=0;i<=s-1;i++)
{
printf("\n");
for(j=0;j<=d-1;j++)
{
t=a[i][j]+b[i][j];
printf("%d",t);
}
}
}
}
*06.
Write a program to find gcd (Greatest Common Divisors) and lcm (Least Common Multiple) from given number.
Answer :
#include<stdio.h>
int gcd(int a,int b)
{
if(a>b)
{
int c=a;
a=b;
b=c;
}
while(b!=0)
{
int g=a%b;
a=b;
b=g;
} return a;}
main()
{
int n,a,b,c,g,r;
printf("Enter
the the two number ");
scanf("%d
%d",&a,&b);
r=gcd(a,b);
printf("The
Greatest common divisor(gcd)%d",r);
}(Least Common Multiple)
Answer :
#include<stdio.h>
int lcm(int,int);
int main()
{
int a,b=1;
printf("PLEASE, ENTER POSITIVE INTEGERS. TO TERMINATE, PRESS ZERO.");
while(1){
scanf("%d",&a);
if(a<1) break;
else if(a>b) b = lcm(a,b);
else b = lcm(b,a);
}
printf("LCM is %d",b);
}
int lcm(int a,int b)
{
int temp = a;
while(1){
if(temp % b == 0 && temp % a == 0)
break;
temp++;
}
return temp;
}
*07.
Write a program to find the root of a given quadratic equation.
Answer :
#include<stdio.h>
main()
{
int b,a,c,D;float
i,j,x1, x2, x3;
printf("Enter
the valure of a,b,c of the equqation [ax^2+bx+c=0]\n");
scanf("%d%d%d",&a,&b,&c);
D=b*b-4*a*c;
if(D>0)
{
x1=(float)(-b+sqrt(D))/(float)(2*a);
x1=(float)(-b-sqrt(D))/(float)(2*a);
printf("THE ROOT ARE REAL");
printf("The root are x1=%.3f \n\t\t\tx2=%.3f\n",x1,x2);
}
else if(D==0)
{
x1=x2=(float)(-b)/(float)(2*a);
printf("\nTHE ROOTS ARE EQUAL.\n");
printf("The root are x1=%.3f x2=%.3f",x1,x2);
}
else
{
x1 =
(float)(-b)/(float)((2*a)); i=(float)(-D)/(float)((2*a));
x2 =
(float)(-b)/(float)((2*a)); j=(float)(-D)/(float)((2*a));
printf("\nTHE
ROOTS ARE IMAGINARY.\n");
printf("\nThe
roots are : \nx1 = %.3f + %.3f i", x1, i);
printf("\nx2
= %.3f - %.3f i", x2, j);
}
} return 0;
}
}
Thanks Every one
|
MD.Saddam hossain (Noyon)
|