Beruflich Dokumente
Kultur Dokumente
#include<iostream.h>
#include<conio.h>
void main ()
{
clrscr ();
int
char ch;
cout<<"Enter your alphabet - ";
cin>>ch;
switch (ch)
{case 'a':cout<<"Alphabet is a Vowel";
break;
case 'e':cout<<"Alphabet is a Vowel";
break;
case 'i':cout<<"Alphabet is a Vowel";
break;
case 'o':cout<<"Alphabet is a Vowel";
break;
case 'u':cout<<"Alphabet is a Vowel";
break;
case 'A':cout<<"Alphabet is a Vowel";
break;
case 'E':cout<<"Alphabet is a Vowel";
break;
case 'I':cout<<"Alphabet is a Vowel";
break;
case 'O':cout<<"Alphabet is a Vowel";
break;
case 'U':cout<<"Alphabet is a Vowel";
break;
default:cout<<"Alphabet is a Consonant";}
}
#include<iostream.h>
void main()
{
int a,b;
for(a=1;a<=10;++a)
{
cout<<endl;
for(b=1;b<=a;++b)
cout<<"*";
}
}
(II TYPE)
#include<iostream.h>
void sWRITE A PROGRAM(int &,int &);
void main()
{
int a,b;
cout<<"Enter value of a : ";
cin>>a;
cout<<"Enter value of b : ";
cin>>b;
sWRITE A PROGRAM(a,b);
cout<<"Value of a after sWRITE A PROGRAMping : "<<a<<endl;
cout<<"Value of b after sWRITE A PROGRAMping : "<<b<<endl;
}
void sWRITE A PROGRAM(int & a,int & b)
{
int c;
c=a-b;
a=a-c;
b=b+c;
}
WRITE A PROGRAM WHICH ACCEPT PERCENTAGE MARKS OF STUDENT AND PRINTS HIS RESULT
AS GIVEN CRITERIA:
PM<35
FAIL
PM>=35 AND PM<50
3RD DIVISION
PM>=50 AND PM<60
2ND DIVISION
PM>=60 AND PM<95
1ST DIVISION
OTHERWISE STUDENT PASSED WITH DISTINCTION.
#include<iostream.h>
void main()
{
int p;
cout<<"Enter the percentage : ";
cin>>p;
if(p<35)
cout<<"fail";
else
if((p>=35)&&(p<50))
cout<<"3rd Division";
else
if((p>=50)&&(p<60))
cout<<"2nd Division";
else
if((p>=60)&&(p<95))
cout<<"1st division";
else
cout<<"Passed with distinction";
}
WRITE A PROGRAM TO FIND OUT THE ELECTRICITY BILL AS GIVEN IN FOLLOWING CRITERIA
WHEN UNITS CONSUMED INPUT BY USER.( MONTHLY RENT IS RS. 120 TO CHARGED FROM EVERY
CONSUMER)
UNIT CONSUMED
RATE PER UNIT
FIRST 100 UNITS
RS. 1.50
NEXT 250 UNITS
RS. 2.00
NEXT 500 UNITS
RS. 4.00
BEYOND 850 UNITS
RS. 5.00
#include<iostream.h>
void main()
{
int csm,rnt=120,bill,x;
cout<<"Enter units you have consumed : ";
cin>>csm;
{
if(csm<=100)
bill=rnt+1.5*csm;
else
if(csm>100 && csm<=350)
bill=rnt+150+(csm-100)*2;
else
if(csm>350 && csm<=850)
bill=rnt+150+500+(csm-350)*4;
else
if(csm>850)
bill=rnt+150+500+2000+(csm-850)*5;
}
cout<<"Your bill is Rupees "<<bill;
}
break;}
}
if(i==n)
cout<<"Element not found";
}
WRITE A PROGRAM TO CALCULATE SUM OF EACH ROW AND EACH COLUMN OF A 2D ARRAY.
#include<iostream.h>
#include<stdio.h>
int main(){
int a[3][3],b[3][3],c[3][3],i,j;
cout<<"Enter the First matrix -> "<<endl;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
cin>>a[i][j];
cout<<"Enter the Second matrix -> "<<endl;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
cin>>b[i][j];
cout<<"\nThe First matrix is\n";
for(i=0;i<3;i++){
cout<<"\n";
for(j=0;j<3;j++)
cout<<"\t"<<a[i][j];
}
cout<<"\nThe Second matrix is\n";
for(i=0;i<3;i++)
{
cout<<"\n";
for(j=0;j<3;j++)
cout<<"\t"<<b[i][j];
}
for(i=0;i<3;i++)
for(j=0;j<3;j++)
c[i][j]=a[i][j]+b[i][j];
cout<<"\nThe Addition of two matrix is\n";
for(i=0;i<3;i++){
cout<<"\n";
for(j=0;j<3;j++)
cout<<"\t"<<c[i][j];
}
return 0;
}
}
}
WRITE A PROGRAM TO FIND THE SUM OF UPPER AND LOWER DIAGONAL ELEMENTS OF A
MATRIX
#include <iostream.h>
int i, j, X[3][3];
void main()
{
cout<<"Enter the values of the matrix (3x3) : "<<endl;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
cin>>X[i][j];
cout<<endl;
cout<<"The matrix formed is : "<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
cout<<X[i][j]<<"\t";
cout<<endl;
}
cout<<endl;
int sum1=0;
int sum2=0;
int sum3=0;
int sum4=0;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
if(i+j<=1)
sum1+=X[i][j];
else
if(i+j>=3)
sum2+=X[i][j];
}
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
if(i<j)
sum3+=X[i][j];
else
if(i>j)
sum4+=X[i][j];
}
cout<<"Sum of the upper triangle from left is : "<<sum1<<endl;
cout<<"Sum of the lower triangle from right is : "<<sum2<<endl;
cout<<"Sum of the upper triangle from right is : "<<sum3<<endl;
cout<<"Sum of the lower triangle from left is : "<<sum4<<endl;
}
WRITE A PROGRAM TO FIND THE GREAEST COMMON DIVISOR BETWEEN TWO NUMBERS
#include <math.h>
#include<iostream.h>
int getGCD(int a, int b)
{
a = a % b;
if (a == 0)
{
return b;
b=(b%a);
}
if (b==0)
{
return(a);
}
}
int main()
{
int x, y;
cout<< "Please enter two integers x and y, for GCD calculation" <<endl;
cin>> x >> y;
cout<< "The GCD of " << x << " and " << y << " is " <<getGCD(x, y) <<endl;
return (0);
}
void main()
{
clrscr();
int a,b,c,d=0;
cout<<"Enter the no. you want to check: ";
cin>>a;
b=a;
do
{
c=b%10;
b=b/10;
d=(d*10)+c;
}
while(b!=0);
if(d==a)
cout<<"This is a pallindrome";
else
cout<<"This isn't a pallindrome";
getch();
}
WRITE A PROGRAM WHICH ACCEPTS A STRING, COUNT THE NO. OF VOWELS USING
SWITCH AND PRINT THE SAME
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
char string[10];
int len=0,count=0;
cout<<"Enter the string: ";
gets(string);
for(len=0;string[len]!='\0';len++)
{
switch(string[len])
{
case'A':
case'a':
case'E':
case'e':
case'I':
case'i':
case'O':
case'o':
case'U':
case'u':
count++;
}
}
cout<<"The no.s of vowels is/are:"<<count;
getch();
}
for(i=0;i<4;i++)
for(j=0;j<4;j++)
cin>>A[i][j];
cout<<"The matrix formed is : "<<endl;
for (int k=0;k<4;k++)
{
for (int l=0;l<4;l++)
cout<<X[k][l]<<"\t";
cout<<endl;
}
cout<<endl;
cout<<"New Array: \n";
k=0;
for(i = 0;i<4;i++)
{
for(j=0;j<4;j++)
{
B[k++] = A[i][j];
}
}
WRITE A FUNCTION WHICH RECEIVE TWO PARAMETERS A AND B THEN RETURN A RAISE
TO POWER B. (SUPPOSE ARGUMENTS 5, 4 THEN IT SHOULD RETURN 625)
#include<iostream.h>
#include<math.h>
int power(int,int);
int main()
{ int a,b,c;
cout<<"Enter any two numbers: "<<endl;
cin>>a>>b;
c=power(a,b);
cout<<a<<" to the power "<<b<<" = "<<c;
return 0;
}
int power(int a, int b)
{ int c;
c=pow(a,b);
return c;
}
WRITE A FUNCTION WHICH RECEIVES AN ARRAY, ITS SIZE AND AN ITEM AS ARGUMENTS.
THE FUNCTION SHOULD RETURN THE LOCATION OF ITEM IF IT IS FOUND IN ARRAY
OTHERWISE IT SHOULD RETURN -1.
#include<iostream.h>
#include<conio.h>
int linear_search(int [],int,int);
main()
{ clrscr();
const array_size=10;
int array[array_size]={0};
cout<<"\n Enter the contents of the array are : "<<endl;
cout<<"\n
Elements :"<<"\t\t
Value:"<<endl;
for(int count=0;count<array_size;count++)
{
}
int searching_element=0;
int flag=0;
cout<<"\n\n Enter the element you want to find = ";
cin>>searching_element;
flag=linear_search(array,array_size,searching_element);
if(flag!=-1)
cout<<"\n The given element is found at the position array["<<
flag<<"]"<<endl;
else
cout<<"\n The given element is not found. "<<endl;
getch();
return 0;
}
int linear_search(int array[],int size,int element)
{ for(int count=0;count<size;count++)
{ if(element==array[count])
{ return count;
}
}
return -1;
}
WRITE A PROGRAM TO FIND THE MAXIMUM AND MINIMUM NUMBER FROM 10 NUMBERS
ENTERED AND HOW MAYN TIMES THEY OCCURRED
#include<iostream.h>
void main()
{
int x[10], max, min;
cout<<"Enter your 10 nubers : "<<endl;
for(int i=0; i<=9; i++)
{
cin>>x[i];
}
{
max=x[0];
for(int j=0; j<=9; j++)
{
if(x[j]>max)
max=x[j];
}
min=x[0];
for(int k=0; k<=9; k++)
{
if(x[k]<min)
min=x[k];
}
cout<<"The max value is : "<<max<<endl;
cout<<"The min value is : "<<min<<endl;
}
int c=0;
for(int a=0; a<=9; a++)
{
if (x[a]==max)
c++;
}
int d=0;
for(int b=0; b<=9; b++)
{
if (x[b]==min)
d++;
}
cout<<"Number of times max value appeared : "<<c<<endl;
cout<<"Number of times min value appeared : "<<d<<endl;
}
cout<<"Enter Length"<<endl;
cin>>l;
cout<<"Enter Breadth"<<endl;
cin>>b;
cout<<endl;
peri=2*(l+b);
cout<<"Perimeter = "<<peri;
}
break;
case '3' :
{
cout<<"Enter Length"<<endl;
cin>>l;
cout<<"Enter Breadth"<<endl;
cin>>b;
cout<<endl;;
diag=sqrt((l*l)+(b*b));
cout<<"Diagonal = "<<diag;
}
break;
case '4' :
exit (0);
default :
cout<<"Wrong Choice Entered";
}
}