0% found this document useful (0 votes)
13 views65 pages

Programs

The document contains 14 programs demonstrating the use of basic C programming concepts like print statements, escape sequences, gotoxy function, if-else statements, nested if statements, for loops, while loops. The programs show examples to find the biggest number, calculate student results and employee salary, generate electricity bills, and print natural and even numbers in ranges.

Uploaded by

tsravyasri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views65 pages

Programs

The document contains 14 programs demonstrating the use of basic C programming concepts like print statements, escape sequences, gotoxy function, if-else statements, nested if statements, for loops, while loops. The programs show examples to find the biggest number, calculate student results and employee salary, generate electricity bills, and print natural and even numbers in ranges.

Uploaded by

tsravyasri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 65

1

Program 1
// Print Statements
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
printf ("Welcome to C World");
getch();
return 0;
}
Program 2
// Output Statements using escape sequences
// /n /t /a // /? /' /" /b
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
printf ("Welcome to C World");
printf("\n C Escape Sequences ");
getch();
return 0;
}
Program 3
// Output Statements using gotoxy function
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
gotoxy(40,5);
printf ("Welcome to C World");
gotoxy(40,6);
printf(" C Escape Sequences ");
getch();
return 0;
}
2

Program 4
// Example for simple if Statements
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int sno;
printf("\n Enter student Number..");
scanf("\n %d",&sno);
if (sno==100)
printf("Record Existed");
getch();
return 0;
}

Program 5
// Example for simple if Statements with blocks
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int sno;
printf("\n Enter student Number..");
scanf("\n %d",&sno);
if (sno==100)
{
printf("Record Existed");
printf("\n He is student in NRI");
}
getch();
return 0;
}
3

Program 6
/* Example program for if-else
Printing Biggest number from two inputs */
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int a,b;
printf("\n Enter two integers ..");
scanf("\n %d%d",&a,&b);
if (a>b)
printf("\nBig is =%d",a);
else
printf("\nBig is %d",b);
getch();
return 0;
}
Program 7
/* Example program for if-else
Printing Biggest integer from three inputs */
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int a,b,c;
printf("\n Enter two integers ..");
scanf("\n %d%d%d",&a,&b,&c);
if ((a>b) && (a>c))
printf("\nBig is =%d",a);
else
if ((b>a) && (b>c))
printf("\nBig is %d",b);
else
printf("\n Big is %d",c);
getch();
return 0; }
4

Program 8
/* Example program for if-else
Printing Biggest integer from Four inputs */
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int a,b,c,d;
printf("\n Enter two integers ..");
scanf("\n %d%d%d%d",&a,&b,&c,&d);
if ((a>b) && (a>c) && (a>d))
printf("\nBig is =%d",a);
else
if ((b>a) && (b>c) && (b>d))
printf("\n Big is %d",b);
else
if ((c>a) && (c>b) && (c>d))
printf("\n Big is %d",c);
else
printf("\n Big is %d",d);

getch();
return 0;
}
5

Program 9
/* Nested If Example 1
Caluculating Student Results */
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int sno,m1,m2,m3,tot;
char htno[15],sna[15],res,div;
float avg;
printf("Enter Student Number...");
scanf("\n %d",&sno);
printf("\n Enter Student name..");
scanf("\n %s",&sna);
printf("\n Enter Marks in Three Subjects..");
scanf("\n %d %d %d",&m1,&m2,&m3);
tot=m1+m2+m3;
avg=tot/3;
if ((m1>=50) && (m2>=50) && (m3>=50))
{
res='P';
if (avg>=75)
div='D';
else
if (avg>=60)
div='F';
else
div='S';
}
else
{
res='F';
div='N';
}
clrscr();
printf("Student Number = %d",sno);
printf("\n Student name =%s",sna);
6

printf("\n Students Marks = m1=%d , m2=%d , m3=%d",m1,m2,m3);


printf("\n Total Marks = %d",tot);
printf("\n Average Marks = %f",avg);
printf("\n Result =%c",res);
printf("\n Division = %c",div);
getch();
return 0;
}
7

Program 10
/* Electricity Bill Generation type1
Example 2 for Nested if */
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int cno,nu;
char code,cna[30];
long int lmr,cmr;
float ba,nb;
printf("\n Enter Consumer Number..");
scanf("\n %d",&cno);
printf("\n Enter Consumer Name..");
scanf("\n %s",&cna);
printf("\n Enter Last Month Meter Reading..");
scanf("\n %ld",&lmr);
printf("\n Enter Current Month Meter Reading..");
scanf("\n %ld",&cmr);
printf("\n Enter Code D/B/I ...");
scanf("\n %c",&code);
nu=cmr-lmr;
if ((code=='d') || (code=='D'))
{
if (nu<=100)
ba=nu*1.20;
else
if (nu<=200)
ba=nu*1.40;
else
if (nu<=300)
ba=nu*1.60;
else
ba=nu*1.75;
}
Else
8

