Você está na página 1de 14

WAP to print the sum of 3 no.

s :

#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
int a,b,c,sum;
cout<<Enter The Three No.s ;
cin>>a>>b>>c;
sum=a+b+c;
cout<<The Sum of Three No.s is <<sum;
getch();
}

WAP to print average and multiplication of three no.s :

#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
Int a,b,c,ave,multi;
cout<<Enter the three no.s \n;
cin>>a>>b>>c;
ave=(a+b+c)/(3);
multi=a*b*c;
cout<<The average of the no.s is \n<<ave;
cout<<the multiplication of the no.s is \n<<multi;
getch();
}

WAP to find simple intrest when principle amount, rate of intrest and time period are entered by the
user :

ANS:
#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
int p,r,t,i;
cout<<"Enter Principle : ";
cin>>p;
cout<<"Enter Rate : ";
cin>>r;
cout<<"Enter Time : ";
cin>>t;
i=(p*r*t)/100;
cout<<"Simple interest is : "<<i;

getch();
}

WAP to convert temperature from Celsius to Fahrenheit :

#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
float celsius;
float fahrenheit;
cout << "Enter Celsius temperature: ";
cin >> celsius;
fahrenheit = (5/9) * (celsius + 32);
cout << "Fahrenheit = " << fahrenheit << endl;
getch();
}

WAP to print square and cube of an no. :

#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
Int a,square,cube;
cout<<Enter the no. ;
cin>>a;
square=a*a;
cube=a*a*a;
cout<<Square is \n<<square;
cout<<Cube is \n<<cube;
getch();
}

WAP to print largest among three no.s :

#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
int num1, num2, num3;

cout << "Please enter three numbers : " ;
cin >> num1;
cin >> num2;
cin >> num3;

if (num1 > num2 && num1 > num3)
cout << "The largest number is" << num1 << endl;
else if (num2 > num1 && num2 > num3)
cout << "The largest number is" << num2 << endl;
else if (num3 > num1 && num3 > num2)
cout << "The largest number is" << num3 << endl;
getch();
}

WAP to print factorial of any no. :

#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
int num,factorial=1;

cout<<" Enter Number To Find Its Factorial: ";

cin>>num;
for(int a=1;a<=num;a++)
{
factorial=factorial*a;
}
cout<<"Factorial of Given Number is ="<<factorial<<endl;
getch();
}

WAP to print roots of a quadratic equation :

#include<iostream.h>
#include<math.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,x1,x2;
float d;
cout<<"enter the value of a,b,c"<<"\n";
cin>>a>>b>>c;
d=(b*b)-(4*a*c);
if(d==0)
{
x1=x2=(-b)/(2*a);
cout<<"roots are real and value is"<<x1<<"\n";
}
else if(d>0)
{
x1=(-b)+sqrt(d)/(2*a);
x1=(-b)-sqrt(d)/(2*a);
cout<<"the value of two roots are"<<"\n";
cout<<"x1="<<x1<<"\n"<<"x2="<<x2;
}
else
{
cout<<"roots are imaginary";
}
getch();
}

WAP to print fibonacci series :
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a=0,b=1,c=0,n;
cout<<"Enter the number of terms you want to see: ";
cin>>n;
cout<<a<<" "<<b<<" ";
for(int i=1;i<=n-2;i++)
{
c=a+b;
a=b;
b=c;
cout<<c<<" ";
}
getch();
}

Write a menu driven programme for operations of rectangle :

#include<iostream.h>
#include<math.h>
#include<stdio.h>
void main()
{
int ch,l,b,result;
clrscr();
cout<<Enter length ;
cin>>l;

cout<<Enter breadth ;
cin>>b;

cout<<\n;
cout<<1.Perimeter.\n";
cout<<"2.Area.\n";
cout<<3.Diagonal.\n";

cout<<"Enter your choice here : ";
cin<<ch;

switch(ch)
{
case 1:
result=2*(l+b);
cout<<\nPerimeter is <<result;
break;

case 2:
result=l*b;
cout<<\nArea is <<result;
break;

case 3:
result=sqrt(l*l + b*b)
cout<<\nDiagonal is <<result;
break;


default:
cout<<"\nplease enter valid choice";

}
getch();
}

