enter a number
TRANSCRIPT
Enter a number: 151
Choose the program to perform
1. To check if number is palindrome or not
2. To check if number is even or odd
Your choice: 1
The number is palindrome
Enter a number: 113
Choose the program to perform
1. To check if number is palindrome or not
2. To check if number is even or odd
Your choice: 2
Number is odd
//Q.1.
// Menu driven program to check whether number is:
// Palindrome or not
// even or odd
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int num, choice;
cout<<" Enter a number:";
cin>>num;
cout<<"\n Choose the program to perform";
cout<<"\n 1.To check if number is palindrome or not";
cout<<"\n 2.To check if number is even or odd";
cout<<"\n Your choice:";
cin>>choice;
switch(choice)
{
case 1: int a,b;
a=num/100;
b=num%10;
if(a==b)
{
cout<<"\n The number is palindrome";
}
else
{
cout<<"\n The number is not palindrome";
}
break;
case 2: if(num%2==0)
{
cout<<"\n Number is even";
}
else
{
cout<<"\n Number is odd";
}
break;
default :cout<<"\n Wrong choice";
}
getch();
}
Enter a number: 153
Choose a program to perform
1. Check if no is prime
2. Check if no is armstrong or not
Enter your choice: 2
Number is armstrong
Enter a number: 8
Choose a program to perform
1. Check if no is prime
2. Check if no is armstrong or not
Enter your choice: 1
Number is not prime
//Q.2.//Menu driven program to check if number is://Prime or Composite//Armstrong or not
#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
It is not a leap year.
//Q.3.
// Program to accept a year & check if it is a leap year or not
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int year;
cout<<"\n Enter a year (in 4 digits):";
cin>>year;
if(year%4==0)
{
if (year%400==0)
{
cout<<"\n It is Leap year.";
}
else
{
cout<<"\n It is not a leap year.";
}
}
getch();
}
How many elements(>5)?: 9
Fibonacci series: 0 1 1 2 3 5 8 13 21
//Q.4.
//Program to generate Fibonacci Series.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a=0,b=1,c,n,i;
cout<<"How many elements(>5)?: ";
cin>>n;
cout<<"\nFibonacci series: ";
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.
//TO WRITE A C++ PROGRAM TO GENERATE THE FOLLOWING PATTERN
// A
// A B
// A B C
// A B C D
// A B C D E
#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:
1
2
3
4
5
6
7
8
9
Enter another 3X3 matrix:
1
2
5
4
6
7
8
9
2
First matrix is:
1 2 3
4 5 6
7 8 9
Second matrix is:
1 2 5
4 6 7
8 9 2
MATRIX MENU:
1. ADDITION OF MATRICES
2. SUBSTRACTION OF MATRICES
3. MULTIPLICATION OF MATRICES
4. EXIT
ENTER YOUR CHIOCE (1-4):1
SUM OF MATRIX IS :
2 4 8
8 11 13
15 17 11
//Q.6.
// TO WRITE A MENU DRIVEN PROGRAM TO PERFORM THE FOLLOWING:
// 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;
cout<<" \n \t \t \t WELCOME TO THE MENU DRIVEN PROGRAM";
cout<<" \n\nEnter a 3X3 matrix: \n";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cin>>a[i][j];
}
}
cout<<" \n\nEnter another 3X3 matrix: \n";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cin>>b[i][j];
}
}
clrscr();
cout<<" \n \t First matrix is: \n";
for(i=0;i<3;i++)
{
cout<<"\n \t ";
for(j=0;j<3;j++)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
cout<<" \n \t Second matrix is: \n";
for(i=0;i<3;i++)
{
cout<<" \n \t ";
for(j=0;j<3;j++)
{
cout<<b[i][j]<<" ";
}
cout<<endl;
}
cout<<" \n \n \t MATRIX MENU:";
cout<<" \n \t 1. ADDITION OF MATRICES";
cout<<" \n \t 2. SUBSTRACTION OF MATRICES";
cout<<" \n \t 3. MULTIPLICATION OF MATRICES";
cout<<" \n \t 4. EXIT";
cout<<" \n \n \t ENTER YOUR CHIOCE (1-4):";
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];
}
}
cout<<" \n \t SUM OF MATRIX IS : \n";
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];
}
}
cout<<" \n \t DIFFERENCE OF TWO MATRIX IS : \n";
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]);
}
}
}
cout<<" \n \t PRODUCT OF TWO MATRIX ARE: \n";
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);
default :cout<<" \n \t Wrong choice";
}
getch();
}
ENTER MATRIX OF 25 ELEMENTS:
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
ENTERED MATRIX IS:
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
CHOICES ARE:
1.DISPLAY UPPER TRIANGULAR PART OF MATRIX
2.DISPLAY LOWER TRIANGULAR PART OF MATRIX
3.TRANSPOSE THE MATRIX
4.EXIT
ENTER YOUR CHOICE (1-4):1
ENTERED CHOICE IS : 1
UPPER TRIANGULAR PART OF MATRIX IS:
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
// 1.DISPLAY UPPER TRIANGULAR PART OF MATRIX
// 2.DISPLAY LOWER TRIANGULAR PART OF MATRIX
// 3.TRANSPOSE THE MATRIX
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[3][3],b[3][3],i,j,choice;
cout<<"\n Enter a 3X3 matrix:";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cin>>a[i][j];
}
}
cout<<"\n \n \t MATRIX MENU:";
cout<<"\n 1.Display Upper Triangle Of Matrix";
cout<<"\n 2.Display Lower Triangle Of Matrix";
cout<<"\n 3.Transpose The Matrix";
cout<<"\n ENTER YOUR CHOICE (1-4):";
cin>>choice;
cout<<"\n\n\tYour choice is: "<<choice;
switch(choice)
{
case 1: cout<<"\n \t Upper triangle of matrix is:\n";
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;
case 2: cout<<"\n \t Lower Triangle of matrix is:\n";
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;
case 3: cout<<"\n \t Transposed matrix is:\n";
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;
default: cout<<"\nWrong choice";
}
getch();
}
ENTER 9 ELEMENTS:
1
2
3
4
5
6
7
8
9
ENTERED 9 ELEMENTS ARE:
1 2 3
4 5 6
7 8 9
CHOICES ARE:
1. MAXIMUM ELEMENT
2. MINIMUM ELEMENT
3. AVERAGE OF ELEMENTS
4. EXIT
ENTER YOUR CHOICE (1-4):3
CHOICE ENTERED IS :3
AVERAGE OF ELEMENTS IS :5
//Q.8.
//Menu driven program to display following in single matrix
//Maximum element
//Minimum element
//Average element
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[3][3], max, min, sum=0, av;
inti,j,ch;
cout<<"Enter a matrix:";
for(i=0; i<3; i++)
{
for(j=0;j<3;j++)
{
cin>>a[i][j];
}
}
cout<<"\nMatrix Operations Menu:";
cout<<"\n1.Maximum Element"<<"\n2.Minimum Element"<<"\n3.Average Element";
cout<<"\n\nEnter your choice(1-3): ";
cin>>ch;
switch(ch)
{
case 1: max=a[0][0];
for(i=0; i<3; i++)
{
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;
case 3: for(i=0; i<3; i++)
{
for(j=0;j<3;j++)
{
sum=sum + a[i][j];
}
}
av=(sum/(i*j));
cout<<"\nAverage Of Elements="<<av;
break;
default :cout<<"\nWrong Choice";
}
getch();
}
ENTER STRING: New Delhi
String Menu
1.Count Vowels
2.Count Consonants
3.Count Digits
4.Count special characters
Enter your choice: 1
Number of vowels is: 3
ENTER STRING: Damnyouman
String Menu
1.Count Vowels
2.Count Consonants
3.Count Digits
4.Count special characters
Enter your choice: 2
Number of consonants in the string is:6
ENTER STRING: Madr85pl6785
String Menu
1.Count Vowels
2.Count Consonants
3.Count Digits
4.Count special characters
Enter your choice: 3
Number of digits is:6
ENTER STRING: hy$&^%$nuisd
String Menu
1.Count Vowels
2.Count Consonants
3.Count Digits
4.Count special characters
Enter your choice:4
Number of special characters is: 5
//.Q.9
//Menu-driven Program to perform following operations in a string
//Count number of vowels
//Count number of consonants
//Count number of digits
//Count number of special characters
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
void main()
{
clrscr();
charstr[20];
inti,vow=0,cons=0,dig=0,spec=0,ch;
cout<<"\nENTER STRING: ";
cin.getline(str,20);
cout<<"\nString Menu";
cout<<"\n1.Count Vowels";
cout<<"\n2.Count Consonants";
cout<<"\n3.Count Digits";
cout<<"\n4.Count special characters";
cout<<"\nEnter your choice:";
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++;
}
}
cout<<"\nNumber of vowels is:"<<vow;
break;
case 2: for(i=0; str[i]!='\0'; i++)
{
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++;
}
}
cout<<"\nNumber of consonants in the string is:"<<cons;
break;
case 3: for(i=0; str[i]!='\0'; i++)
{
str[i]=tolower(str[i]);
if(str[i]>='0'&&str[i]<='9')
{
dig++;
}
}
cout<<"\nNumber of digits is:"<<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++;
}
}
cout<<"\nNumber of special characters is:"<<spec;
break;
default :cout<<"\nWrong Choice";
}
getch();
}
Enter a string: NEW DELHI
String Menu:
1.Uppercase to Lowercase
2.Lowercase to Uppercase
3.Reverse a string
Enter your choice:1
New string is:newdelhi
Enter a string:new delhi
String Menu:
1.Uppercase to Lowercase
2.Lowercase to Uppercase
3.Reverse a string
Enter your choice: 2
New string is:NEW DELHI
Enter a string: edivid wen
String Menu:
1.Uppercase to Lowercase
2.Lowercase to Uppercase
3.Reverse a string
Enter your choice:3
Reversed string is: new divide
//Q.10
//TO WRITE A MENU DRIVEN PROGRAM TO PERFORM THE FOLLOWING
// OPERATION ON 1-D CHARACTER ARRAY:
// 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";
cout<<"\nEnter your choice:";
cin>>choice;
switch(choice)
{
case 1:for(i=0;str[i]!='\0';i++)
{
str[i]=tolower(str[i]);
}
cout<<"\nNew string is:";
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]);
}
cout<<"\nNew string is:";
for(i=0;str[i]!='\0';i++)
{
cout<<str[i];
}
break;
case 3:for(i=0;str[i]!='\0';i++)
{
}
cout<<"Reversed string is:";
for(j=i;j>=0;j--)
{
cout<<str[j];
}
break;
default:cout<<"\nWrong Choice!!!";
}
getch();
}
ENTER THREE NAMES :
GOPI
KRISHH
SALMAN
ENTER AGAIN THREE NAMES :
HIMADRI
AKHI
SANJAY
NAMES ENTERED IN FIRST ARRAY ARE :
GOPI
KRISHH
SALMAN
NAMES ENTERED IN SECOND ARRAY ARE :
HIMADRI
AKHI
SANJAY
ENTERED NAMES AFTER CONCATENATION ARE :
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();}
longint factorial(long int n) {int fact;if(n==0) {fact=1;return(fact); }else {return(n*factorial(n-1)); } }
Enter two numbers: 48
52
Enter an operator:+
Sum is: 100
Enter two numbers:40
9
Enter an operator:-
Difference is:31
Enter two numbers:57
12
Enter an operator:*
Product is: 684
Enter two numbers: 110
56
Enter an operator:/
Quotient is:1
Enter two numbers:562
100
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 DETAILS OF STUDENT ENTER THE ROLL NO :7
ENTER NAME :RAGHAV
ENTER MARKS IN MATHS :60
ENTER MARKS IN SCIENCE :70
ENTER GRADE :B
ENTER DETAILS OF STUDENT ENTER THE ROLL NO :18
ENTER NAME :RAM
ENTER MARKS IN MATHS :50
ENTER MARKS IN SCIENCE :82
ENTER GRADE :C
ENTER DETAILS OF STUDENT ENTER THE ROLL NO :25
ENTER NAME :SALIL
ENTER MARKS IN MATHS :69
ENTER MARKS IN SCIENCE :30
ENTER GRADE :D
MERIT ORDER :
ROLL NO :18NAME :RAM MARKS IN MATHS :50 MARKS IN SCIENCE :82 TOTAL MARKS :132GRADE :C
ROLL NO :7NAME :RAGHAV MARKS IN MATHS :60 MARKS IN SCIENCE :70 TOTAL MARKS :130GRADE :B
ROLL NO :25NAME :SALIL MARKS IN MATHS :69 MARKS IN SCIENCE :30 TOTAL MARKS :99GRADE :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]; } }
cout<<"\nRoll Number"<<"\tName"<<"\tMarks In Maths"<<"\tMarks in Science";for(i=0;i<3;i++) {cout<<"\n"<<ob1[i].rollno<<"\t"<<ob1[i].name<<"\t"<<ob1[i].maths<<"\t"<<ob1[i].science; }getch();
EMPLOYEE RECORD
Enter empno:85
Enter name:Shivam
Enter designation:Clerk
Enter department:N/A
Employee number:85Employee name:ShivamEmployee Designation:ClerkEmployee 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();}