if ((code=='b') || (code=='B'))
{
if (nu<=100)
ba=nu*1.50;
else
if (nu<=200)
ba=nu*1.90;
else
if (nu<=300)
ba=nu*2.20;
else
ba=nu*2.75;
}
else
{
if (nu<=100)
ba=nu*1.70;
else
if (nu<=200)
ba=nu*2.10;
else
if (nu<=300)
ba=nu*2.60;
else
ba=nu*3.75;
}
clrscr();
printf("\n Consumer Number....%d",cno);
printf("\n Consumer Name..%s",cna);
printf("\n Number of Units..%d",nu);
printf("\n Code = %c",code);
printf("\n Bill Amount ..%.2f",ba);
nb=ba+ba*10/100;
printf("\n Net Bill Amount..%.2f",nb);
getch();
return 0;
}
9

Program 11
/* Electricity Bill Generation type2
Example 3 for Nested if */
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int cno,nu;
char code,cna[30];
long int lmr,cmr;
float ba,nb;
printf("\n Enter Consumer Number..");
scanf("\n %d",&cno);
printf("\n Enter Consumer Name..");
scanf("\n %s",&cna);
printf("\n Enter Last Month Meter Reading..");
scanf("\n %ld",&lmr);
printf("\n Enter Current Month Meter Reading..");
scanf("\n %ld",&cmr);
printf("\n Enter Code D/B/I ...");
scanf("\n %c",&code);
nu=cmr-lmr;
if ((code=='d') || (code=='D'))
{
if (nu<=100)
ba=nu*1.20;
else
if (nu<=200)
ba=(100*1.20)+(nu-100)*1.40;
else
if (nu<=300)
ba=(100*1.20)+(100*1.40)+(nu-200)*1.60;
else
ba=(100*1.20)+(100*1.40)+(100*1.60)+(nu-300)*1.75;
}
10

else
if ((code=='b') || (code=='B'))
{
if (nu<=100)
ba=nu*1.20;
else
if (nu<=200)
ba=(100*1.20)+(nu-100)*1.40;
else
if (nu<=300)
ba=(100*1.20)+(100*1.40)+(nu-200)*1.60;
else
ba=(100*1.20)+(100*1.40)+(100*1.60)+(nu-300)*1.75;
}
else
{
if (nu<=100)
ba=nu*1.20;
else
if (nu<=200)
ba=(100*1.20)+(nu-100)*1.40;
else
if (nu<=300)
ba=(100*1.20)+(100*1.40)+(nu-200)*1.60;
else
ba=(100*1.20)+(100*1.40)+(100*1.60)+(nu-300)*1.75;

}
clrscr();
printf("\n Consumer Number....%d",cno);
printf("\n Consumer Name..%s",cna);
printf("\n Number of Units..%d",nu);
printf("\n Code = %c",code);
printf("\n Bill Amount ..%.2f",ba);
nb=ba+ba*10/100;
printf("\n Net Bill Amount..%.2f",nb);
getch();
return 0; }
11

Program 12
/* Nested If Example 4
Caluculating Employee Salary */

#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int eno;
char ena[30],code;
long int basic,hra,ta,da,pf,pt,gs,ns;
printf("\n Enter Employee Number..");
scanf("\n %d",&eno);
printf("\n Enter Employee Name..");
scanf("\n %s",&ena);
printf("\n Enter Employee Code (A/B/C)..");
scanf("\n %c",&code);
printf("\n Enter Basic Salary ..");
scanf("\n %ld",&basic);

if ((code=='a') || (code=='A'))
{
da=basic*40/100;
hra=basic*12/100;
ta=basic*10/100;
gs=basic+da+hra+ta;
pf=gs*10/100;
pt=gs*2/100;
ns=gs-(pf+pt);
}
else
12

if ((code=='b') || (code=='B'))
{
da=basic*42/100;
hra=basic*14/100;
ta=basic*12/100;
gs=basic+da+hra+ta;
pf=gs*12/100;
pt=gs*2/100;
ns=gs-(pf+pt);
}
else
{
da=basic*44/100;
hra=basic*16/100;
ta=basic*14/100;
gs=basic+da+hra+ta;
pf=gs*16/100;
pt=gs*2/100;
ns=gs-(pf+pt);
}
clrscr();
printf("\n Employee Number=%d",eno);
printf("\n Employee Name..=%s",ena);
printf("\n Employee Code..=%c",code);
printf("\n Employee Basic=%ld",basic);
printf("\n DA=%ld",da);
printf("\n HRA=%ld",hra);
printf("\n TA=%ld",ta);
printf("\n Gross Salary=%ld",gs);
printf("\n PF=%ld",pf);
printf("\n PT=%ld",pt);
printf("\n NetSalary=%ld",ns);

getch();
return 0;
}
13

