1. 1. Program to Find Sum and Average of Three Real Numbers.
#include <stdio.h>
#include<conio.h>
main()
{
float a, b, c, sum, avg;
printf("nEnter value of three numbers: ");
scanf("%f %f %f", &a, &b, &c);
sum = a + b + c;
avg = sum / 3;
printf("nSum = %f", sum);
printf("nAverage = %f", avg);
getch();
}
Output:
1
2. 2. Program to Find Area of Square & Circumference of a Circle.
#include <stdio.h>
#include<conio.h>
#define PI 3.142
main()
{
float len, r, area, circum;
printf("nEnter length of a square: ");
scanf("%f", &len);
area = len * len;
printf("nEnter radius of a circle: ");
scanf("%f", &r);
circum = 2 * PI * r;
printf("nArea of square = %f", area);
printf("nCircumference of circle = %f", circum);
getch();
}
Output:
2
3. 3. Program to Find Area of a Triangle using Hero’s Formula .
#include <stdio.h>
#include<conio.h>
#include <math.h>
main()
{
float a, b, c, s, area;
printf("nEnter three sides of a triangle: ");
scanf("%f %f %f", &a, &b, &c);
s = (a + b + c) / 2;
area = sqrt(s * (s - a) * (s - b) * (s - c));
printf("nnArea of triangle: %f", area);
getch();
}
Output:
3
4. 4. Program to find Simple Interest and Compound Interest.
SI = (p * r * t) / 100
CI = p * pow((1 + r/100), t) - p
#include <stdio.h>
#include<conio.h>
#include <math.h>
main()
{
float p, r, t, si, ci;
printf("nEnter priciple, rate and time: ");
scanf("%f %f %f", &p, &r, &t);
si = (p * r * t) / 100;
ci = p * pow((1 + r/100), t) - p;
printf("nnSimple Interest: %f", si);
printf("nnCompound Interest: %f", ci);
getch();
}
Output:
4
5. 5. Basic salary of an employee is input through the keyboard. The DA
is 25% of the basic salary while the HRA is 15% of the basic
salary. Provident Fund is deducted at the rate of 10% of the gross
salary(BS+DA+HRA).
Program to Calculate the Net Salary.
#include <stdio.h>
#include<conio.h>
main()
{
float basic_sal, da, hra, pf, gross_sal, net_sal;
printf("nEnter basic salary of the employee: Rs. ");
scanf("%f", &basic_sal);
da = (basic_sal * 25)/100;
hra = (basic_sal * 15)/100;
gross_sal = basic_sal + da + hra;
pf = (gross_sal * 10)/100;
net_sal = gross_sal - pf;
printf("nnNet Salary: Rs. %f", net_sal);
getch();
}
Output:
5
6. 6.Program to Swap Values of Two Variables Without using 3rd Variable
#include <stdio.h>
#include<conio.h>
main()
{
int a, b, temp;
printf("nEnter any two numbers: ");
scanf("%d %d", &a, &b);
printf("nnBefore Swapping:n");
printf("na = %dn", a);
printf("nb = %dn", b);
a = a + b;
b = a - b;
a = a - b;
printf("nnAfter Swapping:n");
printf("na = %dn", a);
printf("nb = %dn", b);
getch();
6
}
Output:
7. 7. Program to Swap Values of Two Variables using Third Variable
#include <stdio.h>
#include<conio.h>
main()
{
int a, b, temp;
printf("nEnter any two numbers: ");
scanf("%d %d", &a, &b);
printf("nnBefore Swapping:n");
printf("na = %dn", a);
printf("nb = %dn", b);
temp = a;
a = b;
b = temp;
printf("nnAfter Swapping:n");
printf("na = %dn", a);
printf("nb = %dn", b);
getch();
7
}
Output:
8. 8. Program to Find Largest of Three Numbers .
#include <stdio.h>
#include<conio.h>
main()
{
int a, b, c;
printf("nEnter three numbers: ");
scanf("%d %d %d", &a, &b, &c);
if (a>b && a>c)
printf("nn%d is greater", a);
else if (b>a && b>c)
printf("nn%d is greater", b);
else
printf("nn%d is greater", c);
getch();
}
Output:
8
9. 9. Program to Check Whether a Character is a Vowel or not by using
switch Statement
#include <stdio.h>
#include<conio.h>
main()
{
char ch;
printf("nEnter any character: ");
scanf("%c", &ch);
switch (ch)
{
case 'a':
case 'A':
printf("nn%c is a vowel", ch);
break;
case 'e':
case 'E':
printf("nn%c is a vowel", ch);
break;
case 'i':
case 'I':
printf("nn%c is a vowel", ch);
break;
case 'o':
case 'O':
printf("nn%c is a vowel", ch);
break;
case 'u':
case 'U':
printf("nn%c is a vowel", ch);
break;
default:
printf("nn%c is not a vowel", ch);
}
getch();
}
9
11. 10. Program to Find the Sum of First 100 Positive Integers .
#include <stdio.h>
#include<conio.h>
main()
{
int i, sum=0;
printf("ntSum of first 100 positive numbersn");
for(i=0; i<=100; i++)
sum = sum + i;
printf("nSum = %d", sum);
getch();
}
Output:
11
12. 11. Program to Find the Sum of Even and Odd Numbers from First 100
Positive Integers
#include <stdio.h>
#include<conio.h>
main()
{
int i, sumEven=0, sumOdd=0;
for (i=0; i<=100; i++)
if (i%2 == 0)
sumEven = sumEven + i;
else
sumOdd = sumOdd + i;
printf("nSum of first even 100 numbers: %dn", sumEven);
printf("nSum of first odd 100 numbers: %dn", sumOdd);
getch();
}
Output:
12
13. 12. Program to Print a Table of any Number .
#include <stdio.h>
#include<conio.h>
main()
{
int n, mul, i;
printf("nEnter any no.: ");
scanf("%d", &n);
for(i=1; i<=10; i++)
{
mul = n*i;
printf("nn%dtxt%dt=t%d", n, i, mul);
}
getch();
}
Output:
13
14. 13. Program to Print the Numbers, Which are Divisible by 3 and 5 from
First 100 Natural Numbers
#include <stdio.h>
#include<conio.h>
main()
{
int i;
printf("nFirst 100 numbers which are divisible by 3 and
5nn");
for (i=1; i<=100; i++)
if (i%3==0 && i%5==0)
printf("t%d", i);
getch();
14
}
Output:
15. 14. Program to Find Factorial of a Number using Recursion
#include <stdio.h>
#include<conio.h>
long fact(int);
main()
{
int n;
long f;
printf("nEnter number to find factorial: ");
scanf("%d", &n);
f = fact(n);
printf("nFactorial: %ld", f);
getch();
}
long fact(int n)
{
int m;
if (n == 1)
return n;
else
{
m = n * fact(n-1);
return m;
}
}
15
16. 15.Program to Reverse a Given Number .
#include <stdio.h>
#include<conio.h>
main()
{
long n;
int rev;
printf("nEnter any number: ");
scanf("%ld", &n);
printf("nReverse no. is:nn");
while (n > 0)
{
rev = n % 10;
n = n / 10;
printf("%d", rev);
}
getch();
}
Output:
16
17. 16. Program to Find Vowels in a String.
#include <stdio.h>
#include <string.h>
#include<conio.h>
main()
{
char str[20];
int count=0, i=0;
printf("nEnter any string: ");
gets(str);
while (str[i] != '0')
{
if (str[i]=='a' || str[i]=='e' || str[i]=='i' ||
str[i]=='o' || str[i]=='u')
count++;
i++;
}
printf("nNo. of vowels: %d", count);
getch();
}
Output:
17
18. 17. Program to add two matrices.
#include <stdio.h>
#include<conio.h>
main()
{
int a[10][10], b[10][10], c[10][10], i, j, row, col;
printf("nEnter number of rows and columns: ");
scanf("%d %d", &row, &col);
printf("nEnter elements of Array A:n");
for (i=0; i<row; i++)
for (j=0; j<col; j++)
scanf("%d", &a[i][j]);
printf("nEnter elements of Array B:n");
for (i=0; i<row; i++)
for (j=0; j<col; j++)
scanf("%d", &b[i][j]);
printf("nElements of Matrix A:nn");
for (i=0; i<row; i++)
{
for (j=0; j<col; j++)
printf("t%d", a[i][j]);
printf("nn");
}
printf("nElements of Matrix B:nn");
for (i=0; i<row; i++)
{
for (j=0; j<col; j++)
printf("t%d", b[i][j]);
printf("nn");
}
for (i=0; i<row; i++)
for (j=0; j<col; j++)
c[i][j] = a[i][j] + b[i][j];
printf("nMatrix Addition is:nn");
for (i=0; i<row; i++)
{
for (j=0; j<col; j++)
printf("t%d", c[i][j]);
printf("n");
}
getch();
}
18
20. 18. Program to Concatenate Two Strings using strcat ().
#include <stdio.h>
#include <string.h>
#include<conio.h>
main()
{
char s1[20], s2[20];
printf("nEnter first string: ");
gets(s1);
printf("nEnter second string: ");
gets(s2);
strcat(s1, s2);
printf("nThe concatenated string is: %s", s1);
getch();
}
Output:
20
21. 19. Program to Concatenate Two Strings without using strcat ().
#include <stdio.h>
#include <conio.h>
#include <string.h>
main()
{
char string1[30], string2[20];
int i, length=0, temp;
printf("Enter the Value of String1: n");
gets(string1);
printf("nEnter the Value of String2: n");
gets(string2);
for(i=0; string1[i]!='0'; i++)
length++;
temp = length;
for(i=0; string2[i]!='0'; i++)
{
string1[temp] = string2[i];
temp++;
}
string1[temp] = '0';
printf("nThe concatenated string is:n");
puts(string1);
getch();
}
Output:
21
22. 20. Program to Compare Two Strings using strcmp() .
#include <stdio.h>
#include<conio.h>
#include <string.h>
main()
{
char s1[20], s2[20];
int result;
printf("nEnter first string: ");
gets(s1);
printf("nEnter second string: ");
gets(s2);
result = strcmp(s1, s2);
if (result == 0)
printf("nBoth strings are equal");
else
printf("nBoth strings are not equal");
getch();
}
Output:
22
23. 21. Program to Compare Two Strings Without using strcmp() .
#include<stdio.h>
#include<conio.h>
main()
{
char string1[5],string2[5];
int i,temp = 0;
printf("Enter the string1 value:n");
gets(string1);
printf("nEnter the String2 value:n");
gets(string2);
for(i=0; string1[i]!='0'; i++)
{
if(string1[i] == string2[i])
temp = 1;
else
temp = 0;
}
if(temp == 1)
printf("Both strings are same.");
else
printf("Both string not same.");
getch();
}
Output:
23
24. 22. Program to Copy String using strcpy() .
#include <stdio.h>
#include<conio.h>
#include <string.h>
main()
{
char s1[20], s2[20];
printf("nEnter string into s1: ");
gets(s1);
strcpy(s2, s1);
printf("ns2: %s", s2);
getch();
}
Output:
24
25. 23. Program to Find Length of a String using strlen().
#include <stdio.h>
#include<conio.h>
#include <string.h>
main()
{
char s1[20];
int len;
printf("nEnter any string: ");
gets(s1);
len = strlen(s1);
printf("nLength of string: %d", len);
getch();
}
Output:
25
26. 24. Program to Reverse a String without using strrev() .
#include <stdio.h>
#include <conio.h>
#include <string.h>
main()
{
char string1[10], string2[10];
int i, length;
printf("Enter any string:n");
gets(string1);
length = strlen(string1)-1;
for(i=0; string1[i]!='0'; i++)
{
string2[length]=string1[i];
length--;
}
string2[length]='0';
printf("nThe Reverse of string is:n");
puts(string2);
getch();
}
Output:
26