You are on page 1of 7

/*WAP input 2 numbers from the user find the greater number using conditional operator*/

#include<iostream>

using namespace std;

int main()

int num1,num2,num3;

cout<<"Enter the 2 numbers\n";

cin>>num1>>num2;

num3=(num1>num2)?num1:num2;

cout<<num3<<" is greater";

return 0;

/*WAP input 3 numbers from the user find the greater number using conditional operator*/

#include<iostream>

using namespace std;

int main()

int num1,num2,num3,num4;

cout<<"Enter the 3 numbers\n";

cin>>num1>>num2>>num3;

num4=(num1>num2)?(num1>num3)?num1:num3:(num2>num3)?num2:num3;

cout<<num4<<" is greatest";

return 0;

//(condition)?a:b;

/*WAP to input the grade from user and based on that give the description
E-EXCELLENT

V- VERY GOOD

A-AVERAGE

F-FAIL */

#include<iostream>

using namespace std;

int main()

char choice;

kavan:

cout<<"Enter the grade\n";

cin>>choice;

switch(choice)

case 'E':

case 'e':

cout<<"EXCELLENT";

break;

case 'v':

case 'V':cout<<"VERY GOOD";

break;

case 'a':

case 'A':cout<<"AVERAGE";

break;

case 'f':

case 'F':cout<<"FAIL";

break;

default:cout<<"Invalid input\n";

goto kavan;

}
}

/*WAP TO CALCULATE AREA OF A GEOMETRIC SHAPE AS PER THE INPUT GIVEN BY THE USER*/

#include<iostream>

using namespace std;

int main()

int option;

start:

cout<<"for area of circle enter 1 for traingle enter 2 and for rectangle enter 3\n";

cin>>option;

float radius,base,height,length,breadth,area;

switch(option)

case 1:

cout<<"Enter the radius of the circle\n";

cin>>radius;

area=3.14*radius*radius;

cout<<"The area of the circle is "<<area;

break;

case 2:cout<<"ENTER THE BASE OF TRIANGLE\n";

cin>>base;

cout<<"ENTER THE height OF TRIANGLE\n";

cin>>height;

area=0.5*base*height;

cout<<"the area of the TRIANGLE is "<<area;

break;

case 3:cout<<"ENTER THE length OF rectangle\n";

cin>>length;
cout<<"ENTER THE breadth OF rectangle\n";

cin>>breadth;

area=length*breadth;

cout<<"The area of the rectangle is "<<area;

break;

default:cout<<"Invalid input"<<endl;

goto start;

break;

/*WAP to print numbers till 50 if user enters an odd number print odd numbers till 50 else print
even numbers till 50 */

#include<iostream>

using namespace std;

int main()

int num;

cout<<"ENTER THE STARTING NUMBER\n";

cin>>num;

for(int i=num;i<=50;i=i+2)

cout<<i<<endl;

/*WAP to print the sum of 1st 10 natural numbers */

#include<iostream>
using namespace std;

int main()

int sum=0;int i;

for(i=1;i<=10;i++)

sum=sum+i;

cout<<"The sum of 1st "<<i-1<<" numbers is "<<sum;

While syntax:

int main()

initialisation;

while(condition)

iteration;

/*WAP to print 1st n numbers using do while*/

#include<iostream>

using namespace std;


int main()

int n;

cout<<"Enter the value of n\n";

cin>>n;

cout<<endl;

int i=1;

do

cout<<i<<endl;

i++;

while(i<=n);

return 0;

/*WAP to input marks using arrays and find the total marks and the average*/

#include<iostream>

using namespace std;

int main()

float sum,average;

int n;

cout<<"Enter the number of subjects\n";

cin>>n;

int marks[n];
for(int i=0;i<n;i++)

cout<<"ENTER THE MARKS OUT OF 100 OF SUBJECT "<<i+1<<":";

cin>>marks[i];

cout<<endl;

sum=0;

for(int i=0;i<n;i++)

sum=sum+marks[i];

average=sum/n;

cout<<"The total marks scored is "<<sum<<" and the average marks is "<<average;

You might also like