Program 13
// Program to print natural numbers between 1 to 10
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
for (int i=1;i<=10;i++)
{
printf("\n %d",i);
}
getch();
return 0;
}
Program 13.1
// Program to print natural numbers between 1 to 10 using while loop
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int i=1;
while(i<=10)
{
printf("\n %d",i);
i++;
}
getch();
return 0;
}
14

Program 14
// Program to print even numbers between 0 to 10
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
for (int i=0;i<=10;i+=2)
{
printf("\n %d",i);
}
getch();
return 0;
}
Program 14.1
// Program to print even numbers between 0 to 10 using while
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int i=0;
while(i<=10)
{
printf("\n %d",i);
i+=2;
}
getch();
return 0;
}
15

Program 15
// Program to print odd numbers between 0 to 10
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
for (int i=1;i<=10;i+=2)
{
printf("\n %d",i);
}
getch();
return 0;
}
Program 15.1
// Program to print odd numbers between 0 to 10 using while
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int i=1
while(i<=10)
{
printf("\n %d",i);
i+=2;
}
getch();
return 0;
}
16

Program 16
// Program to print sum of natural numbers between 0 to 10
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int s=0;
for (int i=1;i<=10;i++)
{
s=s+i;
}
printf("\n %d",s);
getch();
return 0;
}
Program 16.1
// Program to print sum of natural numbers between 0 to 10 using while
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int s=0,i=1;
while(i<=10)
{
s=s+i;
i++;
}
printf("\n %d",s);
getch();
return 0;
}
17

Program 17
// Program to print sum of even numbers between 0 to 10
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int s=0;
for (int i=0;i<=10;i+=2)
{
s=s+i;
}
printf("\n %d",s);
getch();
return 0;
}

Program 17.1
// Program to print sum of even numbers between 0 to 10 using while
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int s=0,i=0;
while(i<=10)
{
s=s+i;
i+=2;
}
printf("\n %d",s);
getch();
return 0;
}
18

Program 18
// Program to print sum of odd numbers between 0 to 10
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int s=0;
for (int i=1;i<=10;i+=2)
{
s=s+i;
}
printf("\n %d",s);
getch();
return 0;
}

Program 18.1
// Program to print sum of odd numbers between 0 to 10 using while
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int s=0,i=1;
while(i<=10)
{
s=s+i;
i+=2;
}
printf("\n %d",s);
getch();
return 0;
}
19

Program 19
/* Printing natural numbers between two integers.
using for loop */

#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int a,b;
printf("\n Enter two integers..");
scanf("\n %d%d",&a,&b);
for(;a<=b;a++)
{
printf("\n %d",a);
}
getch();
return 0;
}
Program 19.1
/* Printing natural numbers between two integers
using while */
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int a,b;
printf("\n Enter two integers..");
scanf("\n %d%d",&a,&b);
while(a<=b)
{
printf("\n %d",a);
a++;
}
getch();
return 0;
}
20

Program 20
/* Printing even numbers between two integers.
using for loop */
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int a,b;
printf("\n Enter two integers..");
scanf("\n %d%d",&a,&b);
for(;a<=b;a++)
{
if ((a%2)==0 )
printf("\n %d",a);
}
getch();
return 0;
}
Program 20.1
/* Printing even numbers between two integers.
using while loop */
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int a,b;
printf("\n Enter two integers..");
scanf("\n %d%d",&a,&b);
while(a<=b)
{
if ((a%2)==0 )
printf("\n %d",a)
a++;
}
getch();
return 0; }
21

Program 21
/* Printing odd numbers between two integers.
using for loop */
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int a,b;
printf("\n Enter two integers..");
scanf("\n %d%d",&a,&b);
for(;a<=b;a++)
{
if ((a%2)!=0 )
printf("\n %d",a);
}
getch();
return 0;
}
Program 21.1
/* Printing odd numbers between two integers.
using while loop */
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int a,b;
printf("\n Enter two integers..");
scanf("\n %d%d",&a,&b);
while(a<=b)
{
if ((a%2)!=0 )
printf("\n %d",a);
a++;
}
getch();
return 0; }
22

Program 22
/* Printing sum of natural numbers between two integers.
using for loop */
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int a,b,s=0;
printf("\n Enter two integers..");
scanf("\n %d%d",&a,&b);
for(;a<=b;a++)
{
s=s+a;
}
printf("\n %d",s);
getch();
return 0;
}
Program 22.1
/* Printing sum of natural numbers between two integers.
using while loop */
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int a,b,s=0;
printf("\n Enter two integers..");
scanf("\n %d%d",&a,&b);
while(a<=b )
{
s=s+a;
a++;
}
printf("\n %d",s);
getch();
return 0; }
23

Program 23
/* Printing sum of even numbers between two integers.
using for loop */
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int a,b,s=0;
printf("\n Enter two integers..");
scanf("\n %d%d",&a,&b);
for(;a<=b;a++)
{
if ((a%2)==0)
s=s+a;
}
printf("\n %d",s);
getch();
return 0;
}
Program 23.1
/* Printing sum of even numbers between two integers.
using while loop */
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int a,b,s=0;
printf("\n Enter two integers..");
scanf("\n %d%d",&a,&b);
while(a<=b)
{
if ((a%2)==0)
s=s+a;
a++;
}
printf("\n %d",s); getch(); return 0; }
24

