Sie sind auf Seite 1von 26

WRITE A PROGRAM TO FIND WEATHER AN ENTERED ALPHABET IS A VOWEL OR A CONSONANT

#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";}
}

WRITE A PROGRAM TO FIND WEATHER LARGEST NUMBER AMONG THE THREE


#include <iostream.h>
#include <conio.h>
void main ()
{
long a,b,c;
cout<<"enter first number - ";
cin>>a;
cout<<"enter second number - ";
cin>>b;
cout<<"enter third number - ";
cin>>c;
if((a>b)&&(a>c))
cout<<"the largest number is "<<a;
if((a>b)&&(a<c))
cout<<"the largest number is "<<c;
if((b>a)&&(b>c))
cout<<"the largest number is "<<b;
if((b>a)&&(b<c))
cout<<"the largest number is "<<c;
if((c>a)&&(c>b))
cout<<"the largest number is "<<c;
if((c>a)&&(c<b))
cout<<"the largest number is "<<b;
}

WRITE A PROGRAM TO GET THE TABLE OF AN ENTERED NUMBER.


#include <iostream.h>
void main ()
{
int i,n;
cout<<"Enter the number whose table you want - ";
cin>>n;
for (i=0;i<=20;i++)
{
int product=i*n;
cout<<"\n"<<n<<"*"<<i<<"="<<product;
}
}

WRITE A PROGRAM TO KNOW THE USE OF INCREMENT AND DECREMENT OPERATOR.


#include<iostream.h>
void main ()
{
int a,b,c,d;
cout<<"enter value of a,b,c ";
cin>>a>>b>>c;
d=a++- --b +c++ -b -c;
cout<<"value is "<<d;
}

WRITE A PROGRAM TO FIND WEATHER A YEAR IS A LEAP YEAR OR NOT.


#include<iostream.h>
void main()
{
int a;
cout<<"Enter the value of year in A.D. : ";
cin>>a;
switch (a%4)
{
case 1 : cout<<"The year is not a leap year";
break;
case 2 : cout<<"The year is not a leap year";
break;
case 3 : cout<<"The year is not a leap year";
break;
default : cout<<"The year is a leap year";
}
}

WRITE A PROGRAM TO PRINT A PYRAMID.


#include<iostream.h>
void main()
{
int a,b;
for(a=10;a>=1;--a)
{
cout<<endl;
for(b=1;b<=a;++b)
cout<<"*";
}
}

#include<iostream.h>

void main()
{
int a,b;
for(a=1;a<=10;++a)
{
cout<<endl;
for(b=1;b<=a;++b)
cout<<"*";
}
}

WRITE A PROGRAM TO MAKE A CALCULATOR.


#include<iostream.h>
void main()
{
int x,y,z;
char op;
cout<<"Enter your first numer : ";
cin>>x;
cout<<endl<<"Enter your second number : ";
cin>>y;
cout<<endl<<"Enter your operator(+,-,*,/) : "<<endl;
cin>>op;
switch(op)
{
case '+': z=x+y;
cout<<"The answer is : "<<z;
case '-': z=x-y;
cout<<"The answer is : "<<z;
case '*': z=x*y;
cout<<"The answer is : "<<z;
case '/': z=x/y;
cout<<"The answer is : "<<z;
default : cout<<"wrong operator entered.";
}
}

WRITE A PROGRAM TO CONVERT TEMPERATURE FROM CELSIUS TO FARENHIET.


#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,C,F;
cout<<"Enter 1, if u want to change from celsius to fahrenhiet"<<"\n";
cout<<"Enter 2, if u want to change from fahrenhiet to celsius"<<"\n";
cin>>a;
if(a==1)
{
cin>>C;
F=(9*C+160)/5;
cout<<F;
}
else
if(a==2)
{
cin>>F;
C=(5*F-160)/9;
cout<<C;
}
else
cout<<"wrong choice entered";
}
WRITE A PROGRAM TO FIND IF A NUMBER ENTERED IS ODD/EVEN OR PRIME/COMPOSITE
#include <iostream.h>
#include<process.h>
void main()
{
long a;
cout<<"Enter the number : ";
cin>>a;
cout<<"\n";
if(a%2==0)
{
cout<<"An even number"<<"\n";
}
if(a%2==1)
{
cout<<"An odd number"<<"\n";
}
for(int b=2;b<a;b++)
{
if(a%b==0)
{
cout<<"A composite number";exit(0);
}
}
if(a!=1)
cout<<"A prime number";
if(a==1)
cout<<"Neither a prime nor a composite number";
}

