- WAP to calculate the area of a rectangle in c. [Hints: a = l x b]
#include<stdio.h>
#include<conio.h>
void main()
{
int l, b, a;
printf (“Enter Length: ”);
scanf (“%d”, &l);
printf (“Enter Breadth: “);
scanf (“%d”, &b);
a = l * b;
printf (“The area is %d”, a);
getch();
}
- Write a program in C language to enter base and height of a triangle and calculate its area. [AOT = ½ × B × H]
#include<stdio.h>
#include<conio.h>
Void main()
{
int b, h, area;
printf("Enter base and height of triangle: ");
scanf("%d %d", &b, &h);
area= (1/2)*b*h;
printf("Area of triangle =%d",area);
getch();
}
- Write a C program to accept principal, time and rate as input and calculate simple interest. [SI = (P × T × R) / 100)
#include<stdio.h>
#include<conio.h>
void main ()
{
float p, t, r, si=0;
printf (“Enter principal time and rate: ”);
scanf (“%f %f %f”, &p, &t, &r);
si= (p*t*r)/100;
printf (“The interest is %f”, i);
getch ();
}
- Write a C program that ask a user to enter a number and check whether the number is odd or even.
#include<stdio.h>
#include<conio.h>
void main ()
{
int n;
printf ("Enter any number: ");
scanf ("%d ", &n);
if (n % 2 ==0)
{
printf("%d is an even number", n);
}
else
{
printf ("%d is an odd number", n);
}
getch();
}
- Write a C program that ask a user to enter a number and check whether the number is positive, negative or zero.
#include<stdio.h>
#include<conio.h>
void main ()
{
int n;
printf ("Enter any number: ");
scanf ("%d ", &n);
if (n > 0)
{
printf ("%d is a positive number", n);
}
else if (n < 0)
{
printf ("%d is a negative number", n);
}
else
{
printf ("The entered number is zero");
}
getch();
}
- Write a program in C language to display the series 1, 2, 3, 4, 5, ………up to 10th terms.
#include<stdio.h>
#include<conio.h>
Void main()
{
int i;
for (i=1; i<=10; i++)
{
printf("% d \t", i);
}
getch();
}
- Write a program in C language to display the series with their sum 1, 2, 3, 4, 5, …………up to 10th terms.
#include<stdio.h>
#include<conio.h>
Void main()
{
int i, s=0;
for (i=1; i<=10; i++)
{
s = s + i;
}
printf("The sum of numbers=%d", s);
getch();
}
- Write a program in C language that asks any two number and display the greatest among them.
#include<stdio.h>
#include<conio.h>
void main ()
{
int a, b;
printf("enter any two numbers: ");
scanf("%d %d", &a, &b);
if (a > b)
{
printf("% d is the greatest number", a);
}
else
{
printf("% d is the greatest number", b);
}
getch();
}
- Write a program in C language that asks any two number and display the smallest among them.
#include<stdio.h>
#include<conio.h>
void main ()
{
int a, b;
printf ("enter any two numbers: ");
scanf ("%d %d", &a, &b);
if (a < b)
{
printf("% d is the smallest number", a);
}
else
{
printf("% d is the smallest number", b);
}
getch();
}
- Write a program in C language to display the series 2, 4, 6, 8, ………..up to 10th terms.
#include<stdio.h>
#include<conio.h>
void main()
{
int i, a=2;
for(i=1; i <=10; i++)
{
printf("%d \t", a);
a = a+2;
}
getch();
}
- Write a program in C language to input a number then check whether the number is completely divisible by 5 or not.
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf("Enter any number: ");
scanf("%d ", &n);
if(n%5==0)
{
printf("%d is exactly divisible by 5", n);
}
else
{
printf("%d is not exactly divisible by 5", n);
}
getch();
}
- Write a program in C language to display the series of first 10 even numbers.
#include<studio.h>
#include<conio.h>
void main()
{
int i, a=2;
clrscr();
for(i=1; i<=10; 1++)
{
printf("%d \t", a);
a= a + 2;
}
getch();
}
- Write a program in C language to display the series of first 10 natural numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
for(i=1; i<=10; 1++)
{
printf("%d \t", i);
}
getch();
}
- Write a program in C language to calculate the sum of odd numbers from 80 to 90.
#include<stdio.h>
#include<conio.h>
void main()
{
int i, s=0;
for(i=80; i<=90; i= i+2)
{
s = s + i;
}
printf("Sum= %d", s);
getch();
}
- Write a C program to display the series 1,1,2,3,5,8,……….up to 10th terms.
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i, a=1, b=1, c;
printf("%d \t %d \t", a, b);
for(i=3, i<=10; i++)
{
c = a + b;
printf("% d \t", c);
a= b;
b= c;
}
getch();
}
-
Write a program in C language that asks any three numbers and display the greatest among them.
#include<stdio.h>
#include<conio.h>
void main ()
{
int a, b, c;
printf ("enter any three numbers: ");
scanf ("%d %d %d", &a, &b, &c);
if (a > b && a>c)
{
printf ("% d is the greatest number", a);
}
else if(b > c && b > a)
{
printf ("% d is the greatest number", b);
}
else
{
printf("%d is the greatest number", c);
}
getch();
}