WAP to check whether a no. is palindrome or not :

#include<iostream.h>
#include<conio.h>
void main()
{
int n, num, digit, rev = 0;
cout << "Enter a positive number: ";
cin >> num;
n = num;
do
{
digit = num%10;
rev = (rev*10) + digit;
num = num/10;
}while (num!=0);
cout << " The reverse of the number is: " << rev << endl;
if (n = = rev)
cout << " The number is a palindrome";
else
cout << " The number is not a palindrome";
getch();
}

WAP to check whether input no. is even or odd :

#include<stdio.h>
#include <iostream>
void main()
{
int number;
cout << "Enter any integer: ";
cin >> number;
if(number % 2 ==0)
cout << number << " is even number.";
else
cout << number <<" is odd number.";
getch();
}

WAP to find the sum of n natural no.s :

#include<iostream.h>
#include<conio.h>
void main()
{
int i,a=0,n;
cout<<"enter the no of elements in the series";
cin>>n;
for(i=1;i<=n;i++)
{
a=a+i;
}
cout<<"result for natural no.s is"<<a;
getch();
}

WAP to check whether the input no.s is prime no. or not :

ANS:
#include<iostream.h>
void main()
{
int num;
cout << "Enter a number ";
cin >> num;
int i=2;
while(i<=num-1)
{
if(num%i==0)
{
cout << "\n" << num << " is not a prime number.";
break;
}
i++;
}
if(i==num)
cout << "\n" << num << " is a prime number.";
getch();
}

WAP to print name of the month according to entered month no. :

#include<iostream>
#include<conio.h>
void main()
{
int num = 0;

while (num != -99) {
cout << "Enter number between[1-12]: or -99 to Quit\n";
cin >> num;

switch(num)
{
case 1 :
cout << "January";
break;
case 2 :
cout << "February";
break;
case 3 :
cout << "March";
break;
case 4 :
cout << "April";
break;
case 5 :
cout << "May";
break;
case 6 :
cout << "June";
break;
case 7 :
cout << "July";
break;
case 8 :
cout << "August";
break;
case 9 :
cout << "September";
break;
case 10 :
cout << "October";
break;
case 11 :
cout << "November";
break;
case 12 :
cout << "December";
break;
default:
if (num > 12 && num != -99)
cout << "Error!!! Number must be between 1 to 12\n";
break;
}
}
getch();
}

WAP to read a string and convert it into upper case :

