PROGRAM – 1
WAP to accept marks of 5 subjects and find the sum and percentage.
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int s1, s2, s3, s4, s5, sum;
float percentage;
printf("Enter marks of Subject 1: ");
scanf("%d", &s1);
printf("Enter marks of Subject 2: ");
scanf("%d", &s2);
printf("Enter marks of Subject 3: ");
scanf("%d", &s3);
printf("Enter marks of Subject 4: ");
scanf("%d", &s4);
printf("Enter marks of Subject 5: ");
scanf("%d", &s5);
sum = s1 + s2 + s3 + s4 + s5;
percentage = (sum / 5.0);
printf("Total Marks = %d\n", sum);
printf("Percentage = %.2f%%\n", percentage);
getch();
}
Output:
Enter marks of Subject 1: 67
Enter marks of Subject 2: 80
Enter marks of Subject 3: 60
Enter marks of Subject 4: 78
Enter marks of Subject 5: 76
Total Marks = 361
Percentage = 72.20%
PROGRAM – 2
WAP to calculate the area and circumference of a circle.
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
float radius, area, circumference;
const float pi = 3.14;
printf("Enter the value of radius: ");
scanf("%f", &radius);
area = pi * radius * radius;
circumference = 2 * pi * radius;
printf("Area = %.2f\n", area);
printf("Circumference = %.2f\n", circumference);
getch();
}
Output:
Enter the value of radius = 25
Area = 1962.50
Circumference = 157.00
PROGRAM – 3
WAP that swaps value of two variables without using a third variable.
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a, b;
printf("Enter value of a: ");
scanf("%d", &a);
printf("Enter value of b: ");
scanf("%d", &b);
a = a + b;
b = a - b;
a = a - b;
printf("After swapping:\n");
printf("a = %d\n", a);
printf("b = %d\n", b);
getch();
}
Output:
Enter value of a: 5
Enter value of b: 10 After swapping:
a = 10
b = 5
PROGRAM – 4
WAP for Enter 2 Numbers & display highest Number.
void main()
{
int a,b;
clrscr();
printf("Plz Enter 2 Numbers : ");
scanf("%d %d",&a,&b);
if(a>b)
printf("\n\n 1st Number is the Highest Number.");
else if(a<b)
printf("\n\n 2nd Number is the highest Number.");
else
printf("\n\n Both Numbers r equals.");
getch();
}
Output:
Plz Enter 2 Numbers : 100 20
1st Number is the Highest Number.
PROGRAM – 5
WAP that checks whether the three numbers entered by the user are equal or not.
// Enter 3 Numbers & display highest Number.
void main()
{
int a,b,c;
clrscr();
printf("Plz Enter 3 Numbers : ");
scanf("%d %d %d",&a,&b,&c);
// algo for find out highest Number.
if(a>b && a>c)
printf("\n\n 1st Number is the Highest Number.");
else if(b>a && b>c)
printf("\n\n 2nd Number is the highest Number.");
else if(c>a && c > b)
printf("\n\n 3rd Number is the Highest Number.");
// Algo for check numbers r equals or not.
if(a==b && a == c)
printf("\n All numbers equals.");
else if(a==b)
printf("\n 1st & 2nd numbers r equals.");
else if(a==c)
printf("\n 1st & 3rd numbers r equals.");
else if(c==b)
printf("\n 2nd & 3rd numbers r equals.");
getch();
}
Output:
Plz Enter 3 Numbers : 10 10 40
3rd Number is the Highest Number.
1st & 2nd numbers r equals.
PROGRAM – 6
Write a program to print the given year is Leap or not.
#include<stdio.h>
#include<conio.h>
void main()
{
int year;
clrscr();
printf("Enter a year: ");
scanf("%d", &year);
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
printf("Leap year");
else
printf("Not a leap year");
getch();
}
Output:
Enter a year: 2025
Not a leap year
PROGRAM – 7
Write WAP that accepts marks of five subjects and finds percentage and prints
grades according to the following criteria:
Between 90-100% Print ‘A’
80-90% Print ‘B’
60-80% Print ‘C’
Below 60% Print ‘D’
#include<stdio.h>
#include<conio.h>
void main()
{
int m1, m2, m3, m4, m5, total;
float percent;
clrscr();
printf("Enter marks of 5 subjects:\n");
scanf("%d %d %d %d %d", &m1, &m2, &m3, &m4, &m5);
total = m1 + m2 + m3 + m4 + m5;
percent = total / 5.0;
printf("Percentage = %.2f\n", percent);
if (percent >= 90 && percent <= 100)
printf("Grade: A");
else if (percent >= 80)
printf("Grade: B");
else if (percent >= 60)
printf("Grade: C");
else
printf("Grade: D");
getch();
}
Output:
Enter marks of 5 subjects: 75 80 70 90 85
Percentage = 80.00
Grade: B
PROGRAM – 8
WAP to find the factorial of a given number.
#include <stdio.h>
#include <conio.h>
void main()
{
int n, i;
unsigned long long factorial = 1;
clrscr();
printf("Enter a positive integer: ");
scanf("%d", &n);
if(n < 0)
printf("Factorial of negative number doesn't exist.");
else
{
for(i = 1; i <= n; i++)
factorial = factorial * i;
printf("Factorial of %d = %llu", n, factorial);
}
getch();
}
Output:
Enter a positive integer: 5
Factorial of 5 = 120
PROGRAM – 9
WAP to check whether the entered number is prime or not.
void main()
{
int n,j,flag=1;
clrscr();
printf("Plz Enter any Number : ");
scanf("%d",&n);
for(j=2;j<=n/2;j++)
{
if(n%j==0)
{
flag = 0;
break;
}
}
if(flag)
printf("\n\t\tNumber is Prime...");
else
printf("\n\t\tNumber is not Prime...");
getch();
}
Output:
Enter a number: 7
Number is Prime...
PROGRAM – 10
WAP to find the sum of digits of the entered number.
void main()
{
int a,x,sum=0;
clrscr();
printf("Plz Enter any Number : ");
scanf("%d",&a);
printf("\n\n\nNumber in Reverse is : ");
while(a>0)
{
x = a % 10;
a = a / 10;
sum += x;
}
printf("Sum of digits = %d", sum);
getch();
}
Output:
Enter a number: 1234
Sum of digits = 10
PROGRAM – 11
WAP to find the reverse of a number.
void main()
{
long int a,x,rev=0;
clrscr();
printf("Plz Enter any Number : ");
scanf("%ld",&a);
while(a>0) {
x = a % 10;
a = a / 10;
rev = rev * 10 + x;
}
printf("\n\n\nNumber in Reverse is : %d",rev);
getch();
}
Output:
Plz Enter any Number : 1234
Number in Reverse is : 4321
PROGRAM – 12
WAP that simply takes elements of the array from the user and finds the sum of these
elements.
#include <stdio.h>
#include <conio.h>
void main()
{
int arr[100], n, i, sum = 0;
clrscr();
printf("Enter number of elements in array: ");
scanf("%d", &n);
printf("Enter %d elements: ", n);
for(i = 0; i < n; i++)
{
scanf("%d", &arr[i]);
sum = sum + arr[i];
}
printf("Sum of array elements = %d", sum);
getch();
}
Output:
Enter number of elements in array: 5
Enter 5 elements:
10
20
30
40
50
Sum of array elements = 150
PROGRAM – 13
WAP to search an element in a array using Linear Search.
#define MAX 5
void main()
{
int i,n,ar[10],flag = 0;
clrscr();
for(i=0;i<MAX;i++)
{
printf("enter value for ar[%d] : ",i);
scanf("%d",&ar[i]) ;
}
printf("Enter value for search in array - ");
scanf("%d",&n) ;
for(i=0;i<MAX;i++)
{
if(ar[i] == n)
{
flag = 1;
printf("Array element found at ar[%d] index\n",i);
break;
}
}
if(!flag)
printf("Sorry value not found in the array......\n\n");
for(i=0;i<MAX;i++)
printf("%d , ",ar[i]);
getch();
}
Output:
enter value for ar[0] : 10
enter value for ar[1] : 20
enter value for ar[2] : 30
enter value for ar[3] : 40
enter value for ar[4] : 50
Enter value for search in array - 60
Sorry value not found in the array......
PROGRAM – 14
WAP to sort the elements of the array in ascending order using Bubble Sort
technique.
#define MAX 5
void main()
{
int i,j,temp,ar[10];
clrscr();
// loop for input values
printf("Enter 5 elements: ");
for(i=0;i<MAX;i++)
scanf("%d",&ar[i]);
// Sorting algo - Bubble Sort.
for(i=0;i<MAX-1;i++) {
for(j=0;j<MAX-1-i;j++) {
if(ar[j]>ar[j+1])
{
temp = ar[j];
ar[j] = ar[j+1];
ar[j+1] = temp;
}
}
}
printf("\n\nAll Elements r - ");
// for disp
for(i=0;i<MAX;i++)
printf("%d, ",ar[i]);
getch();
}
Output:
Enter 5 elements: 55 34 7 87 56
Array after sorting in ascending order: 7 34 55 56 87
PROGRAM – 15
WAP to multiply two matrices of order n x n.
#define MAX 10
void main() {
int i,j,k,r,c,a[MAX][MAX],b[MAX][MAX],c[MAX][MAX]={0};
clrscr();
printf("Plz Enter rows & cols for matrix : ");
scanf("%d %d",&r,&c);
for(i=0;i<r;i++)
{
printf("Plz Enter 1st Matrix row %d : ",i+1);
for(j=0;j<c;j++)
scanf("%d",&a[i][j]);
}
for(i=0;i<r;i++)
{
printf("Plz Enter 2nd Matrix row %d : ",i+1);
for(j=0;j<c;j++)
scanf("%d",&a[i][j]);
}
// algo of Multi of matrix.
if(r!=c)
printf("multiplication of matrix Not Possible\n");
else
{
for(i=0;i<r;i++)
for(j=0;j<c;j++)
for(k=0;k<c;k++)
c[i][j] += a[i][k] * b[k][j];
printf("\nMulti of Matrix - \n\n");
for(i=0;i<r;i++)
{
printf("\n\t");
for(j=0;j<c;j++)
printf("%3d ",c[i][j]);
}
getch();
}
}
PROGRAM – 16
WAP that finds the sum of diagonal elements of a m x n matrix.
#include <stdio.h>
#include <conio.h>
void main()
{
int a[10][10], m, n, i, j; int sum = 0;
clrscr();
printf("Enter the number of rows (m): ");
scanf("%d", &m);
printf("Enter the number of columns (n): ");
scanf("%d", &n);
printf("Enter elements of the matrix:\n");
for(i = 0; i < m; i++)
for(j = 0; j < n; j++)
scanf("%d", &a[i][j]);
// Calculate sum of diagonal elements (only if i == j)
for(i = 0; i < m; i++)
for(j = 0; j < n; j++)
if(i == j)
sum += a[i][j];
printf("\nSum of diagonal elements: %d", sum);
getch();
}
Output:
Enter the number of rows
(m): 3 Enter the number
of columns (n): 3 Enter
elements of the matrix:
1 2 3
4 5 6
7 8 9
Sum of diagonal elements: 15
PROGRAM – 17
WAP for check string is palindrome or not without using inbuild functions..
void main()
{
char str[] = "malayalam";
int i,len = 0,flag=1;
clrscr();
while(str[len] != '\0')
len++;
for(i = 0; i <= len/2; i++) // length ke half tak
{
if(str[i] != str[len - i - 1])
{
flag = 0;
break;
}
}
if(flag)
printf("\n %s is a Palindrome String", str);
else
printf("\n %s is Not a Palindrome String", str);
getch();
}
Output:
malayalam is a Palindrome String