WRITE A PROGRAM TO AWAP TWO NUMBERS


(I 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;
a=b;
b=c;
}

(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;
}

WRITE A PROGRAM TO FIND FACTORIAL OF ANY NUMBER


#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
intn,i,f=1;
cout<<"Enter a no you want the factorial"<<endl;
cin>>n;
for(i=1;i<=n;i++)
f=f*i;
cout<<"Factorial ="<<f;
getch();
}

WRITE A PROGRAM TO PRINT THE FIBONACCI SERIES UP TO n TERMS.


#include<iostream.h>
int main()
{
int n, first = 0, second = 1, next, c;
cout<<"Enter the number of terms : ";
cin>>n;
cout<<"First n terms of Fibonacci series are : "<<endl;
for ( c = 0 ; c < n ; c++ )
{
if ( c <= 1 )
next = c;
else
{
next = first + second;
first = second;
second = next;
}
cout<<next<<" ";
}
return 0;
}

WRITE A PROGRAM TO PRINT ALL ARMSTRONG NOS. FROM 1 TO 1000


#include<iostream.h>
#include<stdio.h>
main()
{
int number, temp, digit1, digit2, digit3;
cout<<"Print all Armstrong numbers between 1 and 1000:"<<endl;
number = 001;
cout<<"The armstrong numbers are : ";
while (number <= 900)
{
digit1 = number - ((number / 10) * 10);
digit2 = (number / 10) - ((number / 100) * 10);
digit3 = (number / 100) - ((number / 1000) * 10);
temp = (digit1 * digit1 * digit1) + (digit2 * digit2 * digit2) + (digit3 * digit3 * digit3);
if (temp == number)
{
cout<<"\n"<<temp;
}
number++;
}
}

WRITE A PROGRAM TO FIND THE SUM OF THE DIGITS OF A NUMBER


#include<iostream.h>
#include <stdio.h>
#include <conio.h>
void main()
{
int num,s=0;
cout<<"Enter the number : ";
cin>>num;
while(num>0)
{
s+=num%10;
num/=10;
}
cout<<"Sum of digits value is = "<<s;
getch();
}
WRITE A PROGRAM TO PRINT ALL THE ASCII CODES AND ITS EQUIVALENT CHARACTERS.
#include<iostream.h>
void main()
{
int ch;
for(ch=33;ch<=122;ch++)
cout<<ch<<" -> "<<char(ch)<<" ";
}

WRITE A PROGRAM TO CALCULATE THE LENGTH OF A GIVEN STRING


#include<iostream.h>
#include<stdio.h>
void main()
{
char string[50];
int i, length = 0;
cout<<"Enter a string"<<"\n";
gets(string);
for (i = 0; string[i] != '\0'; i++)
{
length++;
}
cout<<"The length of a string is the number of characters in it"<<"\n";
cout<<"So, the length of the string"<<"\n";
cout<<string<<"\t";
cout<<"is"<<"\t"<<length;
}

WRITE A PROGRAM TO CHANGE THE LOWERCASE STRING INTO UPPERCASE STRING


#include<stdio.h>
#include<conio.h>
#include<iostream.h>
void upper(char[]);
int main()
{
char str[20];
clrscr();
cout<<"Enter string : ";
gets(str);
upper(str);
getch();
return 0;
}
void upper(char str[20])
{
int i;
cout<<" String in upper case is ";
for(i=0;str[i];i++)
{
if(str[i]>96 &&str[i]<123)
str[i]-=32;
}
cout<<str;
}