# include < iostream>
# include < string>
void main()
{
char str1 [30], temp[30];
cout<< "Enter the string:";
cin>> str1;
strcpy ( temp, str1);
cout<< "strupr ( temp ) : " < < strupr (temp) < < end1;
cout<< "strlwr (temp) : " < < strlwr ( temp) < < end1;
getch();

WAP to swap values of 2 variables :

#include<iostream.h>
#include<conio.h>
void main()
{
int d1, d2, temp;
clrscr();
cout<<"Enter the first number : ";
cin>>d1;
cout<<"Enter the second number : ";
cin>>d2;
temp = d1;
d1 = d2;
d2 = temp;
cout<<"The value numbers after swapping is :"<<endl;
cout<<"First no. : "<<d1<<endl;
cout<<"Second no. : "<<d2;
getch();
}

WAP to print half pyramid as using * as shown in figure below. :

*
* *
* * *
* * * *
* * * * *

#include <iostream>
void main()
{
int i,j,rows;
cout<<"Enter the number of rows: ";
cin>>rows;
for(i=1;i<=rows;++i)
{
for(j=1;j<=i;++j)
{
cout<<"* ";
}
cout<<"\n";
}
getch();
}

WAP to print half pyramid as using numbers as shown in figure below. :

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

#include <iostream>
void main()
{
int i,j,rows;
cout<<"Enter the number of rows: ";
cin>>rows;
for(i=1;i<=rows;++i)
{
for(j=1;j<=i;++j)
{
cout<<j<<" ";
}
cout<<"\n";
}
getch();
}

































WAP to input a character & print whether it is an alphabet,digit or any other character.:

ANS:
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
#include<stdio.h>

void main()
{
char ch;
cout<<"Enter any character :";
ch=getchar();
if(isalpha(ch))
cout<<"Alphabet";
else if(isdigit(ch))
cout<<"Number";
else
cout<<"Special Character";
getch();

}

WAP to print the sum of first n even no. .:
ANS:
#include <iostream.h>
#include <conio.h>
void main ()
{
clrscr ();
int i,n,sum=0;
cout<<"Enter the limit\n";
cin>>n;
for (i=2;i<=n;i=i+2)
{
sum=sum+i;
}
cout<<"The sum of first "<<n<<" even numbers is "<<sum;
getch ();
}



WAP to print the sum of first n odd no. .:
ANS:
#include <iostream.h>
#include <conio.h>
void main ()
{
clrscr ();
int i,n,sum=0;
cout<<"Enter the limit\n";
cin>>n;
for (i=1;i<=n;i=i+2)
{
sum=sum+i;
}
cout<<"The sum of first "<<n<<" odd numbers is "<<sum;
getch ();
}

WAP to swap the values of two variables using call by reference method.:
ANS:
#include<iostream.h>
#include<conio.h>
void swap (int &a, int &b)
{
/* &a and &b are reference variables */
int temp;
temp=a;
a=b;
b=temp;
}

void main()
{
clrscr();
int i=5,j=10;
cout<<"Before swapping I = "<<i<<" J = "<<j<<endl;
swap(i,j);
cout<<"After swapping I = "<<i<<" J = "<<j<<endl;
getch();
}


WAP to print transpose of a matrix.:
ANS:

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[10][10],m,n,i,j;
cout<<"Enter number of rows: ";
cin>>m;
cout<<"Enter number of coloumns: ";
cin>>n;
if(m!=n)
{cout<<"Matrix not square so Transpose not possible :(";}
else
{cout<<endl<<"Enter elements of matrix: "<<endl;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{cout<<"Enter element a"<<i+1<<j+1<<": ";
cin>>a[i][j];}}
cout<<endl<<"Displaying Matrix: "<<endl<<endl;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{cout<<a[i][j]<<" ";}
cout<<endl<<endl;}
cout<<endl<<"Displaying Matrix Transpose: "<<endl<<endl;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cout<<a[j][i]<<" ";
}
cout<<endl<<endl;
}
}
getch();
}

WAP to print sum of diagonal elements of a Matrix.:

ANS:

#include<iostream.h>
#include<conio.h>
void main()
{
int a[10][10],*p[10];
int m,n,i,j,s1=0,s2=0,t;
cout<<"Enter the order of matrics: ";
cin>>m>>n;
cout<<"Enter the elements\n\n";
for(i=0;i<m;i++)
{
p[i]=&a[i][0];
for(j=0;j<n;j++)
{
cin>>a[i][j];
}
}
cout<<"\n\nFirst diagonal elements are\n\n";
for(i=0;i<n;i++)
{
cout<<*(p[i]+i)<<"\t";
s1=s1+*(p[i]+i);
}
cout<<"\n\nSecond diagonal elements are\n\n";
t=n;
for(i=0;i<n;i++)
{
cout<<*(p[t-1]+i)<<"\t";
s2=s2+*(p[t-1]+i);
t--;
}
cout<<"\n\nSum of first diagonal elements is: ";
cout<<s1;
cout<<"\n\nSum of second diagonal elements is: ";
cout<<s2;
getch();}

Você também pode gostar