int a=10, b=20; if( a < b ){
cout<<"a is less than b";
}
Output :#include <iostream.h> using namespace std; int main(){ int a=10, b=20; if (a < b) { cout<<"a is less than b"; } return 0; }
a is less than b
int a=10, b=20; if( a == b ){ cout<<"a is equal to b"; }else{ cout<<"a is not equal to b"; }
Output :#include <iostream.h> using namespace std; int main(){ int a=10, b=20; if( a == b ){ cout<<"a is equal to b"; }else{ cout<<"a is not equal to b"; } return 0; }
a is not equal to b
int a=10, b=20; if( a < b ){ cout<<"a is less than b"; }else if( a > b ){ cout<<"a is greater than b"; }else{ cout<<"a is equal to b"; }
Output :#include <iostream.h> using namespace std; int main(){ int a=10, b=20; if( a < b ){ cout<<"a is less than b"; }else if( a > b ){ cout<<"a is greater than b"; }else{ cout<<"a is equal to b"; } return 0; }
a is less than b
Output :#include <iostream.h> using namespace std; int main(){ char Day='D'; switch(Day){ case 'A' : cout<<"Today is Sunday"; break; case 'B' : cout<<"Today is Monday"; break; case 'C' : cout<<"Today is Tuesday"; break; case 'D' : case 'E' : cout<<"Today is Wednesday"; break; case 'F' : cout<<"Today is Thurday"; break; case 'G' : cout<<"Today is Friday"; break; case 'H' : cout<<"Today is Saturday"; break; default : cout<<"Day is Not Found"; } return 0; }
Today is Wednesday
Output :#include <iostream.h> using namespace std; int main() { int i=0; while ( i < 20 ){ cout<<"value of i is "<<i; i++; if ( i == 10) break; } return 0; }
value of i is 0 value of i is 1 value of i is 2 value of i is 3 value of i is 4 value of i is 5 value of i is 6 value of i is 7 value of i is 8 value of i is 9
Output :#include <iostream.h> using namespace std; int main(){ int i; for(i=0;i<10;i++){ if(i==7){ cout<<"Number %d is skipped."<<i; continue; } cout<<i<<endl; } return 0; }
0 1 2 3 4 5 6 Number 7 is skipped. 8 9
जब goto statement कुछ statement को छोड़कर उसके अगले statement को execute करता है , उसे Forward goto statement कहते है और किसी पिछले या execute हुए statement को फिरसे execute करने के लिए अपने पिछले label पर जाता है , उसे Backward goto statement कहते है |
Output :#include <iostream.h> using namespace std; int main(){ int num1, num2, num3; char ch; yes : cout<<"Enter two values"<<endl; cin>>num1>>num2; num3 = num1 + num2 ; cout<<"Addition of "<<num1<<" and "<<num2<<" is "<<num3; cout<<"\nDo you want to continue y(yes) or n(No)"; cin>>ch; if(ch=='y'){ goto yes; } else if(ch=='n'){ goto no; } else{ cout<<"You entered other key"; } no : cout<<"Do you want to exit ?, Press Enter"; return 0; }
Enter two values 4 5 Addition of 4 and 5 is 9 Do you want to continue y(yes) or n(No)y Enter two values 6 4 Addition of 6 and 4 is 10 Do you want to continue y(yes) or n(No)n Do you want to exit ?, Press Enter