C++_Practical_Record question

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

PRACTICAL EXAM

RECORD QUESTIONS
C++
PROGRAM NO : 1
Write a program to calculate Simple Interest using formula.
I = p*n*r/100

CODE

#include<iostream.h>

#include<conio.h> OUT PUT

void main()

clrscr();

float p,n,r,i;

cout<<"enter the principle amount";

cin>>p;

cout<<"enter the number of years";

cin>>n;

cout<<"enter the rate of interest";

cin>>r;

i=p*n*r/100;

cout<<"\n simple interest:"<<i;

getch();

}
PROGRAM NO : 2
Write a c++ program to input student details [Roll
Number, Name, Aggregate marks of a student and also display
the Grade.] The grade is calculated as follow
Marks Grade
>90 A
75-89 B
60-75 C
50-60 D
40-50 E
<40 F

CODE

#include<iostream.h>

#include<conio.h>

void main()

{ OOUT PUT

clrscr();

char name[20];

int no,m;

cout<<"enter the roll number\t";

cin>>no;

cout<<"enter the name\t";

cin>>name;

cout<<"enter the mark";

cin>>m;

if(m>=90)

cout<<"\n\ngrade:A";

else

if(m>75 && m<90)


cout<<"\n\ngrade:B";

else

if(m>60 && m<75)

cout<<"\n\ngrade:C";

else

if(m>=40 && m<60)

cout<<"\n\ngrade:D";

else

cout<<"\n\ngrade:E";

getch();

}
PROGRAM NO : 3
Write a program to find Addition, Subtraction,
Multiplication, Division to two numbers entered by the use. The
menu options is following format.
I. Addition
II. Subtraction
III. Multiplication
IV. Division

CODE
OUT PUT
#include<iostream.h>

#include<conio.h>

void main()

clrscr();

int a,b,c;

cout<<"enter two numbers";

cin>>a>>b;

cout<<"\n1:addition";

cout<<"\n2:subtraction";

cout<<"\n3:multiplication";

cout<<"\n4:division";

cout<<"\n\n enter your choice";

cin>>c;

switch(c)
{

case 1:cout<<"\n addition result:"<<a+b;

break;

case 2:cout<<"\n subtraction result:"<<a-b;

break;

case 3:cout<<"\n multiplication result:"<<a*b;

break;

case 4:cout<<"\n division result:"<<a/b;

break;

default:

cout<<"\n invalid choice";

getch();

}
PROGRAM NO : 4
Write a program to Factorial of a given number.

CODE

#include<iostream.h>

#include<conio.h>

void main() OUT PUT

clrscr();

int n,a=1;

long int f=1;

cout<<"enter a number";

cin>>n;

while(a<=n)

f=f*a;

a++;

cout<<"\n factorial of "<<n<<"="<<f;

getch();

}
PROGRAM NO : 5
Write a program to display a number pattern.

1 2

1 2 3

1 2 3 4

1 2 3 4 5

CODE

#include<iostream.h>

#include<conio.h>

void main() OUT PUT

clrscr();

int a,b;

for(a=1;a<=5;a++)

for(b=1;b<=a;b++)

cout<<b<<" ";

cout<<"\n";

getch();

}
PROGRAM NO : 6
Write a program to print Leap year.

CODE

#include<iostream.h>

#include<conio.h>

void main()

{ OUT PUT

clrscr();

int a;

cout<<"enter the year";

cin>>a;

if(a%4==0)

cout<<"this year is leap year";

else

cout<<"this year is not a leap year";

getch();

}
PROGRAM NO : 7
Write a program to print prime number between 2 and 100.
CODE

#include<iostream.h>

#include<conio.h>

void main()

clrscr();

int N,i,j,isPrime,n;

cout<<"enter the value of N\n";

cin>>N;

for(i=2;i<=N;i++)

isPrime=0;

for(j=2;j<=i/2;j++)

if(i%j==0)

isPrime=1;

break;

if(isPrime==0 && N!=1)

cout<<"\t"<<i<<" ";

}
getch();

OUT PUT
PROGRAM NO : 8
Write a program for Pascal Triangle.
CODE

#include<iostream.h>

#include<conio.h>

void main()
OUT PUT
{

clrscr();

int rows;

cout<<"enter the number of rows:";

cin>>rows;

cout<<endl;

for(int i=0;i<=rows;i++)

int val=1;

for(int j=1;j<=rows-i;j++)

cout<<" ";

for(int k=0;k<=i;k++)

cout<<" "<<val;

val=val*(i-k)/(k+1);

cout<<endl<<endl;
}

cout<<endl;

getch();

}
PROGRAM NO : 9
Write a program for ARM STRONG.
CODE

#include<iostream.h>

#include<conio.h>

void main()
OUT PUT
{

clrscr();

int num,orig,rem,result=0;

cout<<"enter the three digit integer";

cin>>num;

orig=num;

while(orig!=0)

rem=orig%10;

result+=rem*rem*rem;

orig/=10;

if(result==num)

cout<<"is an armstrong number"<<num;

else

cout<<"is not an armstrong number"<<num;

getch();

}
PROGRAM NO : 10
Store ‘n’ name in to an array and search for a particular name.
CODE

#include<iostream.h>

#include<conio.h> OUT PUT

#include<string.h>

void main()

clrscr();

int n,j,i=0;

char name[20][20],s[20];

cout<<"enter how many names to be stored";

cin>>n;

for(i=0;i<n;i++)

cin>>name[i];

cout<<"enter a name to search\n";

cin>>s;

for(i=0;i<n;i++)

if(strcmp(name[i],s)==0)

n=1;

}
if(n==1)

cout<<"\n serched name presented at position"<<i;

else

cout<<"\n serched name not presented in array";

getch();

}
PROGRAM NO : 11
Write a program for Palindrome.

CODE
#include<iostream.h>

#include<conio.h>

#include<string.h> OUT PUT

void main()

clrscr();

char a[10],b[10],rev[20];

cout<<"\n enter the string\n";

cin>>a;

strcpy(b,a);

strrev(b);

cout<<"\n reverse of the string\n"<<a;

cout<<" \n"<<b<<" is";

if(strcmpi(a,b)==0)

cout<<"\n palindrome\n";

else

cout<<"\n not palindrome\n";

getch();

}
PROGRAM NO : 12
Write a program for Fibonacci.

CODE
#include<iostream.h>

#include<conio.h>

void main()

{
OUT PUT
clrscr();

int a=0,b=1,c=2,i=1;

cout<<"enter the range";

cin>>i;

cout<<a<<" "<<b<<" ";

while(c<i-1)

c=a+b;

a=b;

b=c;

cout<<c<<" ";

i=i+1;

getch();

}
PROGRAM NO : 13
Write a program using the function overloading to find area of
Rectangle, area of Square and area of circle.

CODE
#include<iostream.h>

#include<conio.h> OUT PUT

void main()

clrscr();

int r;

cout<<"enter radius of a circle";

cin>>r;

cout<<"\n area of circle


is\n"<<(3.14*r*r);

int l,b;

cout<<"\n enter length and breadth of a rectangle\n";

cin>>l>>b;

cout<<"\n enter of rectangle is\n"<<(l*b);

int a;

cout<<"\n enter a side\n";

cin>>a;

cout<<"\n area of square\n"<<(a*a*a*a);

getch();

You might also like