Chapter 4- Programming in C----> Structural Programming
1. Write a C program to find simple interest. (SI=(PTR)/100)
#include<stdio.h>
int main()
{
float p,t,r,si;
printf("Enter principal, time and rate");
scanf("%f%f%f", &p,&t,&r);
si=(p*t*r)/100;
printf("simple interst =%f",si);
return 0;
}
2. Write a C program to find area of circle. (area=πr2)
#include<stdio.h>
int main()
{
float r,area,pi=3.14;
printf("Enter radius");
scanf("%f",&r);
area=pi*r*r;
printf("area of circle =%f",area);
return 0;
}
3. Write a C program to check whether the inputted number is positive, negative or zero
#include<stdio.h>
int main()
{
int n;
printf("Enter a number");
scanf("%d",&n);
if(n>0)
{
printf("%d is positive",n);
}
else if(n<0)
{
printf("%d is negative",n);
}
else
{
printf("%d is zero",n);
}
return 0;
}
4. Write a C program to check whether the inputted number is odd or even
#include<stdio.h>
int main()
{
int n,r;
printf("Enter a number");
scanf("%d",&n);
r=n%2;
if(r==0)
{
printf("%d is even",n);
}
else
{
printf("%d is odd",n);
}
return 0;
}
5. Write a C program to inputted two numbers and find greatest among two.
#include<stdio.h>
int main()
{
int a,b;
printf("Enter two numbers");
scanf("%d%d",&a,&b);
if(a>b)
{
printf("%d is greater than %d",a,b);
}
else
{
printf("%d is greater than %d",b,a);
}
return 0;
}
6. Write a C program to inputted three numbers and find smallest among three.
#include<stdio.h>
int main()
{
int a,b,c;
printf("Enter three numbers");
scanf("%d%d%d",&a,&b,&c);
if(a<b && a<c)
{
printf("%d is smallest",a);
}
else if(b<a && b<c)
{
printf("%d is smallest",b);
}
else
{
printf("%d is smallest",c);
}
return 0;
}
7. Write a C program to display 1,2,3…………..upto 10th term
#include<stdio.h>
int main()
{
int i;
for(i=1;i<=10;i++)
{
printf("%d\t",i);
}
return 0;
}
8. Write a C program to display 2,4,6,…………..upto 10th term
#include<stdio.h>
int main()
{
int i;
for(i=2;i<=10;i=i+2)
{
printf("%d\t",i);
}
return 0;
}
9. Write a C program to display 0,1,1,2…………..upto 10th term
#include<stdio.h>
int main()
{
int i,a=0,b=1,c;
for(i=1;i<=10;i++)
{
printf("%d\t",a);
c=a+b;
a=b;
b=c;
}
return 0;
}
10. Write a C program to display 7,22,11,34…………..upto 10th term
#include<stdio.h>
int main()
{
int i,n=7;
for(i=1;i<=10;i++)
{
printf("%d\t",n);
if(n%2==0)
{
n=n/2;
}
else
{
n=n*3+1;
}
}
return 0;
}