Saturday, 17 March 2012

Conditions






CONDITIONAL STATEMENTS


                           Here i will tell you how you apply the conditions in the c++ code. it is very much simple by applying the conditions you will perform your desired task. please at the code for understanding.





WRITE A PROGRAME THAT TAKES NUMBER FROM USER AND TELLS EITHER IT IS GREATER THAN 10 OR NOT

CODE for C++

#include<iostream.h>  // library

void main() // main function

{

int x;    // integer

cout<<"enter number"; // for display

cin>>x; // store data which is given by user

if(x>10) // condition

cout<<"number is greater than 10";

else    // condition

cout<<"number is smaller than or equal to 10"<<endl; // result

}


OUTPUT



WRITE A PROGRAMME THAT CHECKS EITHER NUMBER IS GREATER,LESS AOR EQUAL TO 10



CODE for C++


#include<iostream.h>

void main()

{

int x;

cout<<"enter number";

cin>>x;

if(x>10)   // condition

cout<<"number is greater than 10";

if(x<10) // condition

cout<<"number is less than 10";

if(x==10) // condition

cout<<"number is equal to 10";

}




OUTPUT








MULTIPLE CONDITIONS IN IF

WRITE A PROGRAMME THAT COMPUTES THE GRADE FOR STUDENT


CODE for C++

#include<iostream.h>

void main()

{

int x;

cout<<"enter MARKS";

cin>>x;

if(x>90)  // condition

cout<<"grade is A+"<<endl;

else if(x>80 && x<90)  // condition

cout<<"grade is A"<<endl;

else if(x>70 && x<80)  // condition

cout<<"grade is B"<<endl;

else if(x<50)   // condition

cout<<"student is fail"<<endl;

}

 




OUTPUT







WRITE A PROGRAMME THAT CHECK THAT EITHER THE NUMBER IS EVEN OR ODD



CODE for C++

#include<iostream.h>

#include<conio.h>

void main()

{

int num;

cout<<"ENTER THE NUMBER\n";

cin>>num;

if(num%2==0)

{

cout<<"number is even"<<endl;

}

else

{

cout<<"number is odd"<<endl;

}

}



OUTPUT






WRITE A PROGRAMME FOR CALCULATOR USING ELSE IF STATEMENT



CODE for C++

#include<iostream.h>

#include<conio.h>

void main()

{

int a=0;

int num1,num2;

cout<<"enter first number\n";

cin>>num1;

cout<<"enter second number\n";

cin>>num2;

char select;

cout<<"select the operation\n";

do

{

cin >>select;

int sum,mul,sub;

float div;

if(select=='+')

{

sum=num1+num2;

cout<<"sum is = "<<sum;

}



else if(select=='-')

{

sub=num1-num2;

cout<<"subtraction result is= "<<sub;

}

else if(select=='*')

{

mul=num1*num2;

cout<<"multiplication result is ="<<mul;

}

else if(select=='/')

{

if(num2!=0)

{

div=num1/num2;

cout<<"division result is = "<<div;

}

else

cout<<"eneter number 2 except than 0";

}

else

cout<<"eneter correct operator";

a=1;

}

while(a==1);

}






OUTPUT




0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Bluehost Review