1. WAP to enter any number and check if the number is even or odd.
#include<stdio.h> #include<conio.h> int main() { int num, rem; printf("Enter any number\n"); scanf("%d", &num); rem=num%2; if(rem==0) printf("%d is an even number", num); else printf("%d is an odd number", num); getch(); return 0; }
2. WAP to enter any number and check if the number is exactly divisible by 5 and 6 or not.
#include<stdio.h>
#include<conio.h>
int main()
{
int num;
printf("Enter any number\n");
scanf("%d", &num);
if(num%5==0 && num%6==0)
printf("%d is exactly divisible by 5 & 6", num);
else
printf("%d is not exactly divisible by 5 & 6", num);
getch();
return 0;
}
3. WAP to read the marks of 4 subjects of a student from the user and compute percentage and grade of the student using the following conditions:
per >=80 grade=A
per >=60 and per<80 grade=B
per >=50 and per <60 grade=C
per >=40 and per<50 grade=D
per <40 grade=F
#include<stdio.h>
#include<conio.h>
int main()
{
float m1, m2, m3, m4, per, total;
char grade;
printf("Enter marks in 4 subjects\n");
scanf("%f%f%f%f", &m1, &m2, &m3, &m4);
total=m1+m2+m3+m4;
per=total/4;
if (per>=80)
grade='A';
else if (per>=60)
grade='B';
else if (per>50)
grade='C';
else if (per>=40)
grade='D';
else if (per<40)
grade='E';
printf("Your marks details are given below\n");
printf("Total is = %.2f\nPercentage is = %.2f\nGrade is = %c",
total, per, grade);
getch();
return 0;
4. WAP to enter a number and check if the entered no is Armstrong not Armstrong. Eg. 153, 370, 371, 407.
#include<conio.h>
#include<stdio.h>
int main()
{
int num, r, sum=0, ori;
printf("Enter any any number\n");
scanf("%d", &num);
ori=num;
while(num>0)
{
r=num%10;
sum=sum+r*r*r;
num=num/10;
}
if(ori==sum)
printf("%d is a armstrong number\n", ori);
else
printf("%d is not a armstrong number\n", ori);
getch();
return 0;
}
5. WAP to enter a number and check if the entered no is Palindrome or not Palindrome.
#include<conio.h>
#include<stdio.h>
int main()
{
int num, r, pal=0, ori;
printf("Enter any any number\n");
scanf("%d", &num);
ori=num;
while(num>0)
{
r=num%10;
pal=pal*10+r
num=num/10;
}
if(ori==sum)
printf("%d is a Palindrome number\n", pal);
else
printf("%d is not a Palindrome number\n", pal);
getch();
return 0;
}
6. WAP to enter a number and print in reverse form.
#include<conio.h>
#include<stdio.h>
int main()
{
int num, r, rev=0;
printf("Enter any any number\n");
scanf("%d", &num);
ori=num;
while(num>0)
{
r=num%10;
rev=rev*10+r
num=num/10;
}
printf("%d is the reverse number\n", rev);
getch();
return 0;
7. WAP to display the following pattern:
5
54
543
5432
54321
#include<stdio.h>
#include<conio.h>
int main()
{
int i, j;
for(i=5; i>=1; i--)
{
for(j=5; j>=i; j--)
{
printf("%d", j);
}
printf("\n");
}
getch();
}
8. WAP to display fibonacci series
2 3 5 8 13..... up to 15th term
#include<stdio.h>
#include<conio.h>
int main() {
int a=1, b=1, c, i;
for(i=1; i<=15; i++) {
printf("%d
\t", a);
c=a+b;
a=b;
b=c;
}
9. WAP to enter any number and check if the number is prime or composite.
#include<stdio.h>
#include<conio.h>
int main() {
int i, num, count=0;
printf("Enter any number\n");
scanf("%d", &num);
for(i=1; i<=num; i++) {
if(num%i==0)
count=count+1;
}
if (count==2)
printf("The number is prime");
else
printf("The number is composite");
getch();
}
10. WAP to enter any 3 numbers and find the middle value.
#include<stdio.h>
#include<conio.h>
int main() {
int a, b, c;
printf("Enter any 3 numbers
\n");
scanf("%d%d%d", &a, &b, &c);
if(a>b && a<c || a<b && a>c)
printf("%d is a middle number\n", a);
else if(b>a && b<c || b<a && b>c)
printf("%d is a middle number\n", b);
else if(c>a && c<b || c<a && c>b)
printf("%d is a middle number\n", c);
else
printf("Some numbers must be equal\n");
getch();
return 0;
}
11. WAP to enter 10 numbers in an array and find the largest and the smallest number.
#include<stdio.h>
#include<conio.h>
#define N 10
int main()
{
int num[N];
int i;
int largest, smallest;
printf("Enter any %d elements of array\n", N);
for(i=0; i<N; i++)
{
scanf("%d", &num[i]);
}
largest=num[0];
smallest=num[0];
for(i=0; i<N; i++)
{
if (num[i]>largest)
largest=num[i];
if(num[i]<smallest)
smallest=num[i];
}
printf("The largest number is %d\n", largest);
printf("The smallest number is %d\n", smallest);
getch();
return 0;
}
12. WAP to accept marks in 5 subjects from the keyboard and find the sum and average using array.
#include<stdio.h>
#include<conio.h>
#define N 5
int main()
{
int num[N];
int i, sum=0, ave;
printf("Enter marks in any 5 subjects\n");
for(i=0; i<N; i++)
{
scanf("%d", &num[i]);
sum=sum+num[i];
}
ave=sum/5;
printf("Average of marks of 5 subjects is %d", ave);
printf("The sum of marks of 5 subjects is %d\n", sum);
getch();
return 0;
}
13. WAP to read the age of 100 people and count the number of persons in the age between 50 and 60 years.
#include<stdio.h>
#include<conio.h>
#define N 100
int main()
{
int num[N];ib
int i, count=0;
printf("Enter ages of 100 person\n");
for(i=0; i<N; i++)
{
scanf("%d", &num[i]);
if(num[i]>50 && num[i]<60)
count=count+1;
}
printf("No. of persons between the age 50 and 60 are %d",
count);
getch();
return 0;
}
14. WAP to enter 10 numbers in an array and display them in ascending order.
#include<stdio.h>
#include<conio.h>
#define N 5
int main()
{
int num[N];
int i, j, temp;
printf("Enter any 5 numbers\n");
for(i=0; i<N; i++)
{
scanf("%d", &num[i]);
}
for(i=0; i<N; i++)
{
for(j=0; j<N-i-1; j++)
{
if(num[j]<num[j+1])
{
temp=num[j];
num[j]=num[j+1];
num[j+1]=temp;
}
}
}
printf("Enter numbers in descending order is: \n");
for(i=0; i<N; i++)
{
printf("%d\t", num[i]);
}
getch();
return 0;
}
15. WAP to input any 10 numbers in an array and display it,
find the smallest and biggest number among the input numbers.*/
#include<stdio.h>
#include<conio.h>
#define N 10
int main()
{
int num[N];
int i, biggest, smallest, sum=0;
printf("Enter any 10 numbers\n");
for(i=0; i<N; i++)
{
scanf("%d", &num[i]);
sum=sum+num[i];
}
printf("The sum of 10 number is %d\n", sum);
printf("The entered numbers in an array are given below:\n");
for(i=0; i<N; i++)
{
printf("%d\t", num[i]);
}
biggest=num[0];
if(num[i]>biggest)
biggest=num[i];
if(num[i]<smallest)
smallest=num[i];
}
printf("\nThe greatest number is %d\n", biggest);
printf("The smallest number is %d", smallest);
getch();
return 0;
}
16. WAP to enter two matrices (4x4) and find then sum of the matrices and display it.
#include<stdio.h>
#include<conio.h>
#define R 4
#define C 4
int main()
{
int mat1[R][C], mat2[R][C], sum[R][C];
int i, j;
printf("Enter the elements of first matrix\n");
for(i=0; i<R; i++)
{
for(j=0; j<C; j++)
{
scanf("%d", &mat1[i][j]);
}
}
printf("Enter the elements of second matrix\n");
for(i=0; i<R; i++)
{
for(j=0; j<C; j++)
{
scanf("%d", &mat2[i][j]);
}
}
for(i=0; i<R; i++)
{
for(j=0; j<C; j++)
{
sum[i][j]=mat1[i][j]+mat2[i][j];
}
}
printf("The sum of matrix is given below:\n");
for(i=0; i<R; i++)
{
for(j=0; j<C; j++)
{
printf("%d\t", sum[i][j]);
}
printf("\n");
}
getch();
return 0;
}