#include<stdio.h>
#include<conio.h>
long int factorial(int n);
void main()
{
int n;
clrscr();
printf("\n Enter the number");
scanf("\n %d",&n);
printf("\n Factorial of %d is %ld",n,factorial(n));
getch();
}
long int factorial(int n)
{
if(n<=1)
{
return(01);
}
else
{
n=n*factorial(n-1);
return(n);
}
}
output:-
Enter the number n=5
Factorial of 5 = 120
Welcome ! to C Language Extreme Programmings Blog through learn the programming complete examples.
Write a c program to find even and odd numbers.
#include<stdio.h>
#include<conio.h>
main()
{
int num;
clrscr();
printf("\n enter the number num");
scanf("\n %d",&num);
if(num%2==0)
{
printf("\n num is even %d",num);
}
else
{
printf("\n num is odd %d",num);
}
return (0);
}
output:-
enter the number =103
odd number
http://www.youtube.com/watch?v=AMUpCyRpkJw&feature=context-gau
#include<conio.h>
main()
{
int num;
clrscr();
printf("\n enter the number num");
scanf("\n %d",&num);
if(num%2==0)
{
printf("\n num is even %d",num);
}
else
{
printf("\n num is odd %d",num);
}
return (0);
}
output:-
enter the number =103
odd number
http://www.youtube.com/watch?v=AMUpCyRpkJw&feature=context-gau
Write a C program to subtract of two matrix.
#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
int a[n][m],b[n][m],c[n][m];
int i,j;
clrscr();
printf("\n enter the values of n and m");
scanf("\n %d%d",&n,&m);
printf("\n enter the element of matrix a");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
scanf("\n %d",a[i][j]);
}
}
printf("\n enter the values of matrix b");
{
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
scanf(\n %d",b[i][j]);
}
}
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
c[i][j]=a[i][j]-b[i][j];
printf("\n %d",c[i][j]);
}
}
return (0);
}
output:-
enter the row and column of matrix a={2*2}
enter the row and column of matrix b={2*2}
enter the element of first matrix a={0,2,4,5}
enter the element of first matrix b={0,6,4,5}
matrix c={0,-4,0,0}
#include<conio.h>
#include<math.h>
main()
{
int a[n][m],b[n][m],c[n][m];
int i,j;
clrscr();
printf("\n enter the values of n and m");
scanf("\n %d%d",&n,&m);
printf("\n enter the element of matrix a");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
scanf("\n %d",a[i][j]);
}
}
printf("\n enter the values of matrix b");
{
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
scanf(\n %d",b[i][j]);
}
}
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
c[i][j]=a[i][j]-b[i][j];
printf("\n %d",c[i][j]);
}
}
return (0);
}
output:-
enter the row and column of matrix a={2*2}
enter the row and column of matrix b={2*2}
enter the element of first matrix a={0,2,4,5}
enter the element of first matrix b={0,6,4,5}
matrix c={0,-4,0,0}
Write a c program to find the area and circumference of circle.
#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
int r;
float pi=3.142,area,cir;
clrscr();
printf("\n enter the value of r");
scanf("\n %d",&r);
cir=2*pi*r;
area=pi*r*r;
printf(" the circumference of the circle is %f",cir);
printf(" the area of the circle is %f",area);
}
output:-
enter the value of r=1
circumference (cir)=6.28400
area of circle =3.14200
#include<conio.h>
#include<math.h>
main()
{
int r;
float pi=3.142,area,cir;
clrscr();
printf("\n enter the value of r");
scanf("\n %d",&r);
cir=2*pi*r;
area=pi*r*r;
printf(" the circumference of the circle is %f",cir);
printf(" the area of the circle is %f",area);
}
output:-
enter the value of r=1
circumference (cir)=6.28400
area of circle =3.14200
Write a C program for simple interest calculation
#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
int p,r,t;
float x;
clrscr();
printf("\n enter the values of p,r and t");
scanf("\n %d%d%d",&p,&r,&t);
x=((p*r*t)/100;
printf("\n x=%f",x);
return(0);
}
output:-
enter the value of p=100
enter the value of r=10
enter the value of t=2
x=20.000
#include<conio.h>
#include<math.h>
main()
{
int p,r,t;
float x;
clrscr();
printf("\n enter the values of p,r and t");
scanf("\n %d%d%d",&p,&r,&t);
x=((p*r*t)/100;
printf("\n x=%f",x);
return(0);
}
output:-
enter the value of p=100
enter the value of r=10
enter the value of t=2
x=20.000
Write a c programme for addition of two matrix.
#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
int a[n][m],b[n][m],c[n][m];
int i,j;
clrscr();
printf("\n enter the values of n and m");
scanf("\n %d%d",&n,&m);
printf("\n enter the element of matrix a");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
scanf("\n %d",a[i][j]);
}
}
printf("\n enter the values of matrix b");
{
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
scanf(\n %d",b[i][j]);
}
}
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
c[i][j]=a[i][j]+b[i][j];
printf("\n %d",c[i][j]);
}
}
return (0);
}
output:-
enter the values of n=2
enter the values of m=2
enter the element of matrix a[]={1,2,3,4}
enter the element of matrix b[]={1,2,3,4}
matrix c[]={2,4,6,8}
#include<conio.h>
#include<math.h>
main()
{
int a[n][m],b[n][m],c[n][m];
int i,j;
clrscr();
printf("\n enter the values of n and m");
scanf("\n %d%d",&n,&m);
printf("\n enter the element of matrix a");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
scanf("\n %d",a[i][j]);
}
}
printf("\n enter the values of matrix b");
{
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
scanf(\n %d",b[i][j]);
}
}
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
c[i][j]=a[i][j]+b[i][j];
printf("\n %d",c[i][j]);
}
}
return (0);
}
output:-
enter the values of n=2
enter the values of m=2
enter the element of matrix a[]={1,2,3,4}
enter the element of matrix b[]={1,2,3,4}
matrix c[]={2,4,6,8}
Subscribe to:
Posts (Atom)