0% found this document useful (0 votes)
37 views5 pages

C Programmes

The document contains examples of C programs to check if a number is even or odd, calculate the area of basic shapes like square, rectangle and triangle, print multiplication tables, check if a number is Armstrong, find the largest of four numbers, implement Fibonacci recursion, bubble sort an array. All programs include functions like scanf, printf and return 0.

Uploaded by

Mitesh Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views5 pages

C Programmes

The document contains examples of C programs to check if a number is even or odd, calculate the area of basic shapes like square, rectangle and triangle, print multiplication tables, check if a number is Armstrong, find the largest of four numbers, implement Fibonacci recursion, bubble sort an array. All programs include functions like scanf, printf and return 0.

Uploaded by

Mitesh Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

1 )

C-program to check wether the number is odd or even ?

#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)

To print table of 1-10 10 times :

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

8) to find biggest among 4 numbers :-

#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);

printf("Enter the values:");


for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}

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

printf("The values of array are:");


for(i=0;i<n;i++)
{
printf("%d\t",a[i]);
}
}

You might also like