WRITE A PROGRAM TO CHECK WHETHER A GIVEN STRING IS PALINDROME OR NOT.


#include <iostream.h>
#include <string.h>
int main()
{
char str[100];
cout << "Enter word : ";
cin >>str;
int x = strlen(str)-1;
for(int i = 0; i <= x; i++)
{
if (str[i] == str[x-i])
{
continue;
}
else
{
cout<<"Not a palidrome"<<endl;
return 0;
}
}
cout << "Indeed Palidrome"<<endl;
return 0;
}

WRITE A PROGRAM TO CONCATENATE TWO STRINGS


#include<stdio.h>
#include<iostream.h>
int main(){
int i=0,j=0;
char str1[20],str2[20];
puts("Enter first string");
gets(str1);
puts("Enter second string");
gets(str2);
printf("Before concatenation the strings are\n");
puts(str1);
puts(str2);
while(str1[i]!='\0'){
i++;
}
while(str2[j]!='\0'){
str1[i++]=str2[j++];
}
str1[i]='\0';
printf("After concatenation the strings are\n");
puts(str1);
return (0);
}

WRITE A PROGRAM TO REVERSE AN ARRAY


#include<iostream.h>
#include<conio.h>
int main()
{
Int Arr[100],n,temp,i,j;
cout<<"Enter number of elements you want to insert ";
cin>>n;
for(i=0;i<n;i++)
{
cout<<"Enter element "<<i+1<<":";
cin>>Arr[i];
}
for(i=0,j=n-1;i<n/2;i++,j--)
{
temp=Arr[i];
Arr[i]=Arr[j];
Arr[j]=temp;
}
cout<<"\nReverse array"<<endl;
for(i=0;i<n;i++)
cout<<Arr[i]<<" ";
getch();
return 0;
}
WRITE A PROGRAM SEARCH AN ELEMENT IN AN ARRAY.
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
void main()
{
int array[10],n,i,find;
clrscr();
cout<<"Enter the no. of elements in array: ";
cin>>n;
cout<<"Enter the elements"<<endl;
for(i=0;i<n;i++)
{
cout<<i+1<<". ";
cin>>array[i];
}
cout<<endl<<"Enter element to find: ";
cin>>find;
for(i=0;i<n;i++)
{
if(array[i]==find)
{
cout<<"Element is present at position "<<i+1;

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 SUM OF MATRICES


#include <iostream.h>
void main()
{
int X[3][3],Y[3][3],Z[3][3];
int a,b;
cout<<"Enter the values of the first maitrix (3x3)"<<endl;
for (int i=0;i<3;i++)
{
for (int j=0;j<3;j++)
cin>>X[i][j];
}
cout<<endl;
cout<<"The matrix formed is : "<<endl;
for (int k=0;k<3;k++)
{
for (int l=0;l<3;l++)
cout<<X[k][l]<<"\t";
cout<<endl;
}
cout<<endl;
cout<<"Enter the values of the second maitrix (3x3)"<<endl;
for (int m=0;m<3;m++)
{
for (int n=0;n<3;n++)
cin>>Y[m][n];
}
cout<<endl;
cout<<"The matrix formed is : "<<endl;
for (int o=0;o<3;o++)
{
for (int p=0;p<3;p++)
cout<<Y[o][p]<<"\t";
cout<<endl;
}
cout<<endl;
for (int q=0;q<3;q++)
for (int r=0;r<3;r++)
Z[q][r]=X[q][r]+Y[q][r];
cout<<endl;
cout<<"The matrix of the sum of the 2 matrix is : "<<endl;
for (int s=0;s<3;s++)
{
for (int t=0;t<3;t++)
cout<<Z[s][t]<<"\t";
cout<<endl;
}
cout<<endl;
}

WRITE A PROGRAM TO FIND MULTIPLICATION OF TWO MATRICES.


#include <iostream.h>
void main()
{
int X[3][3],Y[3][3],Z[3][3],d,e;
cout<<"Enter the values of the first maitrix (3x3)"<<endl;
for (int i=0;i<3;i++)
{
for (int j=0;j<3;j++)
cin>>X[i][j];
}
cout<<endl;
cout<<"The matrix formed is : "<<endl;
for (int k=0;k<3;k++)
{
for (int l=0;l<3;l++)
cout<<X[k][l]<<"\t";
cout<<endl;
}
cout<<endl;
cout<<"Enter the values of the second maitrix (3x3)"<<endl;
for (int m=0;m<3;m++)
{
for (int n=0;n<3;n++)
cin>>Y[m][n];
}
cout<<endl;
cout<<"The matrix formed is : "<<endl;
for (int o=0;o<3;o++)
{
for (int p=0;p<3;p++)
cout<<Y[o][p]<<"\t";
cout<<endl;
}
for(int a=0;a<3;a++)
for (int b=0;b<3;b++)
{
int sum=0;
for (int c=0;c<3;c++)
{
sum=sum+(X[a][c]*Y[c][b]);
Z[a][b]=sum;
}
}
cout<<endl;
cout<<"The matrix of the product of the 2 matrix is : "<<endl;
for (int s=0;s<3;s++)
{
for (int t=0;t<3;t++)
cout<<Z[s][t]<<"\t";
cout<<endl;

}
}

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);
}

WRITE A PROGRAM TO FIND WHETHER A GIVEN CHARACTER IS IN UPPER CASE,


LOWER CASE, A DIGIT OR ANY SPECIAL CHARACTER
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char a;
cout<<"Enter the character: ";
cin>>a;
if(a>=48&&a<=57)
cout<<"Entered character is a digit";
else if(a>=65&&a<=90)
cout<<"Entered caharcter is in UPPERCASE";
else if(a>=97&&a<=122)
cout<<"Entered character is in lowercase";
else if(a>=0&&a<=255)
cout<<"Entered character is a special character";
getch();
}
WRITE A PROGRAM TO CHECK WHETHER A GIVEN NO. IS PALLINDROME OR NOT.
#include<iostream.h>
#include<conio.h>

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();
}

