Professional Documents
Culture Documents
Your choice: 1
Your choice: 2
Number is odd
//Q.1.
// Palindrome or not
// even or odd
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
cin>>num;
cin>>choice;
switch(choice)
a=num/100;
b=num%10;
if(a==b)
{
cout<<"\n The number is palindrome";
else
break;
case 2: if(num%2==0)
else
break;
getch();
}
Enter a number: 153
1. Check if no is prime
Number is armstrong
Enter a number: 8
1. Check if no is prime
#include<iostream.h>
#include<conio.h>
#include<process.h>
void main()
{
clrscr();
int num,choice;
cout<<"\n Enter a number:";
cin>>num;
cout<<"\n Choose a program to perform";
cout<<"\n 1.Check if no is prime";
cout<<"\n 2.Check if no is armstrong or not";
cout<<"\n Enter your choice:";
cin>>choice;
switch(choice)
{
case 1: int i;
for(i=2;i<=num/2;i++)
{
if(num%i==0)
{
cout<<"\n Number is not prime";
exit(0);
}
}
cout<<"\n Number is prime";
break;
case 2: inta,b,c,z;
a=num/100;
b=(num%100)/10;
c=num%10;
z=(a*a*a)+(b*b*b)+(c*c*c);
if(z==num)
{
cout<<"\n Number is armstrong";
}
else
{
cout<<"\n Number is not armstrong";
}
break;
}
getch();
}
Enter a year (in 4 digits): 2500
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
int year;
cin>>year;
if(year%4==0)
if (year%400==0)
else
getch();
}
How many elements(>5)?: 9
Fibonacci series: 0 1 1 2 3 5 8 13 21
//Q.4.
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
int a=0,b=1,c,n,i;
cin>>n;
cout<<a<<" "<<b;
for(i=2;i<n;i++)
c=a+b;
cout<<" "<<c;
a=b;
b=c;
getch();
}
A
A B
A B C
A B C D
A B C D E
//Q.5.
// A
// AB
// ABC
// ABCD
// ABCDE
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
charch='A';
int i, num=ch,j;
for(i=1;i<6;i++)
for(j=0;j<i;j++)
cout<<(char)(ch+j)<<"\t";
cout<<endl<<endl;
getch();
Enter a 3X3 matrix:
123
456
789
125
467
892
MATRIX MENU:
1. ADDITION OF MATRICES
2. SUBSTRACTION OF MATRICES
3. MULTIPLICATION OF MATRICES
4. EXIT
SUM OF MATRIX IS :
248
8 11 13
15 17 11
//Q.6.
// 1. ADDITION OF MATRICES
// 2. SUBSTRACTION OF MATRICES
// 3. MULTIPLICATION OF MATRICES
#include<iostream.h>
#include<conio.h>
#include<process.h>
void main()
clrscr();
int a[3][3],b[3][3],c[3][3],i,j,k,choice;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
cin>>a[i][j];
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
cin>>b[i][j];
clrscr();
for(i=0;i<3;i++)
cout<<"\n \t ";
for(j=0;j<3;j++)
cout<<a[i][j]<<" ";
cout<<endl;
for(i=0;i<3;i++)
cout<<" \n \t ";
for(j=0;j<3;j++)
cout<<b[i][j]<<" ";
cout<<endl;
cout<<" \n \t 4. EXIT";
cin>>choice;
switch(choice)
case 1:
for(i=0;i<3;i++)
for(j=0;j<3;j++)
c[i][j]=a[i][j]+b[i][j];
for(i=0;i<3;i++)
cout<<" \n \t ";
for(j=0;j<3;j++)
cout<<c[i][j]<<" ";
cout<<endl;
break;
case 2:
for(i=0;i<3;i++)
for(j=0;j<3;j++)
c[i][j]=a[i][j]-b[i][j];
for(i=0;i<3;i++)
cout<<" \n \t";
for(j=0;j<3;j++)
cout<<c[i][j]<<" ";
cout<<endl;
break;
case 3:
for(i=0;i<3;i++)
for(j=0;j<3;j++)
c[i][j]=0;
for(k=0;k<3;k++)
{
c[i][j]=c[i][j]+(a[i][k]*b[k][j]);
for(i=0;i<3;i++)
cout<<" \n \t ";
for(j=0;j<3;j++)
cout<<c[i][j]<<" ";
cout<<endl;
break;
case 4: exit(0);
getch();
}
ENTER MATRIX OF 25 ELEMENTS:
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
ENTERED MATRIX IS:
12345
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25
CHOICES ARE:
4.EXIT
ENTERED CHOICE IS : 1
1 2 3 4 5
7 8 9 10
13 14 15
19 20
25
//Q.7.
//TO WRITE A MENU DRIVEN PROGRAM TO PERFORM FOLLOWING FUNCTION ON SINGLE MATRIX
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
int a[3][3],b[3][3],i,j,choice;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
cin>>a[i][j];
cin>>choice;
cout<<"\n\n\tYour choice is: "<<choice;
switch(choice)
for(i=0;i<3;i++)
cout<<"\t";
for(j=0;j<3;j++)
if(i<=j)
cout<<a[i][j]<<" ";
else
cout<<" ";
cout<<endl;
break;
for(i=0;i<3;i++)
cout<<"\t";
for(j=0;j<3;j++)
{
if(i>=j)
cout<<a[i][j]<<" ";
else
cout<<" ";
cout<<endl;
break;
for(i=0;i<3;i++)
cout<<"\t";
for(j=0;j<3;j++)
b[i][j]=a[j][i];
cout<<b[i][j]<<" ";
cout<<endl;
break;
case 4: break;
getch();
}
ENTER 9 ELEMENTS:
9
ENTERED 9 ELEMENTS ARE:
123
456
789
CHOICES ARE:
1. MAXIMUM ELEMENT
2. MINIMUM ELEMENT
3. AVERAGE OF ELEMENTS
4. EXIT
CHOICE ENTERED IS :3
AVERAGE OF ELEMENTS IS :5
//Q.8.
//Maximum element
//Minimum element
//Average element
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
inti,j,ch;
cout<<"Enter a matrix:";
for(j=0;j<3;j++)
cin>>a[i][j];
cin>>ch;
switch(ch)
{
case 1: max=a[0][0];
for(j=0;j<3;j++)
if(a[i][j]>max)
max=a[i][j];
cout<<"\nMaximum Element="<<max;
break;
case 2: min=a[0][0];
for(i=0;i<3;i++)
for(j=0;j<3;j++)
if(a[i][j]<min)
min=a[i][j];
cout<<"\nMinimum Element="<<min;
break;
for(j=0;j<3;j++)
sum=sum + a[i][j];
av=(sum/(i*j));
cout<<"\nAverage Of Elements="<<av;
break;
getch();
}
ENTER STRING: New Delhi
String Menu
1.Count Vowels
2.Count Consonants
3.Count Digits
String Menu
1.Count Vowels
2.Count Consonants
3.Count Digits
String Menu
1.Count Vowels
2.Count Consonants
3.Count Digits
String Menu
1.Count Vowels
2.Count Consonants
3.Count Digits
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
void main()
clrscr();
charstr[20];
inti,vow=0,cons=0,dig=0,spec=0,ch;
cin.getline(str,20);
cout<<"\nString Menu";
cout<<"\n1.Count Vowels";
cout<<"\n2.Count Consonants";
cout<<"\n3.Count Digits";
cin>>ch;
switch(ch)
{
case 1: for(i=0; str[i]!='\0'; i++)
str[i]=tolower(str[i]);
if((str[i]=='a')||(str[i]=='e')||(str[i]=='i')||(str[i]=='o')||(str[i]=='u'))
vow++;
break;
str[i]=tolower(str[i]);
if((str[i]>='a'&&str[i]<='z')&&((str[i]='a')||(str[i]='e')||(str[i]='i')||(str[i]='o')||(str[i]='u')))
{
else
cons++;
break;
str[i]=tolower(str[i]);
if(str[i]>='0'&&str[i]<='9')
{
dig++;
break;
case 4: for(i=0;str[i]!='\0';i++)
str[i]=tolower(str[i]);
if(((str[i]>='a')&&(str[i]<='z'))||((str[i]>='0')&&(str[i]<='9')))
else
spec++;
break;
getch();
}
Enter a string: NEW DELHI
String Menu:
1.Uppercase to Lowercase
2.Lowercase to Uppercase
3.Reverse a string
String Menu:
1.Uppercase to Lowercase
2.Lowercase to Uppercase
3.Reverse a string
String Menu:
1.Uppercase to Lowercase
2.Lowercase to Uppercase
3.Reverse a string
// 1.UPPERCASE TO LOWERCASE
// 2.LOWERCASE TO UPPERCASE
// 3.REVERSE A STRING
// 4.EXIT
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
void main()
clrscr();
inti,j,choice;
charstr[15];
cout<<"\nEnter a string:";
cin.getline(str,15);
cout<<"\nString Menu:";
cout<<"\n1.Uppercase to Lowercase";
cout<<"\n2.Lowercase to Uppercase";
cout<<"\n3.Reverse a string";
cin>>choice;
switch(choice)
case 1:for(i=0;str[i]!='\0';i++)
str[i]=tolower(str[i]);
for(i=0;str[i]!='\0';i++)
{
cout<<str[i];
break;
case 2:for(i=0;str[i]!='\0';i++)
str[i]=toupper(str[i]);
for(i=0;str[i]!='\0';i++)
cout<<str[i];
break;
case 3:for(i=0;str[i]!='\0';i++)
{
}
for(j=i;j>=0;j--)
cout<<str[j];
break;
default:cout<<"\nWrong Choice!!!";
getch();
}
ENTER THREE NAMES :
GOPI
KRISHH
SALMAN
HIMADRI
AKHI
SANJAY
GOPI
KRISHH
SALMAN
HIMADRI
AKHI
SANJAY
GOPI
KRISHH
SALMAN
HIMADRI
AKHI
SANJAY
//Q.11.
// Program to concatenate two strings into third array
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char a[10],b[10],c[20];
inti,j,k=0;
cout<<"\nEnter two strings:";
cin.getline(a,10);
cin.getline(b,10);
for(i=0;a[i]!='\0';i++)
{
c[i]=a[i];
}
for(k=0;b[k]!='\0';k++)
{
c[k+i]=b[k];
}
cout<<"\nConcatenated array is: ";
for(k=0;c[k]!='\0';k++)
{
cout<<c[k];
}
getch();
}
ENTER THE NUMBER:7
FACTORIAL=5040
//.Q.12
//Program to find factorial of a number using function recursion
#include<iostream.h>
#include<conio.h>
longint factorial(long int n);
void main()
{
clrscr();
intnum,r;
cout<<"Enter a number:";
cin>>num;
r=factorial(num);
cout<<"Factorial:"<<r;
getch();
}
52
Enter an operator:+
Enter an operator:-
Difference is:31
12
Enter an operator:*
56
Enter an operator:/
Quotient is:1
Enter an operator:%
Remainder is:62
//Q.13
//To write a C++ program that invokes a CALC FUNCTION()
// which intakes two numbers and an
arithematic operator
// and prints the corresponding result
#include<iostream.h>
#include<conio.h>
voidcalc(int x, int y);
void main()
{
clrscr();
int a, b;
cout<<"Enter two numbers:";
cin>>a>>b;
calc(a,b);
}
voidcalc(int x, int y)
{
char op;
cout<<"Enter an operator:";
cin>>op;
switch(op)
{
case '+': cout<<"Sum is:"<<x+y;
break;
case'-' : cout<<"Difference is:"<<x-y;
break;
case '*': cout<<"Product is:"<<x*y;
break;
case '/': cout<<"Quotient is:"<<x/y;
break;
case '%': cout<<"Remainder is:"<<x%y;
break;
default :cout<<"Wrong choice";
break;
}
getch();
}
STUDENT RECORD
ENTER GRADE :B
ENTER GRADE :C
ENTER GRADE :D
MERIT ORDER :
ROLL NO :18
NAME :RAM
MARKS IN MATHS :50
MARKS IN SCIENCE :82
TOTAL MARKS :132
GRADE :C
ROLL NO :7
NAME :RAGHAV
MARKS IN MATHS :60
MARKS IN SCIENCE :70
TOTAL MARKS :130
GRADE :B
ROLL NO :25
NAME :SALIL
MARKS IN MATHS :69
MARKS IN SCIENCE :30
TOTAL MARKS :99
GRADE :D
//Q.14.
//To write a C++ program to maintain information ROLLNO,
// MARKS IN TWO SUBJECTS and GRADE OF A
STUDENT and
// display them merit orderwise using
structure
#include<iostream.h>
#include<conio.h>
structabc
{
introllno;
char name[20];
intmaths;
int science;
int total;
};
void main()
{
clrscr();
abc ob1[3],temp[4];
int i;
for(i=0;i<3;i++)
{
cout<<"Enter rollno:"<<"\n";
cin>>ob1[i].rollno;
cout<<"Enter name:"<<"\n";
cin>>ob1[i].name;
cout<<"Enter marks in maths:"<<"\n";
cin>>ob1[i].maths;
cout<<"Enter marks in science:"<<"\n";
cin>>ob1[i].science;
ob1[i].total=ob1[i].maths+ob1[i].science;
}
for(i=0;i<3;i++)
{
if(ob1[i].total<ob1[i+1].total)
{
temp[i]=ob1[i];
ob1[i]=ob1[i+1];
ob1[i+1]=temp[i];
}
}
Enter empno:85
Enter name:Shivam
Enter designation:Clerk
Enter department:N/A
Employee number:85
Employee name:Shivam
Employee Designation:Clerk
Employee Department:N/A
//Q.15.
//Program to accept and display record- Empno, Name, Designation and
// Department through structures
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
structabc
{
intempno;
char name[20];
chardesig[20];
char depart[20];
};
void main()
{
clrscr();
abc ob1;
cout<<"\nEnterempno:";
cin>>ob1.empno;
cout<<"\nEnter name:";
cin>>ob1.name;
cout<<"\nEnter designation:";
cin>>ob1.desig;
cout<<"\nEnter department:";
cin>>ob1.depart;
cout<<"\nEmployee number:"<<ob1.empno<<"\nEmployee name:"<<ob1.name;
cout<<"\nEmployee Designation:"<<ob1.desig<<"\nEmployee
Department:"<<ob1.depart;
getch();
}