SlideShare a Scribd company logo
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. 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. 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. 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. 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.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. 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. 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. 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
Output: 
10
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
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
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
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:
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
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
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
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
Output: 
19
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
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
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
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
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
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
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

More Related Content

What's hot (19)

DOCX
ADA FILE
Gaurav Singh
 
DOCX
C Programming
Sumant Diwakar
 
PDF
The solution manual of c by robin
Abdullah Al Naser
 
PDF
Data Structure using C
Bilal Mirza
 
DOC
Basic c programs updated on 31.8.2020
vrgokila
 
DOCX
Core programming in c
Rahul Pandit
 
DOCX
some basic C programs with outputs
KULDEEPSING PATIL
 
DOCX
C programs
Minu S
 
PDF
C programms
Mukund Gandrakota
 
PDF
C Programming Example
PRATHAMESH DESHPANDE
 
PPTX
C Programming Example
University of Potsdam
 
DOCX
C lab manaual
manoj11manu
 
PDF
Simple C programs
ab11cs001
 
DOCX
Practical write a c program to reverse a given number
Mainak Sasmal
 
DOCX
Best C Programming Solution
yogini sharma
 
PDF
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
DR B.Surendiran .
 
PDF
Numerical analysis
Vishal Singh
 
DOCX
SaraPIC
Sara Sahu
 
ADA FILE
Gaurav Singh
 
C Programming
Sumant Diwakar
 
The solution manual of c by robin
Abdullah Al Naser
 
Data Structure using C
Bilal Mirza
 
Basic c programs updated on 31.8.2020
vrgokila
 
Core programming in c
Rahul Pandit
 
some basic C programs with outputs
KULDEEPSING PATIL
 
C programs
Minu S
 
C programms
Mukund Gandrakota
 
C Programming Example
PRATHAMESH DESHPANDE
 
C Programming Example
University of Potsdam
 
C lab manaual
manoj11manu
 
Simple C programs
ab11cs001
 
Practical write a c program to reverse a given number
Mainak Sasmal
 
Best C Programming Solution
yogini sharma
 
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
DR B.Surendiran .
 
Numerical analysis
Vishal Singh
 
SaraPIC
Sara Sahu
 

Viewers also liked (17)

PPTX
Half term quiz
bfisher11
 
PPTX
Lighting
imcourts
 
PDF
Belk IT
Rachel Stachowitz
 
PPTX
Dossier de présentation Gospel Air 2016 Lausanne
apaschou
 
PPTX
Music Magazine Analysis
Cloee Lang
 
PDF
Картофель: мягкой посадки. Глава 5
grisiuck
 
PPTX
Departments and its functions
Ashutosh Bhalerao
 
PPTX
Diapo ingles
jemsen
 
DOCX
Photoshop project tutorial
meyrni-ahmed
 
PPTX
Handling inputs via io..continue
simarsimmygrewal
 
PPT
Applied statistics manufacturing (1)
GlobalCompliance Panel
 
PPT
Conventional representation
Ashutosh Bhalerao
 
PPTX
Step 1
Pavan Purswani
 
PDF
Untitled Presentation
omar puga huerta
 
DOCX
Java file
simarsimmygrewal
 
PPTX
Evaluation
Cloee Lang
 
PPT
Doe process-development-validation
GlobalCompliance Panel
 
Half term quiz
bfisher11
 
Lighting
imcourts
 
Dossier de présentation Gospel Air 2016 Lausanne
apaschou
 
Music Magazine Analysis
Cloee Lang
 
Картофель: мягкой посадки. Глава 5
grisiuck
 
Departments and its functions
Ashutosh Bhalerao
 
Diapo ingles
jemsen
 
Photoshop project tutorial
meyrni-ahmed
 
Handling inputs via io..continue
simarsimmygrewal
 
Applied statistics manufacturing (1)
GlobalCompliance Panel
 
Conventional representation
Ashutosh Bhalerao
 
Untitled Presentation
omar puga huerta
 
Java file
simarsimmygrewal
 
Evaluation
Cloee Lang
 
Doe process-development-validation
GlobalCompliance Panel
 
Ad

Similar to C file (19)

PDF
PCA-2 Programming and Solving 2nd Sem.pdf
Ashutoshprasad27
 
DOCX
PCA-2 Programming and Solving 2nd Sem.docx
Ashutoshprasad27
 
DOCX
C lab
rajni kaushal
 
DOCX
B.Com 1year Lab programs
Prasadu Peddi
 
PDF
Common problems solving using c
ArghodeepPaul
 
DOCX
Chapter 8 c solution
Azhar Javed
 
DOC
'C' language notes (a.p)
Ashishchinu
 
PDF
Progr3
SANTOSH RATH
 
PPTX
Introduction to Basic C programming 02
Wingston
 
