C Programming
1. WAP to calculate the area of a rectangle in c. [Hints: a = l x b]
#include
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();
}
2. WAP to calculate the simple interest in c. [Hints: i= (ptr)/100]
#include
int main()
{
float p, t, r, i;
printf (“Enter principal time and rate: ”);
scanf (“%f %f %f”, &p, &t, &r);
i= (p*t*r)/100;
printf (“The interest is %f”, i);
return 0;
}
3.WAP to calculate the average of 3 number in c. [Hints: av= (a+b+c)/3]
#include
int main()
{
float a, b, c, av;
printf (“Enter 3 numbers: ”);
scanf (“%f %f %f”, &a, &b, &rc);
av= (a+b+c)/3;
printf (“The average is %f”, av);
return 0;
}
4. WAP to calculate the volume of cylinder in c. [Hints: v= pi*r*r*h]
#include
int main()
{
float pi=3.14, r, h, v;
printf (“Enter radius and height: ”);
scanf (“%f %f ”, &r, &h);
v= pi*r*r*h;
printf (“The volume is %f”, v);
return 0;
}
5.Write a program to find greatest among two number
#include
int main()
{
int a,b;
printf (“Enter two number”);
scanf (“%d %d”, &a, &b);
if (a>b)
{
printf (“%d is greatest", a);
}
else
{
printf (“%d is greatest", b);
}
return 0;
}
6.Write a program to check whether given number is odd or even
#include
int main()
{
int n, r ;
printf (“Enter number”);
scanf (“%d”, &n); r = n%2;
if (r ==0)
{
printf (“%d is even", n);
}
else
{
printf (“%d is odd", n);
}
return 0;
}
7. Write a program to check whether given number is positive or negative
#include
int main()
{
int n;
printf (“Enter number”);
scanf (“%d”, &n);
if (n>0)
{
printf (“%d is positive", n);
}
else
{
printf (“%d is negative", n);
}
return 0;
}
8.Write a program to check whether given number is positive, negative or zero.
#include
int main()
{
int n;
printf (“Enter 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;
}
9. Write a program to find greatest among three number.
#include
int main()
{
int a, b, c;
printf (“Enter 3 number”);
scanf (“%d %d %d”, &a, &b, &c);
if (a>b && a>c)
{
printf (“%d is greatest", a);
}
else if (b>a && b>c)
{
printf (“%d is greatest", b);
}
else
{
printf (“%d is greatest", c);
}
return 0; }
11. Write a C program to check whether a character is an alphabet or not.
#include
Int main()
{
Char c;
Printf(“Enter a character:”);
Scanf(“Enter a character:”);
If ((c>=‘a’ && c<=‘Z’) || (c>=‘A’ && c<= ‘Z’))
{
printf(“%c is an alphabet.”,c);
}
Else
{
printf(“%c is not an alphabet.”,c);
}
return 0;
}
12. Write a program in C language to display first 10 natural numbers.
#include
int main ()
{
int I;
for(i=0;i<10;i++)
}
printf(“%d”,i);
}
return 0;
}
13. Write a program in C program to display the series with their sum 1,2,3,4….up to 10th term.
#include
Int main()
{
Int I,sum;
for (i=0;i<10;i++)
{
printf(“%”,i);
Sum+=I;
}
printf(“Sum of the series=%d”,sum);
return 0;
}
14. Write a program in C language to ask a number and check weather is exactly divisible by 5 or not.
#include
int main()
{
int n;
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);
}
return 0;
}
15. Write a program in C program in C language to display the series 2,4,6,8…..upto 10th term.
#include
int main()
{
for(i=0;i<10;i++)
{
printf(“%d”,a);
a+=2;
}
return 0;
}
16. Write a program in C language to display first 10 odd numbers.
#include
int main()
{
int I,a=1;
for(i=0; i<10; i++)
{
Printf(“%d”,a);
a+=2;
return 0;
}
17.Write a program in C language to display the series 2,4,6,8…..upto 10th term.
#include
Int main()
{
Int I,a=2;
For (i=0;i<10;i++)
{
Printf(“%d”,a);
a+=2
}
Return 0;
}
18.Write a program in C language that asks three numbers and print the smallest among them.
#include
Int main()
{
Int a,b,c;
Printf(“Enter any three numbers”);
Scanf(“%d%d%d,&a,&b,&c);
If(a
int main()
{
float side1, side2, side3; // Input the sides of the triangle
printf("Enter the first side of the triangle: ");
scanf("%f", &side1);
printf("Enter the second side of the triangle: ");
scanf("%f", &side2);
printf("Enter the third side of the triangle: ");
scanf("%f", &side3); // Check if the sides form a valid triangle
if ((side1 + side2 > side3) && (side2 + side3 > side1) && (side1 + side3 > side2)) { // Check for equilateral triangle
if (side1 == side2 && side2 == side3)
{
printf("The triangle is Equilateral.\n");
} // Check for isosceles triangle
else if (side1 == side2 || side2 == side3 || side1 == side3)
{
printf("The triangle is Isosceles.\n");
} // Otherwise, it is a scalene triangle
else
{
printf("The triangle is Scalene.\n");
}
}
else
{
printf("The entered sides do not form a valid triangle.\n");
}
return 0;
}
Comments
Post a Comment