Program 24
/* Printing sum of odd numbers between two integers.
using for loop */
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int a,b,s=0;
printf("\n Enter two integers..");
scanf("\n %d%d",&a,&b);
for(;a<=b;a++)
{
if ((a%2)!=0)
s=s+a;
}
printf("\n %d",s);
getch();
return 0;
}
Program 24.1
/* Printing sum of odd numbers between two integers.
using while loop */
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int a,b,s=0;
printf("\n Enter two integers..");
scanf("\n %d%d",&a,&b);
while(a<=b)
{
if ((a%2)!=0)
s=s+a;
a++;
}
printf("\n %d",s); getch(); return 0; }
25

Program 25
// Printing Count of Digits from given Integer
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int n,s=0;
printf("\n Enter Integer..");
scanf("\n %d",&n);
while(n>0)
{
s=s+1;
n=n/10;
}
printf("\n Count of Digits=%d",s);
getch();
return 0; }
Program 26
// Printing Sum of Digits from given Integer
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int n,r,s=0;
printf("\n Enter Integer..");
scanf("\n %d",&n);
while(n>0)
{
r=n%10;
s=s+r;
n=n/10;
}
printf("\n Sum of Digits=%d",s);
getch();
return 0;}
26

Program 27
// Printing Reverse digits from given Integer
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int n,r,s=0;
printf("\n Enter Integer..");
scanf("\n %d",&n);
while(n>0)
{
r=n%10;
s=s*10+r;
n=n/10;
}
printf("\n Reverse Digits=%d",s);
getch();
return 0;
}
Program 28
// Printing Biggest of Digits from given Integer
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int n,r,s=0;
printf("\n Enter Integer..");
scanf("\n %d",&n);
while(n>0)
{
r=n%10;
if (r>s)
s=r;
n=n/10;
}
printf("\n Biggest Digit=%d",s); getch(); return 0; }
27

Program 29
// Printing Smallest digit from given Integer
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int n,r,s=9;
printf("\n Enter Integer..");
scanf("\n %d",&n);
while(n>0)
{
r=n%10;
if (r<s)
s=r;
n=n/10;
}
printf("\n Smallest Digit=%d",s);
getch();
return 0;
}
Program 30
// Swaping two integer values with other variable
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int a,b,c;
printf("\n Enter two integers...");
scanf("\n %d%d",&a,&b);
c=a+b;
a=c-a;
b=c-b;
printf("\n a=%d",a);
printf("\n b=%d",b);
getch();
return 0; }
28

Program 31
// Swapping two integers without extra variable
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int a,b,c;
printf("\n Enter two integers...");
scanf("\n %d%d",&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf("\n a=%d",a);
printf("\n b=%d",b);
getch();
return 0;
}
Program 32
// Lucky Number
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int a,b,c,r,t,s;
printf("\n Enter Start Number..");
scanf("\n %d",&a);
printf("\n Enter Ending Number..");
scanf("\n %d",&b);
printf("\n Enter Lucky Number..");
scanf("\n %d",&c);
29

for(;a<=b;a++)
{
t=a;
s=0;
while(t>0)
{
r=t%10;
s=s+r;
t=t/10;
}
if (c==s)
printf("\n %d",a);
}
getch();
return 0;
}
Program 33
// Math.Table model 1
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int a;
printf("\n Enter Math.Table..");
scanf("\n %d",&a);
for(int i=1;i<=10;i++)
{
printf("\n %d x %d = %d",a,i,a*i);
}
getch();
return 0;
}
30

Program 34
// Math.Table model 2

#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int a,b,i,t;
printf("\n Enter star. End. Math.Table..");
scanf("\n %d%d",&a,&b);
for(;a<=b;a++)
{
for(i=1;i<=10;i++)
{
printf("\n %d x %d = %d",a,i,a*i);
}
getch();
clrscr();
}
getch();
return 0;
}

Program 35

// Math.Table model 3
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int a,b,c,d,i,t;
printf("\n Enter star. End. Math.Table..");
scanf("\n %d%d",&a,&b);
printf("\n Enter star.End. numbers..");
scanf("\n %d%d",&c,&d);
31

for(;a<=b;a++)
{
for(i=1;i<=10;i++)
{
printf("\n %d x %d = %d",a,i,a*i);
}
getch();
clrscr();
}
getch();
return 0;
}

Program 36

// Integer to Binary Conversion

#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int n;
printf("Enter Number to convert");
scanf("\n %d",&n);
while(n>0)
{
printf("%d",n%2);
n=n/2;
}
getch();
return 0;
}
32

37) right most digit from given integer.

// right most digit from given integer.


#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int n,r;
printf("\n Enter Integer..");
scanf("\n %d",&n);
r=n%10;
printf("%d",r);
getch();
return 0;
}

