C Programmes
C Programmes
C Programmes
#include <stdio.h>
int main() {
int a;
printf("enter the number to check whether it is even or odd :-");
scanf("%d",&a);
if (a%2==0)
{
printf("the number is even");
}
else
{
printf("the number is odd");
}
return 0;
}
2 )
To find area of a square ?
#include <stdio.h>
int main() {
int a,area;
printf("enter the leangth of the side of the square in cm :-");
scanf("%d",&a);
area=4*a;
printf("area of the square with sides %d cm is :- %d cm",a,area);
return 0;
}
3 )
To find area of a rectangle ?
#include <stdio.h>
int main() {
int l,b,area;
printf("enter the leangth of the rectangle in cm :-");
scanf("%d",&l);
printf("enter the breadth of the rectangle in cm :-");
scanf("%d",&b);
area=l*b;
printf("area of the rectangle with leangth %d cm and breadth %d cm is :- %d
cm",l,b,area);
return 0;
}
4 )
To find area of a triangle ?
#include <stdio.h>
int main() {
float b,h,area;
printf("enter the leangth of the base of the triangle in cm :-");
scanf("%f",&b);
printf("enter the height of the triangle in cm :-");
scanf("%f",&h);
area=b*h/2;
printf("area of the triangle is :- %f",area);
return 0;
}
5)
#include <stdio.h>
int main() {
int n,i;
n=1;
for(n=1;n<=10;n++)
{
for(i=1;i<=10;i++)
{
printf("%d\t",n*i);
}
printf("\n");
}
return 0;
}
6)
To check the number is armstrong or not
#include<stdio.h>
int main()
{
int n,rem,new=0,temp;
printf("Enter the value of n:");
scanf("%d",&n);
temp=n;
while(temp>0)
{
rem = temp%10;
temp = temp/10;
new = new+rem*rem*rem;
}
if(n == new)
{
printf("Armstrong");
}
else
{
printf("Not an Armstrong");
}
//printf("%d",new);
return 0;
}
or
#include <stdio.h>
int main() {
int i,j,a,b,c,d;
printf("Enter the value where you want to start");
scanf("%d",&a);
printf("Enter the value where you want to stop");
scanf("%d",&b);
printf("Enter the value upto you want to print");
scanf("%d",&c);
printf("Enter the value upto you want to print");
scanf("%d",&d);
for(i=a;i<=b;i++)
{
for(j=c;j<=d;j++)
{
printf("%d\t",i*j);
}
printf("\n");
}
return 0;
}
7) Fabonacci Recursion :-
#include<stdio.h>
int fabonacci(int n);
int main()
{
int n,m_fab;
printf("Enter the value of n:");
scanf("%d",&n);
m_fab=fabonacci(n);
printf("Fab = %d",m_fab);
return 0;
}
int fabonacci(int n)
{
int i,a=0,b=1,f_fab;
if(n==1)
{
return 0;
}
else if(n==2)
{
return 1;
}
else
{
return fabonacci(n-1)+fabonacci(n-2);
}
}
#include <stdio.h>
int main() {
int a,b,c,d;
printf("Enter the first number : ");
scanf("%d",&a);
printf("Enter the second number : ");
scanf("%d",&b);
printf("Enter the third number : ");
scanf("%d",&c);
printf("Enter the fourth number : ");
scanf("%d",&d);
if(a>b)
{
if(a>c)
{
if(a>d)
{
printf("%d is the biggest of all these numbers",a);
}
else
{
printf("%d is the biggest of all these numbers",d);
}
}
else if(c>d)
{
printf("%d is the boggest of all these numbers",c);
}
else
{
printf("%d is the biggest of all these numbers",d);
}
}
else if(b>c)
{
if(b>d)
{
printf("%d is the biggest of all these numbers",b);
}
else
{
printf("%d is the biggest of all these numbers",d);
}
}
else if(c>d)
{
printf("%d is the biggest of all these numbers",c);
}
else
{
printf("%d is the biggest of all these numbers",d);
}
return 0;
}
9 )
Bubble Sorting :-
#include<stdio.h>
void arr_bubble(int a[],int n);
int main()
{
int a[100],i,n;
printf("Enter the no of elements");
scanf("%d",&n);
arr_bubble(a,n);
return 0;
}
void arr_bubble(int a[], int n)
{
int i,j,temp;
for(i=0;i<n;i++)
{
for(j=0;j<n-1;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}