DOC
C basics
MSc CST
 
PDF
Basic C Programming Lab Practice
Mahmud Hasan Tanvir
 
PPTX
C programming
Samsil Arefin
 
PDF
C faq pdf
DebiPanda
 
DOCX
Hargun
Mukund Trivedi
 
PDF
C programs
Vikram Nandini
 
DOCX
Cs291 assignment solution
Kuntal Bhowmick
 
DOCX
Cpds lab
praveennallavelly08
 
PDF
C Programming Lab.pdf
MOJO89
 
PCA-2 Programming and Solving 2nd Sem.pdf
Ashutoshprasad27
 
PCA-2 Programming and Solving 2nd Sem.docx
Ashutoshprasad27
 
B.Com 1year Lab programs
Prasadu Peddi
 
Common problems solving using c
ArghodeepPaul
 
Chapter 8 c solution
Azhar Javed
 
'C' language notes (a.p)
Ashishchinu
 
Progr3
SANTOSH RATH
 
Introduction to Basic C programming 02
Wingston
 
C basics
MSc CST
 
Basic C Programming Lab Practice
Mahmud Hasan Tanvir
 
C programming
Samsil Arefin
 
C faq pdf
DebiPanda
 
C programs
Vikram Nandini
 
Cs291 assignment solution
Kuntal Bhowmick
 
C Programming Lab.pdf
MOJO89
 
Ad

More from simarsimmygrewal (7)

DOCX
Java file
simarsimmygrewal
 
DOCX
C file
simarsimmygrewal
 
DOCX
C++ file
simarsimmygrewal
 
PPTX
Handling inputs via scanner class
simarsimmygrewal
 
PPTX
Excception handling
simarsimmygrewal
 
PPTX
Type casting
simarsimmygrewal
 
PDF
Wrapper classes
simarsimmygrewal
 
Java file
simarsimmygrewal
 
Handling inputs via scanner class
simarsimmygrewal
 
Excception handling
simarsimmygrewal
 
Type casting
simarsimmygrewal
 
Wrapper classes
simarsimmygrewal
 

Recently uploaded (20)

PPTX
Sonnet 130_ My Mistress’ Eyes Are Nothing Like the Sun By William Shakespear...
DhatriParmar
 
PPTX
Translation_ Definition, Scope & Historical Development.pptx
DhatriParmar
 
PDF
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
PPTX
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
PPTX
Command Palatte in Odoo 18.1 Spreadsheet - Odoo Slides
Celine George
 
PDF
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
PPTX
HEALTH CARE DELIVERY SYSTEM - UNIT 2 - GNM 3RD YEAR.pptx
Priyanshu Anand
 
PDF
Virat Kohli- the Pride of Indian cricket
kushpar147
 
PPTX
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
DOCX
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
PDF
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
PPTX
Cleaning Validation Ppt Pharmaceutical validation
Ms. Ashatai Patil
 
PPTX
Constitutional Design Civics Class 9.pptx
bikesh692
 
PPTX
Rules and Regulations of Madhya Pradesh Library Part-I
SantoshKumarKori2
 
PPTX
Basics and rules of probability with real-life uses
ravatkaran694
 
PPTX
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
DOCX
Modul Ajar Deep Learning Bahasa Inggris Kelas 11 Terbaru 2025
wahyurestu63
 
PPTX
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
PDF
Tips for Writing the Research Title with Examples
Thelma Villaflores
 
PPTX
THE JEHOVAH’S WITNESSES’ ENCRYPTED SATANIC CULT
Claude LaCombe
 
Sonnet 130_ My Mistress’ Eyes Are Nothing Like the Sun By William Shakespear...
DhatriParmar
 
Translation_ Definition, Scope & Historical Development.pptx
DhatriParmar
 
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
Command Palatte in Odoo 18.1 Spreadsheet - Odoo Slides
Celine George
 
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
HEALTH CARE DELIVERY SYSTEM - UNIT 2 - GNM 3RD YEAR.pptx
Priyanshu Anand
 
Virat Kohli- the Pride of Indian cricket
kushpar147
 
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
Cleaning Validation Ppt Pharmaceutical validation
Ms. Ashatai Patil
 
Constitutional Design Civics Class 9.pptx
bikesh692
 
Rules and Regulations of Madhya Pradesh Library Part-I
SantoshKumarKori2
 
Basics and rules of probability with real-life uses
ravatkaran694
 
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
Modul Ajar Deep Learning Bahasa Inggris Kelas 11 Terbaru 2025
wahyurestu63
 
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
Tips for Writing the Research Title with Examples
Thelma Villaflores
 
THE JEHOVAH’S WITNESSES’ ENCRYPTED SATANIC CULT
Claude LaCombe
 

C file

  • 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