Page |1
Q1. WAP to print number is even or odd.
Program:-
#include<iostream.h>
#include<stdio.h>
main()
int number;
printf(“enter any number”);
scanf(“%d”,& number);
if( number/2==0)
Printf(“number is even”);
else
printf(“number is odd”);
Output:-
Enter any no. 8
This no. is even
Algorithm:-
1.input no.
2.if no/2==0 output even else odd
Page |2
Flow chart of odd even number.
Start
Input number
If
number/2 Number is even
Number is odd
Stop
Page |3
Q 2. WAP to perform arithmetic operation on two number ?
Program:-
#include<iostream.h>
#include<stdio.h>
Main ()
Int a, b,c,d,e,f,g;
Printf(“enter two number/n”);
Scanf(“%d%d”,&a,&b);
c=a+b;
d=a-b;
e=a*b;
f=a/b;
g=a%b;
Printf(“Addition:%d/n”,c);
Printf(“Substraction:%d/n”,d);
Printf(“Multiplication:%d/n”,e);
Printf(“Division:%d/n”,f);
Printf(“Module division:%d/n”,g);
Output:-
Enter first no a= 4;
Enter second no b=2;
Add.c=6
Sub.d=2
Multi.e=8
Div.f=2
Modiv.g=0
Page |4
Flow chart of arithmetic operation on two number
start
Input two no a,b
c=a+b
d=a-b
e=a*b
f=a/b
g=a%b
Ptint a,b,c,d,e,f,g
stop
Page |5
Q3. WAP to calculate simple interest ?
Program:-
#include<iostream.h>
# include<stdio.h>
main()
Int p,r,t,si;
printf(“enter p,r,t”);
scanf(“%d%d%d”,&p&r&t);
si== p*r*t/100;
printf(“si”);
getch();
Output:-
Enter p=10000
r=3%
t= 1 year
print si=30,000
Algorithm:-
1. input p,r,t
2. process si=(p*r*t)/100
3. output si
Page |6
Flow chart of simple interest.
start
input p,r,t
si= p*r*t/100
print SI
stop
Page |7
Q4. WAP to demonstrate the concept of Break?
Program:-
#include(iostream.h)
#include(stdio.h)
main()
int i;
clrscr()
for(i=1;i<=10;i++)
Printf(“%d”,i);
If(i==5)
break;
getch()
Output:-
1
Algorithm:-
1.Check till i<=5
2.Output i
Page |8
Flow chart of concept of Break
start
input i
For i=1;<=10;i++
If==5 Break
Go to for
stop
Page |9
Q5. WAP to demonstrate the concept of continue?
#include<iostream.h>
#include<stdio.h>
main()
int i
clrscr();
for(i=1;i<=10;i++)
Printf(“%d”,i);
If(i>=5&&i<=8)
continue
getch();
Output:-
1
10
Algorithm:-
1.Check till i<=10
2.Output i
P a g e | 10
Flow chart of concept of continue
start
input i
For i=1;<=10;i++
If==5 continue
Go to for
stop
P a g e | 11
Q6. WAP to find wether a person can vote or not?
Program:-
#include<iostream.h>
#include<stdio.h>
main()
int age;
printf(“enter the age/n”);
scanf(“%d”,&age);
age>=18?person can vote:person can’t vote;
Output:
Enter the age =19
Person can vote
Algorithm:-
1. input age
2. if age>=18 person can vote else can’t vote
3. output age
P a g e | 12
Flow chart of a person can vote or not vote
START
Input age
If age >=18
Person can vote
Person can’t vote
stop
P a g e | 13
Q7.WAP to find the grade of a student
using if-else ladder?
Program:-
#include<iostream.h>
#include<stdio.h>
Printf(“Enter your percent /n”);
Scanf(“%d”,&per);
if(per>=80)
Printf(“Merit”);
else if(per>=60)
Printf(“First”);
else if(per>=45)
Printf(“Second”);
else if(per>=33)
Printf(“Third”);
else
printf(“Fail”)
}
P a g e | 14
}
P a g e | 15
Flow chart of grade of a student using if-else ladder.
start
Input per
If per>=80
merit
Per>=60 first
Per>=60
Per>=45 second
Per>=33 third
fail
stop
P a g e | 16
Q8.WAP to find size of integer, float,char and double?
Program:-
#include<iostream.h>
#include<stdio.h>
main()
Int a,b,c,d;
Clrscr();
Printf(“size of integer”,size of (a) );
Printf(“size of float”,size of (b));
Printf(“size of char”size of(c));
Printf(“size of double”size of(d));
getch( );
Output:-
Size of integer
Size of float
Size of char
Size of double
P a g e | 17
Flow chart of find a size of integer, float,char and double.
start
Input
int,float,char,double
size of int
Size of float
Size of char
Size of double
Print=size of( int,char,float,double)
stop
P a g e | 18
Q9. WAP to print whether a given year is leap or not?
Program:-
#include<iostream.h>
#include<stdio.h>
main()
Int year;
Printf(“Enter any year:/n”);
Scanf(“%d”,& year);
Year/4==0?this is leap year:this is not leap year;
Output:-
Enter any year=2016
This is leap year.
Algorithm:-
1. input year
2. if year/4==0 leap year else leap year
3. output year
P a g e | 19
Flow chart of leap year or not
Start
Input year
If year/4==0 L Leap year
Not leap year
Stop
P a g e | 20
Q10. WAP to find greatest between three numbers?
Program:-
#include<iostream.h>
#include<stdio.h>
Main()
Int a,b,c;
Printf(“Enter three no:/n”);
Scanf(“%d%d%d”,&&a,&&b,&&c);
If(a>b&&a>c)
Printf(“a is greater”);
If (b>a&&b>c)
Printf(“b is greater”);
Else(“c is greater”);
Output:-
Enter three number a=1,b=2,c=3
C is greater
P a g e | 21
Flow chart of find greater number
Start
Input three number a,b,c
If
a>b&&a>c A is greater
If
b>c&&b>a B is greater
C is greater
Stop
P a g e | 22
P a g e | 23
Q10. WAP to find middles between three numbers?
Program:-
#include<iostream.h>
#include<stdio.h>
Main()
Int a,b,c;
Printf(“Enter three no:/n”);
Scanf(“%d%d%d”,&&a,&&b,&&c);
If(a>b&&a<c)
Printf(“a is middle”);
If (b>a&&b<c)
Printf(“b is middle”);
Else(“c is middle”);
Output:-
Enter three no (a=1,b=2,c=3)
B is middle
P a g e | 24
Flow chart of find middle number
Start
Input three number a,b,c
If
a>b&&a<c A is middle
If
b>a&&b<c B is middle
C is middle
Stop
P a g e | 25
Q12.WAP to print smallest number using conditional operator?
Program:-
#include<iostream.h>
#include<stdio.h>
Main ()
Int a,b;
Printf(“enter two numbers”);
Scanf(“%d%d”,&a&b);
b>a?a is smaller:b is smaller;
getch();
Output:-
Enter two number a=1,b=2
a is smaller
Algorithm:-
1. input a,b
2. conditional process
3. output a is smaller
P a g e | 26
Flow chart of smaller number
Start
Input two numbers
if Yes
A is smaller
b>a
No
B is smaller
Stop
P a g e | 27
Q13. WAP to calculate average marks of 30 student using array?
Program:-
#include<iostream.h>
#include<stdio.h>
Main ()
Int avg,sum=0;
Int i;
Int marks[30];//array declaration
For (“i=0;I<=29;i++)
Printf(“\n enter marks”);
Scanf(“%d”,& marks [ i ]);// store data into array
For (i=0;i<=29;i++)
Sum=sum+marks[i];
Avg=sum/30;
Printf(“\n average marks=%d”avg);
}
P a g e | 28
Output:-
Enter marks [1,2,3………………,28,29,30]
Total no. 465
Avg no. 15.5
Algorithm:-
1.input marks
2.For((i=0;i<=29;i++)
3.output total
4.output avg
P a g e | 29
Flowchart of calculate total and average marks of 30 students using
array variable
start
Input i, avg sum=0
For(i=1,i<=29,i++)
Sum=sum+0
Avg=sum/30
Print sum,avg
stop
P a g e | 30
Q14. WAP to reverse String?
Program:-
#include<iostream.h>
#include<stdio.h>
Main()
Int x,y,rev=0;
Clrscr();
While(xǃ0)
Printf(“enter any number”);
Scanf(“%d”,&X);
X=Y;
X=X/10;
Y=Y%10;
rev=rev+y;
Printf(“revers number is %d”,rev);
Output:-
enter any number 123
revers number 321
Algorithm:- 1.input i, string
2. output reserve string
P a g e | 31
Flow chart of reverse String
start
input x,y,rev=0
While(x!0)
X=Y;
X=X/10;
Y=Y%10;
rev=rev+y;
Print rev
stop
P a g e | 32
Q15.WAP to calculate table of a number given by user while loop.
Program:-
#include<iostream.h>
#include<stdio.h>
Main()
Int a,b,i;
i=1;
clrscr();
printf(“enter no. to calculate table”);
scanf(“%d”,&a);
while(i<=10)
b=a*I;
Printf(“\n%d”,b);
i++;
getch();
Output:- enter no. to calculate table 2
8
P a g e | 33
10
12
14
16
18
20
Algorithm:-
1. Input a,b,i
2. Check i<=10
3. Calculate b=a*i
4. Output b
P a g e | 34
Flow chart of calculate table of a number given by user while loop.
Start
input i
I<=10
Go to for
Break
stop
P a g e | 35
Q16.WAP to display the following pattern?
**
***
****
Program:-
#include<iostream.h>
#include<stdio.h>
Void main()
int I, j;
clrscr();
for(i=1;i<=5;i++)
for(j=1;j<=i;j++)
Printf(“*”);
Printf(“\n”);
getch();
}
P a g e | 36
Output:-
**
***
****
*****
Algorithm:-
1. Input i,j
2. Check for i<=5 and j<=i
P a g e | 37
Flow chart of display the following pattern?
start
Input I,j
For(i=1,j<=i;i++)
For(j=1;j<=i;j++)
Print *
Print \n
Stop
P a g e | 38
Q17.WAP to display use of Pointer?
Program:-
#include<iostream.h>
#include<stdio.h>
Void main()
Char name[10],*ptr;
Clrscr();
printf(“enter your name”);
scanf(“%s”,name);
ptr=name;
printf(“\n name=%s’’,ptr);
getch();
Output:-
Enter your name=xyz
Name=xyz
Algorithm:-
1. Input name,*ptr
2. Output name
P a g e | 39
Flow chart of display use of Pointer?
start
input name
ptr=name
print ptr
stop
P a g e | 40
Q.18 WAP to check that the given number is prime or not ?
Program:-
#include<stdio.h>
#include<conio.h>
Void main()
Int a,i;
Clrscr();
Printf(“enter a no.”);
Scanf(“%d”,&a);
if(a==1)
printf(“%d is prime no.”);
for(i=2;i<=a;i++)
if(a%i==0)
Printf(“%d is not a prime no.”);
Break;
if(i==a)
printf(“%d is prime no.”);
getch();
}
P a g e | 41
Output:-
Enter a no.=3
3 is a prime no.
Algorithm:-
1. Input a
2. Check a==1 then output prime no.
3. Check for i<=a and a%i==0 then output not a prime no.
4. Check i==a then output prime no.
P a g e | 42
Flow chart check that the given number is prime or not ?
Start
Input a,i
If a==1
Prime no.
for(i=2;i<=a;i++)
if(a%i==0) Not Prime no.
If a==1
Break
Prime no.
stop
P a g e | 43
Q19. WAP to creat a structure of mark sheet of student that
have data members as roll no., name,marks of 3 subjects
and calculate total and percentage from it.
Program:-
#include<stdio.h>
#include<conio.h>
Struct stud
Int roll no.,fm,cm,om;
Float per,tot;
Char name[10];
Void main()
Struct stud s;
Clrscr();
Printf(“enter roll no.=”);
Scanf(“%d”&s.roll no.);
fflush(stdin);
printf(“enter name”);
scanf(“%s”,&s.name);
printf(“enter marks for funda,c,office=”);
scanf(“%d%d%d”,&s.fm,&s.cm,&s.om);
s.tot=s.fm+s.cm+s.om;
s.pre=(s.tot/300)*100;
printf(“****************”);
printf(“\n\t\t\t markshee\n”);
printf(“*****************”);
P a g e | 44
printf(“\n roll no.=%d”,s.roll no);
printf (“\n name=%s”,s. name);
printf(“\n marks”);
printf(“\n fundamental\t\tc\t\t office”);
printf(“\n%d\t\t%d\t\t%d”,s.fm,s.cm,s.om);
printf(“\n total=%f”,s.tot”);
printf(“\n percent=%f”,s.per);
getch();
Output:-
Enter roll no.=50221
Enter name= virat
Enter marks for funda ,c,office=65,76,78
………………………………………………………………………………………………………
Mark sheet
…………………………………………………………………………………………………......
Roll no.=50221
Name= virat
Marks=
Fundamental c office
65 76 78
Total=219.00
Present=73.00%
Algorithm:-
1. Input roll no.,name,fm,cm,om
2. Calculate total & percent
3. Output roll no.,name,fm,cm,om, total & percent in mark sheet.
P a g e | 45
Flow chart of a structure of mark sheet of student that have
data members as roll no., name,marks of 3 subjects and
calculate total and percentage from it.
Start
Input roll no.name,fm,cm,om
s.tot=s.fm+s.cm+s.om
S.per=(s.tot/300)*100
Print roll no., name fm,cm,om,tot.per
stop
P a g e | 46
Q20. WAP to generate Fibonacci series?
Program:-
#include<stdio.h>
#include<conio.h>
Void main()
Int a,b,c,I,n;
Clrscr();
a=0;
b=1;
printf(“enter trams”);
scanf(“%d”,&n);
scanf(“%d%d”,a,b);
for(i=1;i<=n-2;i==)
c =a+b;
a=b;
b=c;
printf(“c”);
getch();
Output:- enter terms 5
01123
P a g e | 47
Algorithm:-
1. Input n
2. Output a,b
3. Check till i<n-2then c=a+b
4. a=b,b=c
5. output c
P a g e | 48
Flow chart of display the following pattern?
start
Input n
i=1;i<=n-2;i++
C=a+b
a=b,b=c
Print c
Stop
P a g e | 49
Q21. Wap to calculate total and average using array variable?
Program:-
#include<iostream.h>
#include<stdio.h>
Main()
Int avg, sum=0;
Int I;
Int marks [5];
For(i=0;i<=4;i++)
Printf(“\n enter marks”);
Scanf(“%d”,&marks[i]);
For(i=0;i<=4;i++)
Sum=sum+marks[i];
Avg=sum/5;
Print f(“\n average marks=%d”,avg);
}
P a g e | 50
Output:-
Enter no. 33,50,60,12,10
Total no. 165
Avg no. 33
Algorithm:-
1.input marks
2.For((i=0;i<=4;i++)
3.output total
4.output avg
P a g e | 51
Flowchart of calculate total and average using array variable
start
Input i, avg sum=0
For(i=1,i<=4,i++)
Sum=sum+0
Avg=sum/5
Print sum,avg
stop
P a g e | 52
Q.22WAP to demonstrate the concept of global variable?
Program:-
#include<iostream.h>
#include<stdio.h>
int x=100;
main()
Clrscr();
printf(“Value of x=”,X/n);
printf(“Value of ::”,X);
getch();
}
P a g e | 53
Q.23. WAP to find whether the inputted character is vowel or
consonant using switch statement?
Program:-
# include<iostream.h>
# include<stdio.h>
Main()
char a,e,I,o,u;
printf (“enter any character”);
scanf (“%char”,);
switch(a)
Case a:
Printf (“vowel”);
Break;
Case e:
Printf(“vowel”);
Break ;
Case I:
Printf (“vowel”);
Break ;
P a g e | 54
Case o:
Printf(“vowel”);
Break ;
Case u:
Printf (“vowel”);
Break ;
Default :
Printf (“consonant”);
Getch ();
Output:-
P a g e | 55
Flow chart of find whether the inputted character is vowel or
consonant using switch statement?
Start
Char a,e,I,o,u
Case a
Vowel
Case e
Vowel
Case i
Vowel
Case o
Vowel
Case u
Vowel
Default
Stop
P a g e | 56
Q24.WAP to convert given string lower case to upper case?
Program:-
# include<iostream.h>
# include<stdio.h>
Void main()
Char na[3];
Int a;
Clrscr();
Printf(“enter two character in small letter”);
Scanf(“%s”,&na);
a=na[0];
na[0]=a-32;
a=na[1];
na[1]=a-32;
printf(“in capital latter:\n”,na);
getch();
Output:-
enter two character in lower case= ab
upper case= AB
Algorithm:-
1. Input a,name
2.a=na[0]; na[0]=a-32;a=na[1]; na[1]=a-32;
3.output name lower case to upper case=AB
P a g e | 57
Q25.WAP to display variable address?
Program:-
# include<iostream.h>
# include<stdio.h>
Void main()
Int x;
Int*p;
Clrscr();
Printf(“enter any number”);
Scanf(“%d”,&x);
P=&x;
Printf(“address of x:\n”);
Printf(“value of x:\n”);
getch();
Output:-
Enter any number 12
Address of x
Value of x
P a g e | 58
Q26.WAP to swap two number given by user using call by reference?
Program:-
# include<iostream.h>
# include<stdio.h>
Void change (int&x,int&y);
Void main()
Int a=10,b=20;
Clrscr();
Printf(“before change function call”/n);
Printf(“%d%d”,a “and”b);
Change(a b)
getch();
Void change (int&x,int&y);
X=100;
Y=200;
Printf(“ in function change/n”);
Printf(“%d%d”,a “and” b);
a=x+y;
b=x-y;
printf(“value of a:\n” a);
printf(“value of b:\n” b);
}
P a g e | 59
Output:-
before change function call a and b =10,20
after change a=20, b=10
Algorithm:-
1. Input a,b
2. a=x+y
b=x-y
3. print a,b
P a g e | 60
Flowchart of swap two number given by user using call by reference
start
Input a, b
a=x+y
b=x-y
Print a,b
stop
P a g e | 61
Q27.WAP to swap two numbers without using third variable?
Program:-
# include<iostream.h>
# include<stdio.h>
Void change (int&a,int&b);
Void main()
Int a=10,b=20;
Clrscr();
a=a+b;
b=a-b;
printf(“value of a:\n” a);
printf(“value of b:\n” b);
Output:-
Enter a&b =10&20
a=20,b=10
Algorithm:-
1. Input a,b
2. a=a+b
b=a-b
3. print a,b
P a g e | 62
Flowchart of swap two number given by user using third variable
start
Input a, b
a=a+b
b=a-b
Print a,b
stop
P a g e | 63
Q28. WAP to find whether a person got driving license or not.
Program:-
#include<iostream.h>
# include <stdio.h>
main( )
{
Int age;
Printf (“enter the age: \n”);
Scanf (“%d”, & age );
age>=18? Person can get driving license: Person can’t get driving license
}
Output:-
Enter the age =20
Person can get driving license
Algorithm:-
1.input age
2.age>=18
3. Person can get driving license else Person can’t get driving license
P a g e | 64
Flowchart of person can got driving license or can’t
START
Input age
If age >=18
Person can get
driving license
Person can’t get
driving license
stop
P a g e | 65
Q29.WAP to display the following pattern?
* *
* * *
* * * *
* * * * *
Program:-
#include<iostream.h>
#include<stdio.h>
Void main()
int i, j, k;
char c;
clrscr();
printf(“enter character”);
scanf(“%c”,&c);
for(i=j;j<=5;i++)
for(j=5;j<=i;j--)
Printf(“ ”);
for(k=j;k<=I;k++)
P a g e | 66
Printf(“%c,c”);
print(“\n”);
getch();
Output:-
Enter character *
* *
* * *
* * * *
* * * * *
Algorithm:-
1. Input i,j,k,c
2. Check for i<=5 and j<=i
3.output pattern
P a g e | 67
Flow chart of display the following pattern?
start
Input c
for(i=j;j<=5;i++)
for(j=5;j<=i;j--) Print with space
for(k=j;k<=I;k++) Print c
Print \n
Stop
P a g e | 68