1. program:
/* name using with caret sequence:*/
#include<stdio.h>
#include<conio.h>
void main()
{
char yname[30];
clrscr();
printf(“n Your good name please:”);
scanf(“%[^n]“,yname);
clrscr();
printf(“n Hello!….%s”,yname);
printf(“n Happy Frinedship Day!…”);
getch();
}
2. Program:
/*area of triangle when base and height is there…….*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int h,b;
float area;
clrscr();
printf(“Enter the base:”);
scanf(“%d”,&b);
printf(“Enter the height”);
scanf(“%d”,&h);
area=b*h/2;
printf(“n area of the triangle is:%f”,area);
getch();
}
3rd program:
/* find out area of triangle*/
/* formula is sqrt(s(s-a)*(s-b)*(s-c))*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,p;
float s,area;
clrscr();
printf(“n enter the 3 sides of a traingle:”);
scanf(“%d %d %d”,&a,&b,&c);
p=a+b+c;
s=p/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf(“n area of traingle: %f”,area);
getch();
}
4th program:
/* write a program find out leap year using with terminary operator */
#include<stdio.h>
#include<conio.h>
void main()
{
int year;
clrscr();
printf(“Enter any 4 digit number:”);
scanf(“%d”,&year);
(year%4==0) ?printf(“leap year”):printf(“non leap year”);
getch();
}
5th program:
/*write a programe to find wheather group number is even or odd
using with conditional operator or terminary operator*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
printf(“Enter the value of a:”);
scanf(“%d”,&a);
(a%2==0) ?printf(“even”):printf(“odd”);
getch();
}
6th program:
/* find out area of circle*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int r;
float area;
clrscr();
printf(“Enter the value of radius:”);
scanf(“%d”,&r);
area=3.1428*r;
printf(“n area of the circle is %f”,area);
getch();
}
7th program:
/* FOREIGN HEAT caliculation*/
#include<stdio.h>
#include<conio.h>
void main()
{
float fh,cel;
fh=50;
cel=fh-32/9*5;
clrscr();
printf(“foreign heat=%fn”,fh);
printf(“celcius=%f”,cel);
getch();
}
8th program:
/* Another model to find the foreign heat caliculation*/
#include<stdio.h>
#include<conio.h>
void main()
{
float c,f;
printf(“n Enter temparature in celcious:”);
scanf(“%f”,&c);
f=(1.8*c)+32;
printf(“Equivalent fahrenheit: %fn”,f);
printf(“n Enter temparature in fahrenhet”);
scanf(“%f”,&f);
c=(f-32)/1.8;
printf(“n Equilent celcious is: %fn”,c);
getch();
}
9th program:
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
printf(“Enter your name:”);
scanf(“%[^n]“,ch);
printf(“Hello!…..%s”,ch);
printf(“n Welcome to My c programes”);
getch();
}
10th program:
/* numbers in Hexa…Octal……Decimal conversion…..*/
#include<stdio.h>
#include<conio.h>
void main()
{
int num;
clrscr();
printf(“n Enter an integer:”);
scanf(“%i”,&num);
printf(“n Number in Decimal =%i”,num);
printf(“n Number in Hexadecimal=%x”,num);
printf(“n Number in Octal =%o”,num);
getch();
}
11th program:
/* size of program */
#include<stdio.h>
#include<stdlib.h>
main()
{
int x;
float y;
clrscr();
x=printf(“n the float is:%f”, sizeof(float);
getch();
}
/*main()
{
int a,b,c,d;
a=10;
b=7;
c=15;
clrscr();
d=(a>b)?printf(“%dn”,a):printf(“%dn”,b);
(d>c)?printf(“Hello”):printf(“welcome”);
/* (a>b)?printf(“hello”):printf(“welcome”);*/
getch();
}
12th program:
/*find out caliculate the simple interest*/
#include<stdio.h>
#include<conio.h>
void main()
{
int p,n,r,si,tot;
clrscr();
printf(“Enter the principle value:”);
scanf(“%d”,&p);
printf(“Enter the number of years:”);
scanf(“%d”,&n);
printf(“Enter the rate of interest:”);
scanf(“%d”,&r);
si=p*n*r/100;
tot=p+si;
printf(“The simple interest is:%dn”,si);
printf(“nThe total amount is:%d”,tot);
getch();
}
13th program:
/*find out sum of two numbers*/
#include<stdio.h>
#include<conio.h>
void main()
{
a=30;
b=40;
c=40;
c=a+b;
clrscr();
printf(“A value is :%d”,a);
printf(“B value is :%d”,b);
printf(“C value is :%d”,c);
getch();
}
14th program:
/* sum of n numbers*/
/* formula is n(n+1)/2 …….*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int n;
float s;
clrscr();
printf(“Enter limit of n value:”);
scanf(“%d”,&n);
s=n*(n+1)/2;
printf(“Sum :%d num is :%f”,n,s);
getch();
}
15th program:
/* sum of sqares mean 1sq+2sq+3sq+……………nsq*/
/*fomula is s=n*(n+1)+(2*n)+1))/6*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int n,s;
clrscr();
printf(“Enter the value for n:”);
scanf(“%d”,&n);
s=(n*(n+1)*(2*n)+1)/6;
printf(“n sum of squares of %d nos is %d”,n,s);
getch();
}
16th program:
#include<stdio.h>
#include<stdlib.h>
main()
{
int x;
float y=13.45;
clrscr();
x= printf(“The size of float is: %d”,sizeof(float));
getch();
}
Control statements (or)
Control structures
——————-
C is considered as a structure programming language. One of the reason
for this is having various program control structures.
C process the decision making capability and supports the statements
Known as control statements.
There are 3 types of Control statements supported by C.
1. Conditional control statements.
2. Un-conditional control statements.
3. Loop control statements.
1. Conditional control statements:-
C supports 5 types of conditional control statements.
1. Simple if statement.
2. If-else statement.
3. Nested if statement
4. Else if ladder
5. Switch statement.
1. simple if statement:-
It is a decision making statment and is used to control
flow of execution.
syn:- if(expresion)
{
statments;
}
2.If-else statement :-
It is an extension of simple if statement.
syn:-
if(expression)
{
statements-1;
}
else
{
statements-2;
}
3.Nested if statement:-
Using a if statement within another if statement is known as
Nested if statement.
If series of decisions are involved in a program we use
Nested if.
syn:- 1.
if(expr-1)
{
if(expr-2)
{
if(expr-3)
{
——-
——-
——-
if(expr-n)
{
statements;
}
}
}
syn:-2.
if(expr-1)
{
if(expr-2)
{
statements-1;
}
else
{
statements-2;
}
}
else
{
if(expr-3)
{
statement-3;
}
else
{
statements-4;
}
}
4. Else-if Ladder:-
It is also used for series of decissions are involved.
syn:-
if(exp-1)
{
statements-1;
}
else if(exp-2)
{
statements-2;
}
else if(exp-3)
{
statements-3;
}
—————
—————
—————
else if(exp-n)
{
statements-n;
}
else
{
statements;
}
5.Switch statement:-
It is multiway conditional statement used in C language.In situations
where there is need to pick one alternative in many alternative we have to
use Switch statement.
syn:-
switch(expresion (or) variable)
{
case 1:
statements-1;
break;
case 2:
statements-2;
break;
case 3:
statements-3;
break;
———————–
———————–
———————–
case n:
statements-n;
break;
default:
default statements;
}
break:-
It is an unconditional control statement which is used to terminate
from switch statement.
syn:- break;
NOTE:-
1.In switch statement, it can accept only integral value.
(i.e.., int (or) char)
2.It can not accept string (or) float value.
3.In switch statement , default block is optional.
UNCONDITIONAL CONTROL STATEMENTS
——————————–
1.break:- ( keyword )
It passes control
syn:- break;
The break statement causes control to pass to the statement following
the innermost enclosing while , do , for (or) switch statement.
2.continue:- (keyword)
It passes control.
syn:- continue;
It causes control to pass to the end of the innermost enclosing
while , do (or) for statement at which point the loop continuation
condition is re-evaluated.
3.goto:- (key word)
The ‘goto’ statement is an unconditional control statement which is
used up the execution of program sequence by transfer of control to
the some other part of the program.
syn:- goto label;
Where label is ‘C’ valid identifier and is used to the destination
such that the control could transferred.
syn:- identifier:
LOOP CONTROL STATEMENTS
———————–
Loop:-
The process of repeated execution of a block of statements is called
loop.
C supports 3 types of looping statements.They are
1. While loop
2. Do-while loop
3. for loop
Any loop has 3 things.They are
1. Initialize the index
2. Test condition
3. Update the index
1. While loop:-
It is a conditional control loop statement in C language.
syn:-
while(test condition)
{
statements;
}
First thet test condition is evaluated and if it is true then
the statements block will be executed.After the execution of statements the
test condition is evaluated once again. Then if it is true,The statements
block will be executed once agin.This process of repeated execution continue
untill the test condition finally becomes false.
2. do-while loop:-
It is an alternative form of while loop.The only difference between while
and do while is the minimum no of execution of while is ‘0′ for mininum
no of execution of dowhile is ‘1′.
syn:-
do
{
statements;
}while(test condition);
First the statement block will be executed and then test
condition will be evaluated.If the condition is true then
the statement block will be executed once again.This process
of repeated execution continuous until the test condition
finally becomes false.
3. For loop:-
It is the most commonly used loop control statement in
‘C’ language.It consisting of 3 expressions.
syn:-
for(exp1;exp2;exp3)
{
statements;
}
The first expresion is used to initialize the index,
second expression is used to check whether the loop
is to be continued (or) not,third expression is used
to change the index for further iteration(increment
(or) decrement).
Nested Loops:-
Using a loop statement with in another loop statement is known as
Nested loop.
IF Condition Programs:
17th program:
* Ascii scan code */
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
printf(“n press any a key :”);
ch=getch();
if(ch==0)
{
printf(“n Ascii code=%d”,ch);
ch=getch();
printf(“n scanf code=%d”,ch);
}
else
printf(“n Ascii code=%d”,ch);
getch();
}
18th program:
/* find out biggest in two numbers*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf(“Enter A value:”);
scanf(“%d”,&a);
printf(“Enter B value:”);
scanf(“%d”,&b);
if(a>b)
printf(“A value is big”);
else if(b>a)
printf(“B value is big”);
else
printf(“Both are equal”);
getch();
}
19th program:
/* find out biggest in two numbers*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf(“Enter A value:”);
scanf(“%d”,&a);
printf(“Enter B value:”);
scanf(“%d”,&b);
if(a>b)
printf(“A value is big”);
else if(b>a)
printf(“B value is big”);
else
printf(“Both are equal”);
getch();
}
20th Program:
/* find out biggest in 3 nos */
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf(“Enter A value:”);
scanf(“%d”,&a);
printf(“Enter B value:”);
scanf(“%d”,&b);
printf(“Enter c value:”);
scanf(“%d”,&c);
if((a>b)&&(a>c))
printf(“A value is big”);
else if((b>a)&&(b>c))
printf(“B value is big”);
else if((c>a)&&(c>b))
printf(“C value is big”);
else
printf(“All are Equal”);
getch();
}
21st Program:
/* find out biggest in 3 nos */
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf(“Enter A value:”);
scanf(“%d”,&a);
printf(“Enter B value:”);
scanf(“%d”,&b);
printf(“Enter c value:”);
scanf(“%d”,&c);
if((a>b)&&(a>c))
printf(“A value is big”);
else if((b>a)&&(b>c))
printf(“B value is big”);
else if((c>a)&&(c>b))
printf(“C value is big”);
else
printf(“All are Equal”);
getch();
}
22nd Program:
/* abs() */
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int num=-123;
clrscr();
printf(“absolute value=%d”,abs(num));
getch();
}
23rd Program:
/* print 3 integers in assending order */
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf(“Enter the values of A,B,C:”);
scanf(“%d %d %d”,&a,&b,&c);
if((a>b)&&(a>c))
{
if(b>c)
{
printf(“%d %d %d”,c,b,a);
}
else
{
printf(“%d %d %d”,b,c,a);
}
}
else if((b>a)&&(b>c))
{
if(a>c)
{
printf(“%d %d %d”,c,a,b);
}
else
{
printf(“%d %d %d”,a,c,b);
}
}
else if((c>a)&&(c>b))
{
if(a>b)
{
printf(“%d %d %d”,b,a,c);
}
else
{
printf(“%d %d %d”,a,b,c);
}
}
getch();
}
24th Program:
/* FIND THE AGE OF THE PERSON FOR GIVEN BIRTH DATE & CURRENT DATE */
#include<stdio.h>
#include<conio.h>
void main()
{
int cy,cm,cd;
int by,bm,bd;
int yy,mm,dd;
clrscr();
printf(“Enter current date(yy/mm//dd):”);
scanf(“%d %d %d”,&cy,&cm,&cd);
printf(“nEnter birth day date(yy/mm//dd):”);
scanf(“%d %d %d”,&by,bm,bd);
yy=cy-by;
mm=cm-bm;
dd=cd-bd;
if(dd<0)
{
mm=mm-1;
dd=dd+30;
}
if(mm<0)
{
yy=yy-1;
mm=mm+12;
}
printf(“Age is (yy/mm/dd):%d %d %d”,yy,mm,dd);
getch();
}
25th Program:
/* write a program caliculator program */
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
char op;
clrscr();
printf(“Enter the A value:”);
scanf(“%d”,&a);
printf(“Enter the B value:”);
scanf(“%d”,&b);
printf(“Enter the operator(+,-,*,/,%):”);
fflush(stdin);
scanf(“%c”,&op);
if(op==’+')
printf(“Sum of 2 nos is %d and %d in %d”,a,b,a+b);
else if(op==’-')
printf(“Subtraction of 2 nos is %d and %d in %d”,a,b,a-b);
else if(op==’*')
printf(“Multiplicatation of 2 nos is %d and %d in %d”,a,b,a*b);
else if(op==’/')
printf(“Division of 2 nos is %d and %d in %d”,a,b,a/b);
else if(op==’%')
printf(“Reminder of 2 nos is %d and %d in %d”,a,b,a%b);
else
printf(“Invalid option”);
getch();
}
26th Program:
/*current bill*/
#include<stdio.h>
#include<conio.h>
main()
{
int cno,mtn,pmr,cmr,pu;
char cna[20];
float bmt,urt;
clrscr();
printf(“Enter customer no,name:”);
scanf(“%dn %s”,&cno,&cna);
printf(“enter meter no:”);
scanf(“%d”,&mtn);
printf(“enter previous units and current units:”);
scanf(“%dn%d”,&pmr,&cmr);
pu=cmr-pmr;
if(pu<=50)
{
urt=0.50;
bmt=urt*pu;
}
else if(pu<=100 && pu>50)
{
urt=1.25;
bmt=urt*pu;
}
else if(pu<200 && pu>100)
{
urt=1.75;
bmt=urt*pu;
}
else
{
urt=3.00;
bmt=urt*pu;
}
clrscr();
printf(“nCustomer no:%dn”,cno);
printf(“Customer Name:%sn”,cna);
printf(“Meter no:%dn”,mtn);
printf(“Previous meter reading no:%dn”,pmr);
printf(“Current meter reading no:%dn”,cmr);
printf(“present Units:%dn”,pu);
printf(“Unit Rate:%fn”,urt);
printf(“nBill Amount is:%f”,bmt);
getch();
}
27th Program:
/* write a program to check the given no is even or odd */
#include<stdio.h>
#include<conio.h>
void main()
{
int x;
clrscr();
printf(“Enter x value:”);
scanf(“%d”,&x);
if(x%2==0)
{
printf(“%d: is even no”);
}
else
{
printf(“%d: is odd no”);
}
getch();
}
28th Program:
/* write a program find out even or odd without using equal operator */
#include<stdio.h>
#include<conio.h>
void main()
{
int x;
clrscr();
printf(“Enter x value:”);
scanf(“%d”,&x);
if(x%2)
{
printf(“%d is odd no”,x);
}
else
{
printf(“%d is even no”,x);
}
getch();
}
29th Program:
/*find out students results using with if condition*/
#include<stdio.h>
#include<conio.h>
void main()
{
int sno,m1,m2,m3;
char sna[10];
float tot,avg;
clrscr();
printf(“Enter student no:”);
scanf(“%d”,&sno);
printf(“Enter student name:”);
scanf(“%s”,&sna);
printf(“Enter m1 marks:”);
scanf(“%d”,&m1);
printf(“Enter m2 marks:”);
scanf(“%d”,&m2);
printf(“Enter m3 marks:”);
scanf(“%d”,&m3);
tot=m1+m2+m3;
avg=tot/3;
if(m1>=35 && m2>=35 && m3>=35)
{
printf(“n passedn”);
if(avg>=75)
printf(“distenction”);
else if(avg>=60)
printf(“First class”);
else if(avg>=50)
printf(“Second class”);
else if(avg>=35)
printf(“Third class”);
}
else
{
printf(“n Failedn”);
printf(“no division”);
}
getch();
}
30th Program:
/*write a program given no is positive or negative */
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf(“Enter n value:”);
scanf(“%d”,&n);
if(n>0)
{
printf(“%d is positive no”,n);
}
else if(n<0)
{
printf(“%d is negative no”,n);
}
else
{
printf(“%d is zero”,n);
}
getch();
}
31st Program:
/*scan code*/
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
printf(“n press a key”);
ch=getch();
if(ch==0)
{
printf(“n Ascii code=%d”,ch);
ch=getch();
printf(“n scan code=%d”,ch);
}
else
printf(“n Ascii code=%d”,ch);
getch();
}
32nd Program:
/* program to check whether the given number has a perfect square or not */
#include<stdio.h>
#include<conio.h>
void main()
{
int x,t;
clrscr();
printf(“Enter a number:”);
scanf(“%d”,&x);
t=(sqrt(x));
if((t*t)==x)
printf(“%d is perfect square “,x);
else
printf(“%d is not a perfect square”,x);
getch();
}
33rd Program:
/* print given string is whether it is uppeer or lower case */
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char ch;
clrscr();
printf(“Enter any string:”);
ch=getchar();
if(ch>=65 && ch<=90)
printf(“%s Given string is Uppercase letter”);
else if(ch>=97 && ch<=122)
printf(“%s Given string is Lowercase letter”);
/*else
printf(“Given string is special symbol”);*/
getch();
}
While Programs:
34th Program:
/* write to print 1 to no using while loop */
#include<stdio.h>
#include<conio.h>
void main()
{
int i=1;
clrscr();
while(i<=10)
{
printf(“%dn”,i);
i++;
}
getch();
}
35th Program:
/* Arm strong no 153 it means sum of the cubes */
#include<stdio.h>
#include<conio.h>
void main()
{
int n,t,s=0,r;
clrscr();
printf(“Enter any no:”);
scanf(“%d”,&n);
t=n;
while(t>0)
{
r=t%10;
s=s+r*r*r;
t=t/10;
}
if(s==n)
{
printf(“%d is armstrong no”,n);
}
else
{
printf(“%d is not armstrong no”,n);
}
getch();
}
36th Program:
/*ascii no using with while loop */
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
i=0;
while(i<=255)
{
printf(“n%-6c %6d”,i,i);
i++;
if(i%10==0)
{
getch();
clrscr();
}
}
getch();
}
37th Program:
/* write a program to print factorial of given no */
#include<stdio.h>
#include<conio.h>
void main()
{
unsigned long p=1;
int i,n;
clrscr();
printf(“Enter number to find the factorial:”);
scanf(“%d”,&n);
i=1;
while(i<=n)
{
p=p*i;
printf(“%d *”,i);
i++;
}
printf(“bb=%lu”,p);
getch();
}
38th Program:
/* caliculating balance fee */
#include<stdio.h>
#include<conio.h>
void main()
{
char sname,cj,ch;
int sno,tf,fp,bf;
clrscr();
ch=’y';
while(ch==’y')
{
printf(” Enter Student no is:”);
scanf(“%d”,&sno);
printf(“Student name is:”);
scanf(“%s”,&sname);
printf(“Total fee is:”);
scanf(“%d”,&tf);
printf(“Fee paid:”);
scanf(“%d”,&fp);
bf=tf-fp;
printf(“Balance fee is:%d”,bf);
printf(“n do you want to continue:”);
scanf(“%s”,ch);
}
getch();
}
39th Program:
/* write a program print like this format
1 * * * *
* 1 * * *
* * 1 * *
* * * 1 *
* * * * 1
%c-10-n
32 -’ ‘(space)
48-57-0-9
65-90 – ‘A’- ‘Z’
97-122 – ‘a’ -’z’
*/
#include<stdio.h>
#include<conio.h>
void main()
{
int i=1,j;
clrscr();
while(i<=5)
{
j=1;
while(j<=5)
{
if(i==j)
{
printf(“%c”,’1′);
}
else
{
printf(“%c”,’*');
}
j++;
}
printf(“n”);
}
getch();
}
40th Program:
/* print like this format */
#include<stdio.h>
#include<conio.h.
void main()
{
int r,c;
clrscr();
r=1;
while(r<=5)
{
c=1;
while(c<=5)
{
if(r>=c)
printf(“%-3c”,’*');
else
printf(“%c”,32);
c++;
}
r++;
printf(“n”);
}
getch();
}
41st Program:
/* printf like this format isosceles right angel triangle
*
**
***
****
*****
******
******* */
#include<stdio.h>
#include<conio.h>
void main()
{
int r,c;
clrscr();
r=1;
while(r<=5)
{
c=1;
while(c<=2*r-1)
{
printf(“%-3c”,’*');
c++;
}
printf(“n”);
r++;
}
getch();
}
42nd Program:
/* 1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1 print like this format */
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
i=1;
while(i<=5)
{
j=1;
while(j<=5)
{
if(i==j) /*(i+j==6)*/
{
printf(“%dt”,1);
}
else
{
printf(“%dt”,0);
}
j++;
}
printf(“n”);
i++;
}
getch();
}
43rd Program:
/* 1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1 */
#include<stdio.h>
#include<conio.h>
void main()
{
int r,c;
clrscr();
r=1;
while(r<=5)
{
c=1;
while(c<=5-r)
{
printf(“%-3c”,32);
c++;
}
c=1;
while(c<=2*r-1)
{
if(r>=c)
printf(“%-3d”,c);
else
printf(“%-3d”,2*r-c);
c++;
}
r++;
printf(“n”);
}
getch();
}
44th Program:
/* * * * * * * * *
* * * * * *
* * * *
*
*/
#include<stdio.h>
#include<conio.h>
void main()
{
int r,c,n;
clrscr();
printf(“Enter no of rows:”);
scanf(“%d”,&n);
clrscr();
r=n;
while(r>=1)
{
c=1;
while(c<=n-r)
{
printf(“%-3c”,32);
c++;
}
c=1;
while(c<=2*r-1)
{
printf(“%-3c”,’*');
c++;
}
printf(“n”);
r–;
}
getch();
}
47th Program:
/* 1 * * * 1
* 1 * 1 *
* * 1 * *
* 1 * 1 *
1 * * * 1 print like this format */
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
i=1;
while(i<=5)
{
j=1;
while(j<=5)
{
if(i+j==6||i==j)
{
printf(“%-3c”, ‘1′);
}
else
{
printf(“%-3c”,’*');
}
j++;
}
printf(“n”);
i++;
}
getch();
}
48th Program:
/* 1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25 printf like this format */
#include<stdio.h>
#include<conio.h>
void main()
{
int i=1,r=1;
clrscr();
while(i<=25)
{
printf(“%dt”,i);
if(i%5==0)
{
printf(“n”);
}
i=i+1;
}
getch();
}
49th Program:
/* write a program to check given no is perfect no or not */
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i=1,sum=0;
clrscr();
printf(“Enter no:”);
scanf(“%d”,&n);
while(i<n)
{
if(n%i==0)
sum=i+sum;
i++;
}
if(sum==n)
printf(“%d is perfect no”,n);
else
printf(“%d is not perfect no”,n);
getch();
}
50th Program:
/* write a program to check given no is perfect no or not */
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i=1,sum=0;
clrscr();
printf(“Enter no:”);
scanf(“%d”,&n);
while(i<n)
{
if(n%i==0)
sum=i+sum;
i++;
}
if(sum==n)
printf(“%d is perfect no”,n);
else
printf(“%d is not perfect no”,n);
getch();
}
51st Program:
/* write a program to find the product of 1 to 10 nos */
#include<stdio.h>
#include<conio.h>
void main()
{
unsigned int p=1;
int i=1;
clrscr();
while(i<=10)
{
p=p*i;
i++;
}
printf(“nproduct of 1 to 10 is %lun”,p);
getch();
}
52nd Program:
/* write a program to find sum of given no in the format(1+2+3+4=10)*/
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i;
int sum=0;
clrscr();
printf(“Enter number:”);
scanf(“%d”,&n);
i=1;
while(i<=n)
{
sum=sum+n;
printf(“%d +”,i);
i++;
}
printf(“b b=%d”,sum);
getch();
}
53rd Program:
/* find out the sum of the squares 1 2 4 16 256*/
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n=1,f=1;
clrscr();
i=1;
while(i<=5)
{
printf(“%-5d”,f);
f=1;
j=1;
while(j<=n)
{
f=f*2;
j++;
}
n=n*2;
i++;
}
getch();
}
FOR Loop Programs:
54th Program:
/* 1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1 print this format using with for loop */
#include<stdio.h>
#include<conio.h>
void main()
{
int r,c;
clrscr();
for(r=1;r<=5;r++)
{
for(c=1;c<=5;c++)
{
if(r==c)
printf(“%-3d”,1);
else
printf(“%-3d”,0);
}
printf(“n”);
}
getch();
}
55th Program:
/* 1 2 3 4 5
2 1 2 3 4
3 2 1 2 3
4 3 2 1 2
5 4 3 2 1 print this format using with for loop */
#include<stdio.h>
#include<conio.h>
void main()
{
int r,c;
clrscr();
for(r=1;r<=5;r++)
{
for(c=1;c<=5;c++)
{
if(r>=c)
printf(“%-3d”,r-c+1);
else
printf(“%-3d”,c-r+1);
}
printf(“n”);
}
getch();
}
56th Program:
/* print isocessless triangle
*
**
***
****
***** */
#include<stdio.h>
#include<conio.h>
void main()
{
int r,c;
clrscr();
for(r=1;r<=5;r++)
{
for(c=1;c<=r;c++)
{
printf(“%-3c”,’*');
}
printf(“n”);
}
getch();
}
57th Program:
/* print horizontal line using with for loop */
#include<stdio.h>
#include<conio.h>
void main()
{
int c1,c2,r,i;
clrscr();
printf(“Enter Starting and ending coloumn:”);
scanf(“%d %d “,&c1,&c2);
printf(“Enter the row no:”);
scanf(“%d”,&r);
clrscr();
for(i=c1;i<=c2;i++)
{
gotoxy(i,r);
printf(“%c”,196);
}
getch();
}
58th Program:
/*table*/
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
for(i=1;i<=20;i++)
{
for(j=1;j<=20;j++)
{
printf(“%d x %d = %dn”,i,j,i*j);
}
printf(“n press any key to continue:n”);
getch();
}
getch();
}
59th Program:
/* print vertical line */
#include<stdio.h>
#include<conio.h>
void main()
{
int r1,r2,c,i;
clrscr();
printf(“Enter (r,r2,c):”);
scanf(“%d %d %d”,&r1,&r2,&c);
clrscr();
for(i=r1;i<=r2;i++)
{
gotoxy(c,i);
printf(“%c”,179);
}
getch();
}
60th Program:
/* ascii no using with for loop */
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
for(i=0;i<=255;i++)
{
printf(“n %-6c %6d”,i,i);
if(i%10==0)
{
getch();
clrscr();
}
}
getch();
}
SWITCH Programs:
61st Program:
/* write a program to print caliculator operations */
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
char op;
clrscr();
printf (“Enter the first no:”);
scanf(“%d”,&a);
printf(“Enter the second no:”);
scanf(“%d”,&b);
printf(“Enter the operator(+,-,*,/,%):”);
fflush(stdin);
scanf(“%c”,&op);
switch(ch)
case ‘+’:
printf(“sum of two numbers is %d and %d in %d”,a,b,a+b);
case ‘-’:
printf(“Subtraction of two numbers is %d and %d in %d,a,b,a-b);
case ‘*’:
printf(“Multiplication of two numbers is %d and %d in %d”,a,b,a*b);
case ‘/’:
printf(“Division of two numbers is %d and %d in %d”,a,b,a/b);
case ‘%’:
printf(“Remainder of two numeber is %d and %d in %d”,a,b,a%b);
default:printf(“Invalid option”);
}
getch();
}
62nd Program:
/* goto */
#include<stdio.h>
#include<conio.h>
void main()
{
int i=1;
clrscr();
meher:
printf(“%dt”,i);
i++;
if(i<=100)
goto meher;
getch();
}
63rd Program:
/* print menu design */
#include<stdio.h>
#include<conio.h>
void main()
{
int fno,sno,ch;
float res;
clrscr();
gotoxy(26,5);
printf(“*********************************n”);
gotoxy(26,6);
printf(“ 1.Addition. n”);
gotoxy(26,7);
printf(“ 2.Subtraction n”);
gotoxy(26,8);
printf(“ 3.Multiplication n”);
gotoxy(26,9);
printf(“ 4.Division n”);
gotoxy(26,10);
printf(“***********************************n”);
gotoxy(26,12);
printf(“Enter 1st no:”);
scanf(“%d”,&fno);
gotoxy(26,15);
printf(“Enter 2nd no:”);
scanf(“%d”,&sno);
gotoxy(26,18);
printf(“Enter choice:”);
scanf(“%d”,&ch);
switch(ch)
{
case 1:
{
res=fno+sno;
printf(“Addition value is:%7.2fn”,res);break;
}
case 2:
{
res=fno-sno;
printf(“Subtraction value is:%7.2fn”,res);break;
}
case 3:
{
res=fno*sno;
printf(“Multiplication value is:%7.2fn”,res);break;
}
case 4:
{
res=fno/sno;
printf(“Divsion value is:%7.2fn”,res);break;
}
default:printf(“wrong option:”);
}
getch();
}
64th Program:
/* print oval or not */
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
printf(“Enter choice:”);
scanf(“%s”,&ch);
switch(ch)
{
case ‘a’:
case ‘e’:
case ‘i’:
case ‘o’:
case ‘u’: printf(“oval”);break;
default :printf(“Consonent”);
}
getch();
}
65th Program:
/* print week days using with switch case */
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
printf(“printf Enter choice:”);
scanf(“%d”,&i);
switch(i)
{
case 0:printf(“Sunday”);break;
case 1:printf(“Monday”);break;
case 2:printf(“Tuesday”);break;
case 3:printf(“Wednesday”);break;
case 4:printf(“Thursday”);break;
case 5:printf(“Friday”);break;
case 6:printf(“Saturday”);break;
default:printf(“Wrong option”);
}
getch();
}