38) Smallest of three integer

// smallest of three integer


#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int a,b,c;
printf("\n Enter three Integers..");
scanf("\n %d%d%d",&a,&b,&c);
if ((a<b) && (a<c))
printf("\n Least is a");
else
if ((b<a) && (b<c))
printf("\n Least is b");
else
printf("\n Least is c");
getch();
return 0;
}
33

39) Left most digit from given integer


// Left most digit from given integer
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int n,r,s=0;
printf("\n Enter Integer..");
scanf("\n %d",&n);
while(n>0)
{
r=n%10;
n=n/10;
}
printf("\n Left most digit for given integer=%d",r);
getch();
return 0;}

40) Printing quotient and remainder values from given integer

// Printing quotient and remainder values from given integer


#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int n,r;
printf("\n Enter Integer..");
scanf("\n %d",&n);
printf("\n Quotient value=%d",n/10);
printf("\n Remainder value=%d",n%10);
getch();
return 0;
}
34

41) Converting Character to Integer

// Converting Character to Integer


#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
char c;
printf("\n Enter Character..");
scanf("\n %c",&c);
printf("\n %d",c);
getch();
return 0;
}
42) Type casting example

// type casting example


#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int a;
float b;
printf("\n Enter Integer value..");
scanf("\n %d",&a);
printf("\n Enter Float value..");
scanf("\n %f",&b);
printf("\n %f",a+b);
printf("\n %d",int(a+b));
getch();
return 0;
}
35

43) Type casting example


// type casting example

#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int a;
float b;
int c;
printf("\n Enter Integer value..");
scanf("\n %d",&a);
printf("\n Enter Float value..");
scanf("\n %f",&b);
c=a+int(b);
printf("\n %d",c);
getch();
return 0;
}

44) Program to find the area & circumference of a circle

// Program to find the area & circumference of a circle


#include<conio.h>
#include<stdio.h>
int main()
{
clrscr();
int r;
float pi=3.14;
float cir,area;
printf("\n enter the radius of the circle");
scanf("%d",&r);
cir=2*pi*r;
area=pi*r*r;
printf("\nthe circumference of the circle is%.2f",cir);
printf("\nthe area of the circle is %.2f",area);
getch();
return 0;
}
36

45) Interest Calculations model 1

// Interest Calculations model 1


#include<stdio.h>
#include<conio.h>
int main()
{
int p,n;
float r,sum;
clrscr();
printf("\n Enter Principal Amount ..");
scanf("\n %d",&p);
printf("\n Number of Years..");
scanf("\n %d",&n);
printf("\n Entr Rate of Interest..");
scanf("\n %f",&r);
sum=p*r/100*n;
printf("\n Rate of Interest values =%.2f",sum);
getch();
return 0;
}

46) Interest Calculations model 2


// Interest Calculations model2
#include<stdio.h>
#include<conio.h>
int main()
{
int p,n;
float r,sum;
clrscr();
printf("\n Enter Principal Amount ..");
scanf("\n %d",&p);
printf("\n Number of Years..");
scanf("\n %d",&n);
printf("\n Entr Rate of Interest..");
scanf("\n %f",&r);
sum=0;
for(int i=1;i<=n;i++)
{
sum=sum+p*r/100;
p=p+sum;
printf("\n Rate of Interest values =%.2f",sum);
}
getch();
return 0; }
37

48) Temparature conversion


// temparature conversion
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
float temp_s,temp_f;
printf("\n Enter temperature in Celcius..");
scanf("\n %f",&temp_s);
temp_f=(1.8*temp_s)+32;
printf("\n Temperature n Fahreinheit is :%.2f",temp_f);
getch();
return 0;
}
49) Income tax Calculation
// Incometax Calculation
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
long int income,nincome;
printf("\n Enter Annual Income..");
scanf("\n %ld",&income);
nincome=income-200000;
if (nincome<0)
printf("No tax");
else
if (nincome<=300000)
printf("\n %ld",nincome*10/100);
else
if (nincome<=700000)
printf("\n %ld",nincome*20/100);
else
printf("\n %ld",nincome*30/100);
getch();
return 0;}
38

51) Program to calculate (a+b)2


// printing (a+b)2
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int a,b;
printf("\n Enter two integers...");
scanf("\n %d%d",&a,&b);
printf("\n %d",a*a+b*b+2*a*b);
getch();
return 0;
}
53) fibonacci Series Example

// fibonacci Series Example


#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int n,a=0,b=1,c;
printf("\n Enter Number of Iterations..");
scanf("\n %d",&n);
printf("\t %d\t%d",a,b);
for (int d=1;d<=n;d++)
{
c=a+b;
printf("\t %d",c);
a=b;
b=c;
}
getch();
return 0;
}
39

53_1) fibonacci Series Example

// Checking fibanacci or not


