3. 犖犖犖萎犖∇ if 犢犖犢犖犖о犖犖伍検犢犖犖犢犖犖犖÷犖ム厳犖犖犖犖橿犖犖巌犖犖迦牽犢犖犢犖犢犖犢犖犖犖迦犢犖犢犖犢犖犖犖迦犖犖犖謹犖犖犖萎見犖о犖迦犖犖迦犢犖ム厳犖犖犖犖犖犖犖迦 犢犖犖∇犖犢犖犖ム犖犖 < boolean expression> 犢犖犢犖犖犖園犖犖巌犢犖犢犖犖犖犖犖犢犖迦犖犖犖犖犖犖萎犖∇ 犢犖犖∇検犖朽牽犖項犢犖犖犖犖犖犖犖犖萎犖∇犖犖園犖犖朽 if statement if (<boolean expression>) <statement>; [ else <statement>; ]
4. #include<iostram.h> void main( ) { int n; cout<< Enter number :: >> ; cin>>n; if( n = = 0) cout<<Zero Number ; if( n > 0) cout<< Positive Number ; else cout<< Negative Number ; }
6. #include<iostream> using namespace std; void main(){ int x = 0; if ( 1 ) cout<<"print 1"<<endl; if ( !x ) cout<<"!x"<<endl; else cout<<"x"<<endl; }
14. #include<iostream.h> void main(){ int n0,n1,n2,n3,n4; int max,min; cout<<"Enter 5 numbers >> "; cin>>n0;cin>>n1;cin>>n2;cin>>n3;cin>>n4; max = n0;min =n0; //round 1 if (n1>max) max=n1; if (n1<min) min=n1; //round 2 if (n2>max) max=n2; if (n2<min) min=n2; //round 3 if (n3>max) max=n3; if (n3<min) min=n3; //round 4 if (n4>max) max=n4; if (n4<min) min=n4; // Print output cout<<"minimum number = "<<min<<endl; cout<<"maximum number = "<<max<<endl; }
15. #include<iostream.h> void main(){ int n[5]; int max,min,i; cout<<"==== Enter 5 numbers ====="<<endl; for (i=0;i<5;i++) { cout<<"Emter number "<<i+1<<" >> ";cin>>n[i];//first is n[0] Not n[1]; } max=n[0];min=n[0]; for (i=1;i<5;i++) { if (n[i]>max) max=n[i]; if (n[i]<min) min=n[i]; } // Print output cout<<"minimum number = "<<min<<endl; cout<<"maximum number = "<<max<<endl; }
16. For statement For ( init-expression ; cond-expression ; loop-expression ) #include<iostream.h> void main(){ int n[5]={1,2,3,4,5}; int max,min,i; for(i=1;i<=5;i++){ // i+=2 cout<<"Print i value "<<i<<endl; } }
17. int i; for ( i = 0; i < 5; cout<<i<<endl, i++); int i, j; for ( i = 5, j = 10 ; i + j < 20 ; i++, j++ ) cout<<" i + j = "<< (i+j) <<endl;
18. #include<iostream.h> void main(){ int n[5]={1,2,3,4,5}; int i; for (i=0;i<=4;i++) if (i >0) { cout<<n[i]<<endl; i +=2; cout<<"Hahaha 55555 Joke "<<endl; } else { for(int j=0;j<2;j++) cout<<" I am a rock"<<j<<endl; } cout<<"======================================="<<endl; }// 犖犖ム献犖園犖犢犖犖朽犢犖犢犖犖劇賢犖犖萎犖
20. #include<iostream.h> void main(){ int i,j,k; cout<<"Print value from 0 to 10,10 to 0 and -5 to 5 "<<endl; cout<<"i j k"<<endl; cout<<"---------------------"<<endl; for(i=0,j=10,k=-5;i<=10,j>=0,k<=5;i++,j--,k++){ // for(i=0,j=0,k=-5;i<=10;i++,j--,k++){ cout<<i<<""<<j<<""<<k; cout<<endl; } cout<<"---------------------"<<endl; }
23. while..do and dowhile #include <iostream.h> int main() { int odd = 0, even = 0,time=0, result; /* process 10 students; counter-controlled loop */ cout << "Enter Number 0 - 9 "<<endl; while (time < 10){ cout << "Number "<< ++time<<" >>" ; cin >> result; if (result%2 == 0) even ++; else odd++; } cout<<"Odd = "<<odd<<endl; cout<<"Even = "<<even<<endl; } while do 犖犖園犖犢犖 犖犖橿犖о犢犖犢犖 犖犖園犖犢犖犢 0 9 犖犖巌犖犖橿犖о 犢犖ム犖о見犖迦硯犢犖迦検犖 犖犖園硯犢犖ム犖犖項 犢犖ム鍵 犖犖朽 犖犖朽犖犖橿犖о while do
24. while..do and dowhile #include <iostream.h> int main() { int odd = 0, even = 0,time=0, result; cout << "Enter Number 0 - 9 "<<endl; do{cout << "Number "<< ++time<<" >>" ; cin >> result; if (result%2 == 0) even ++; else odd++; }while(time<10); cout<<"Odd = "<<odd<<endl; cout<<"Even = "<<even<<endl; } do..while 犖犖園犖犢犖 犖犖橿犖о犢犖犢犖 犖犖園犖犢犖犢 0 9 犖犖巌犖犖橿犖о 犢犖ム犖о見犖迦硯犢犖迦検犖 犖犖園硯犢犖ム犖犖項 犢犖ム鍵 犖犖朽 犖犖朽犖犖橿犖о ... dowhile
25. 犖犖迦犢犖 j k l 犖犖犖犖 犖÷元 犢犖ム鍵犢犖÷犖÷元犖犖橿肩犖園犖 break #include <iostream.h> int main() {int j,k,l; j=10;k=1;l=0; do{ if(j+k) cout<<"J1+K1 = "<<j+k<<endl; break; l++; j--; }while(k++<6); cout<<"j = "<<j<<" k = "<<k<<" l = "<<l<<endl; }
26. #include < iostream .h> float power3 (float); void main (void) { int i ; for (i=1; i <=10; i++) cout<< i<< <<power3 ( i ) ); } float power3 (float x ) { return x * x * x ; } 1 8 27 64 125 216 343 512 729 1000 Function
27. 1. 犖犖巌犖迦牽犖犖迦犖犖犢犖犖犖÷犢犖犢犖犖犖朽 #include <iostream . h> void main () { int i, j, n; cout << " Enter N = " ; cin >> n; i = n; while ( i >= 1 ) { j = 1; while ( j < i ) { cout << " " ; j ++ ; } while ( j < = n ) { cout << "*" ; j ++ ; } cout << " " ; i--; } } #include <iostream . h> void main () { int i, j, n; cout << " Enter N = " ; cin >> n; for ( i = n;i> = 1;i --) { for ( j = 1;j<i;j ++) cout << " " ; for ( j = i;j< = n;j ++) cout << "*" ; cout << " " ; } } 犢犖犖犖朽権犖犢犖犖朽権犖 犖犖迦牽犢犖犢 While 犢犖ム鍵 For loop
28. #include<iostream> using namespace std; int main() { char *buffer = "Any character stream"; int capa, lettera, nota; char c; capa = lettera = nota = 0; cout<<"Any character stream"; while ( c = *buffer++ ) // Walks buffer until NULL { switch ( c ) { case 'A': capa++; break; case 'a': lettera++; break; default: nota++; } } cout<<"Uppercase a: "<<capa<<"Lowercase a: "<<lettera<<"Not character a: "<<nota; cout<<"Total:"; cout<<(capa + lettera + nota)<<endl; } 犢犖犢犖犖園犖犖朽犖犖迦犖犖朽権犖犢犖犢犖犢犖犖犢犖犖犖÷犖ム犖о犖橿犖迦牽犖犖園犖о犖迦犖犢犖犢犖迦賢犖萎犖 犢犖ム犖о犖犖犖犖橿犖迦検犖о犖 犢犖犖犢犖犖犖÷犖朽犖犖橿犖迦犖犖∇犖迦犢犖犢犖犖朽権犖犖犖謹犖犖÷顕犢犖犖劇犖犖犖萎犖