WRITE A PROGRAM TO CHANGE 2D ARRAY INTO 1D ARRAY ROW-WISE


#include<iostream.h>
#include<conio.h>
void main()
{
int j,i,k,A[4][4],B[16];
cout<<"Enter an array 4x4: "<<endl;

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];
}
}

for(k=0; k<16; k++)


cout <<B[k]<<" ";
getch();
}

WRITE A FUNCTION IN C++ TO REVERSE A NUMBER.


#include<iostream.h>
int reverseint(int);
int main()
{ int num,rev;
cout<<"Enter the number (max. 32767): "<<endl;
cin>>num;
rev=reverseint(num);
cout<<"Reverse of the number is "<<rev;
return 0;
}
int reverseint(int num)
{ int digit,rev=0;
do
{ digit=num%10;
rev=(rev*10)+digit;
num=num/10;
} while(num!=0);
return rev;
}

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++)
{

cout<<"\t"<<" array ["<<count<<"]"<<"\t\t";


cin>>array[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;
}

WRITE A PROGRAM TO FIND THE AREA, PERIMETER AND DIAGONAL OF A RECTANGLE


AS PER THE USER WANTS
#include<iostream.h>
#include<math.h>
#include<conio.h>
#include<process.h>
void main ()
{
clrscr ();
float l,b,peri,area,diag;
char ch;
cout<<endl;
cout<<"Options"<<endl;
cout<<"1. Area"<<endl;
cout<<"2. Perimeter"<<endl;
cout<<"3. Diagonal"<<endl;
cout<<"4. Exit"<<endl;
cout<<endl;
cout<<"Enter Your Choice"<<endl;
cin>>ch;
cout<<endl;
switch (ch)
{
case '1' :
{
cout<<"Enter Length"<<endl;
cin>>l;
cout<<"Enter Breadth"<<endl;
cin>>b;
cout<<endl;
area=l*b;
cout<<"Area = "<<area;
}
break;
case '2' :
{

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";
}
}

Das könnte Ihnen auch gefallen