#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int a=0,b=1,c,n;
printf("\n Enter number to check for fibanacci..");
scanf("\n %d",&n);
//printf("\t %d \t%d",a,b);
for(int i=1;i<=n;i++)
{
c=a+b;
a=b;
b=c;
if (c==n)
{
printf("Fibanacci Series");
break;
}

}
getch();
return 0;
}
40

54) Program to check Prime number or not


// Checking whether it is prime number or not
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int n;
printf("\n Enter Number...");
scanf("\n %d",&n);
int s=0;
for(int i=1;i<=n;i++)
{
if ((n%i)==0)
s=s+1;
if (s>=3)
break;
}
if (s==2)
printf("It is prime number");
else
printf("\n It is not prime number");
getch();
return 0;
}
41

55) Printing prime numbers between two integers


// printing Prime numbers between two integers.
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int a,b;
printf ("\n Enter two integers..");
scanf("\n %d%d",&a,&b);
for (;a<=b;a++)
{
int s=0;
for(int i=1;i<=a;i++)
{
if ((a%i)==0)
s=s+1;
if (s>=3)
break;
}
if (s==2)
printf("\n %d",a);
}
getch();
return 0;
}
42

56) Program to check Palindrome number or not

// Checking whether given number is palimdrome number or not


#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int n,t,r,s=0;
printf("\n Enter Integer..");
scanf("\n %d",&n);
t=n;
while(n>0)
{
r=n%10;
s=s*10+r;
n=n/10;
}
if (s==t)
printf("\n Palimdrome number..");
else
printf("\n It is not palimdrome number");
getch();
return 0;
}
43

57) Printing Palindrome numbers between two integers


// printing palimdrome numbers between two integers
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int a,b,t,r,s;
printf("\n Enter two Integer..");
scanf("\n %d%d",&a,&b);
for(;a<=b;a++)
{
t=a;
s=0;
while(t>0)
{
r=t%10;
s=s*10+r;
t=t/10;
}
if (s==a)
printf("\n %d",s);
}
getch();
return 0;
}
44

58) Checking Factorial value for given integer

// Checking Factorial Number for given integer


#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int n,s=1;
printf("\n Enter Integer..");
scanf("\n %d",&n);
while(n>0)
{
s=s*n;
n--;
}
printf("\n Factorial Value=%d",s);
getch();
return 0;
}
45

59) Printing factorial values from given two integers


// Factorial value between two integers.
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int a,b, n,s;
printf("\n Enter two Integer..");
scanf("\n %d%d",&a,&b);
for(;a<=b;a++)
{
n=a;
s=1;
while(n>0)
{
s=s*n;
n--;
}
printf("\n %d Factorial Value=%d",a,s);
}
getch();
return 0;
}
46

60) Checking whether it is Armstrong number or not

//Checking whether it is aramstrong number or not


#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int n,r,s=0,t;
printf("\n Enter Number..");
scanf("\n %d",&n);
t=n;
while(t>0)
{
r=t%10;
s=s+r*r*r;
t=t/10;
}
if (n==s)
printf("\n AramStrong Number");
else
printf("\n Not AramStrong Number");
getch();
return 0;
}
47

61) Printing Armstrong numbers between two integers

//Printing aramstrong numbers between two integers.


#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int a,b,r,s,t;
printf("\n Enter two integers..");
scanf("\n %d%d",&a,&b);
for(;a<=b;a++)
{
t=a;
s=0;
while(t>0)
{
r=t%10;
s=s+r*r*r;
t=t/10;
}
if (a==s)
printf("\n %d",s);
}
getch();
return 0;
}
48

62) Checking whether it is strong number or not

// Checking whether it is Strong Number or not


#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int s,r,n,t=0,k;
printf("\n Enter two Integer..");
scanf("\n %d",&k);
n=k;
while(n>0)
{
r=n%10;
s=1;
while(r>0)
{
s=s*r;
r--;
}
t=t+s;
n=n/10;
}
if (k==t)
printf("\n Strong Number=%d",t);
else
printf("\n It is not Strong Number");
getch();
return 0;
}
49

63) Printing Strong numbers between two integers

// Strong Number between two integers.

#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int t,a,b, s,r,n;
printf("\n Enter two two Integer..");
scanf("\n %d%d",&a,&b);

for(;a<=b;a++)
{
t=0;
n=a;
while(n>0)
{

r=n%10;
s=1;
while(r>0)
{
s=s*r;
r--;
}
t=t+s;
n=n/10;

}
if (t==a)
printf("\n%d= %d",a,t);
}
getch();
return 0;
}
50

64) Scrolling text from left to right


// scrolling text from left to right
#include<stdio.h>
#include<conio.h>
#include<dos.h>
int main()
{
clrscr();
for (int i=1;i<=70;i++)
{
gotoxy(i,6);
printf(" Welcome");
delay(100);
}
getch();
return 0;
}
65) Scrolling text from right to left
// scrolling text from left and right
#include<stdio.h>
#include<conio.h>
#include<dos.h>
int main()
{
clrscr();
int i=1,j=75;
for (;i<=35;i++)
{
gotoxy(i,6);
printf(" Welcome");
gotoxy(j,6);
printf("goodbye ");
j--;
delay(100);
}
getch();
return 0;
}
51

66) Printing pyramid


// pyramid shape
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
for (int i=1;i<=5;i++)
{
for(int j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
getch();
return 0;
}
52

67) Switch case example 1 (using character)


// switch case example
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
char wc;
printf("\n Enter Week code (M/T/W/H/F/S");
scanf("\n %c",&wc);
switch(wc)
{
case 'M':
case 'm':
printf("\n Monday");
break;
case 'T':
case 't':
printf("\n Tuesday");
break;
case 'W':
case 'w':
printf("\n Wednesday");
break;
case 'H':
case 'h':
printf("\n Tuursday");
break;
case 'F':
case 'f':
printf("\n Friday");
break;
case 'S':
case 's':
printf("\n Saturday");
break;
}
getch(); return 0; }
53

68) Switch case example 2 (using integer)


// switch case example
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int d;;
printf("\n Enter Number 1 to 3 :");
scanf("\n %d",&d);
switch(d)
{
case 1:
printf("\n One");
break;
case 2:
printf("\n Two");
break;
case 3:
printf("\n Three");
break;
default:
printf("\n Invalid number");
}
getch();
return 0;
}
54

69) do-while example 1


// do while example 1
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int i;
do
{
printf("\n Enter I value 1to3 or to exit-4 :");
scanf("\n %d",&i);
printf("\n i value =%d",i);
}while(i<=3);
getch();
return 0;
}
70) do-while example 2
// do while example 2
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int i;
do
{
clrscr();
printf("\n 1.Add...");
printf("\n 2.Sub...");
printf("\n 3.Mul...");
printf("\n 4.Exit..");
printf("\n Enter Choice...");
scanf("\n %d",&i);
}while(i<=3);
getch();
return 0; }
55

71) do-while example 3


// do while example 3
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int i;
do
{
clrscr();
printf("\n 1.Add...");
printf("\n 2.Sub...");
printf("\n 3.Mul...");
printf("\n 4.Exit..");
printf("\n Enter Choice...");
scanf("\n %d",&i);
switch(i)
{
case 1:
{
printf("\none");
getch();
clrscr();
break;
}
case 2:
{
printf("\ntwo");
getch();
clrscr();
break;
}
case 3:
{
printf("\nthree");
getch();
clrscr();
56

break;
}
default:
printf("\ninvalid");
}
}while(i<=3);
getch();
return 0;
}
72) do-while example 4
// do while example 4
#include<stdio.h>
#include<conio.h>
int a,b;
int main()
{
clrscr();
int i;
do
{
clrscr();
printf("\n 1.Add...");
printf("\n 2.Sub...");
printf("\n 3.Mul...");
printf("\n 4.Exit..");
printf("\n Enter Choice...");
scanf("\n %d",&i);
switch(i)
{
case 1:
{
printf("\n Enter two integers");
scanf("\n %d%d",&a,&b);
printf("\n Addition=%d",a+b);
getch();
clrscr();
break;
}
57

case 2:
{
printf("\n Enter two integers");
scanf("\n %d%d",&a,&b);
printf("\n Addition=%d",a-b);
getch();
clrscr();
break;
}
case 3:
{
printf("\n Enter two integers");
scanf("\n %d%d",&a,&b);
printf("\n Addition=%d",a*b);
getch();
clrscr();
break;
}
default:
printf("\ninvalid");
}
}while(i<=3);
getch();
return 0;
}
58

73) do-while example 5

// do while example 4
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int i;
printf("\n Enter I value..");
scanf("\n %d",&i);
do
{
printf("\n i value =%d",i);
i++;
}while(i<=10);
getch();
return 0;
}

74) Break and continue Examples


// break and continue example

#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
for(int i=1;i<=10;i++)
{
if(i==3)
continue; //break
printf("\n %d",i);
}
getch();
return 0;
}
59

77) Biggest of given two integers using conditional operator

// Biggest of given two integers using conditional operatorf


#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int a,b;
printf("\n Enter two integers..");
scanf("\n %d%d",&a,&b);
int c= (a>b) ?a :b ;
printf("\n Big is =%d",c);

getch();
return 0;
}

78) Bitwise Operator Examples

// Bit-wise Operations Example

#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int a=6; // ex: 0110
int b=3; // ex: 0011

printf("\n %d",a&b); //output 0010 = 2


printf("\n %d",a|b); // 0111= 7
printf("\n %d",a^b); //5
printf("\n %d",a>>1); //3
printf("\n %d",a<<1); //12
printf("\n %d",~a);
getch();
return 0; }
60

79) x=12+22+32….
// power of integer
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int s=0;
int a,b;
printf("\n Enter two integers :");
scanf("\n %d%d",&a,&b);
for(;a<=b;a++)
{
s=s+a*a;
}
printf("\n sqares of a= %d",s);
getch();
return 0;
}
61

1 Algorithm
2 PSEUDOCODE
3 FLOWCHARTS
4 Program Development Steps
5 Introduction to “C” Language / Features, Advantages & Disadvantages
6 Structure of C Program
7 Character set
8 C Tokens or Constants
9 Backslash Constants
10 Variables or scope of variable
11 Precedence and order of Evaluation
12 Data Types
13 TYPE CONVERSIONS / TYPE CASTING
14 OPERATORS
15 Computer Languages
16 Language Translators (Compiler and Interpreter)
17 Input and Output Statements
18 Control Statement (if-else & Nested If Statements….)
19 Arrays
20 Functions
21 Local Variables and Global Variables
22 Storage Classes
23 Structures
24 Unions
25 Difference between Structure and Union
26 Pointers
27 BITFIELD
28 C PRE-PROCESSOR
29 Dynamic Memory Allocation
30 Header Files
62

1) Algorithm
Definition:
The word “algorithm” means “calculation method”. An algorithm is a finite list of well-defined
instruction. Algorithm means procedures for solving mathematical problems. An algorithm is
step-by-step explanation of a process. It consists of the logical steps necessary to solve a
problem in a computer.

Features of an algorithm:
Finiteness: An algorithm terminates after a fixed number of steps.
Definiteness: Each step of the algorithm is precisely defined.
Effectiveness: All the operations used in the algorithm can be performed exactly in a fixed
duration of time.
Input: An algorithm has certain precise inputs.
Output: An algorithm has one or more outputs.

Example 1:
Algorithm to pick the largest of three numbers.

Step 1: Read A, B, C.
Step 2: if A>B go to step 3.
Else go to step 5
Step 3: if A>C Print A is the largest number
Else Print C is the largest number.
Step 4: Stop.
Step 5: if B>C print B is the largest number.
Else print C is the largest number.
Step 6. Stop.
63

2) PSEUDOCODE

Pseudo Code is a problem Solving Tool. It is the first step in writing a program. It consists of
English like statements that follow a loosely defined syntax and are used to convey the design
of an algorithm. It is an intermediate step in writing a program. It is an aid in writing the
program. It comes from the English language description of a program. It helps to translate
from an English language description of a problem to a program written in a programming
language like C. The goal of writing Pseudo Code is to provide a high-level description of an
algorithm, which facilitates analysis and final coding. Algorithms will often be expressed in
Pseudo Code.
General guidelines for checking the Pseudo Code.
1) Mimic good code and good English. Variable names
be mnemonic, comments be included.
2) Ignore unnecessary details. Use some convention to
group statements (begin /end, brackets)
3) Take advantage of programming shorthand’s. Using if-
then-else or looping structures.
64

3) FLOWCHARTS

Flowchart is a program design tool .In flowcharts standard symbols are used to represent the
logical flow of data through a function. It is a computer-programming tool. The main purpose of
Flowchart is design of an algorithm. It is a pictorial representation of an algorithm. A Flowchart
is simply a method of assisting the programmer to layout in visual, two dimensional formats.
Uses of Flow Charts:
1) Flowcharts are an excellent means of communication and they impart ideas to others.
2) Flowcharts provide an overview of the entire problem and its algorithm for solution.
3) Flowcharts facilitate coding and modification of programs.
4) Flowcharts provide a permanent recording of program logic.
5) Flowcharts show all major elements and their relationships.

Symbols used with Flowcharts:

Name Symbol Purpose


Terminal Oval Beginning / End of the
Flowchart
Input /Output Input / Output Data
Parallelogram

Process Mathematical calculations,


Rectangle
data transfer and logic
operations.

Decision Making Diamond /Rhombus Alternate paths

Connector Transfer to another point in


Circle the flow chart

Flow Direction Arrow Path of a logic flow in a


program
65

4) Program Development Steps

Program Development is a multi step process. It requires understanding the problem,


developing a solution, writing the program, and then testing. It is a system development activity
in which requirement specifications are converted into executable programs.

Problem Definition: Problem definition includes the specification of inputs and outputs
processing requirements, system constraints and error-handling methods. It includes many
factors such as input, output, time constraints, process requirements accuracy, memory
limitations, error handlings and interfaces.
Program Design: Flowcharting techniques are used in describing program structure. Program
design techniques are Flowcharting, top-down design, structured programming and modular
programming. In Modular programming, programs are divided into smaller programs or
modules. And in top-down design generalized subtasks that are subsequently defined.

Coding: Translates the program design into computer instructions.


Debugging: Bug means error. Debugging is finding and correcting the program errors.
Testing: Testing is the validation of the program.
Documentation: Proper documentation is useful in the debugging and testing stages and is also
essential in the maintenance and redesign stages.
Maintenance: Updating and correcting of the program to account for changing conditions.
Redesign: It involves new features or meeting new requirements.

You might also like