Skip to main content

Posts

Multiplication of ten numbers ( for loop )

          Multiplication of ten numbers ( for loop )     So here is the code given below how to use  for loop  in C++.  So here we go to the code. Just don't copy the code just go for its explanation given below the code. It may guide/help your for your learning and remembrance of the code. Multiplication of ten numbers #include<iostream.h> #include<conio.h> void main(){ clrscr(); int num, mul = 1, count = 0; for (count = 0; count < 10; count++){ cout<<"\n\t Enter number : "; cin>>num; mul = mul * num; } if (count == 10 ){ cout<<"\n\t Multiplication of 10 numbers : "<<mul; } getch(); } Explanation  of Code The header tags. #include<iostream.h>  #include<conio.h>  Then the  main()  function is declared. void main() clrscr();  is a function use to clear the output console screen. int  is use to initialize variables.  int num, mul = 1, count = 0; for loop  is use for continuation to chec

Sum of ten numbers ( for loop )

         Sum of ten numbers ( for loop )     So here is the code given below how to use  for loop  in C++.  So here we go to the code. Just don't copy the code just go for its explanation given below the code. It may guide/help your for your learning and remembrance of the code. Sum  of ten numbers #include<iostream.h> #include<conio.h> void main(){ clrscr(); int num, sum = 0, count = 0; for (count = 0; count < 10; count++){ cout<<"\n\t Enter number : "; cin>>num; sum = sum + num; } if (count == 10 ){ cout<<"\n\t Sum of 10 numbers : "<<sum; } getch(); } Explanation  of Code The header tags. #include<iostream.h>  #include<conio.h>  Then the  main()  function is declared. void main() clrscr();  is a function use to clear the output console screen. int  is use to initialize variables.  int num, sum = 0, count = 0; for loop  is use for continuation to check the conditions entered in loop

Fibonacci series using user input ( for loop )

      Fibonacci series using user input ( for loop )     So here is the code given below how to use  for loop  in C++.  So here we go to the code. Just don't copy the code just go for its explanation given below the code. It may guide/help your for your learning and remembrance of the code. Fibonacci series #include<iostream.h> #include<conio.h> void main(){ clrscr(); int prev, curr, next, num; cout<<"\n\t Enter previous number : "; cin>>prev; cout<<"\n\t Enter current number : "; cin>>curr; cout<<"\n\t Enter the count of elements : "; cin>>num; cout<<prev<<" "<<curr<<" "; for( int i = 2; i < num; i++ ){ next = prev + curr; cout<<next<<" "; prev = curr; curr = next; } getch(); } Explanation  of Code The header tags. #include<iostream.h>  #include<conio.h>  Then the  main()  function is decl

Fibonacci series ( for loop )

     Fibonacci series ( for loop )     So here is the code given below how to use for loop  in C++.  So here we go to the code. Just don't copy the code just go for its explanation given below the code. It may guide/help your for your learning and remembrance of the code. Fibonacci series #include<iostream.h> #include<conio.h> void main(){ clrscr(); int prev = 0, curr = 1, next, num; cout<<"Enter the number of elements : "; cin>>num; cout<<prev<<" "<<curr<<" "; for( int i = 2; i < num; i++ ){ next = prev + curr; cout<<next<<" "; prev = curr; curr = next; } getch(); } Explanation  of Code The header tags. #include<iostream.h>  #include<conio.h>  Then the  main()  function is declared. void main() clrscr();  is a function use to clear the output console screen. int  is use to initialize variables  prev, curr, next & num .  int prev = 0,

Greatest among three numbers ( else if )

    Greatest among three numbers ( else if )     So here is the code given below how to use  else if  conditions in C++.  So here we go to the code. Just don't copy the code just go for its explanation given below the code. It may guide/help your for your learning and remembrance of the code. Greatest among three numbers #include<iostream.h> #include<conio.h> void main(){ clrscr(); int a, b, c; cout<<"\n\t Enter number : "; cin>>a; cout<<"\n\t Enter number : "; cin>>b; cout<<"\n\t Enter number : "; cin>>c; if( a > b  && a > c){ cout<<"\n\t Greatest number is : "<<a; } else if( b > c && b > a ){ cout<<"\n\t Greatest number is : "<<b; } else { cout<<"\n\t Greatest number is : "<<c; } getch(); } Explanation  of Code The header tags. #include<iostream.h>  #include<conio.h

Smallest among three numbers ( else if )

   Smallest among three numbers ( else if )     So here is the code given below how to use  else if  conditions in C++.  So here we go to the code. Just don't copy the code just go for its explanation given below the code. It may guide/help your for your learning and remembrance of the code. Smallest among three numbers #include<iostream.h> #include<conio.h> void main(){ clrscr(); int a, b, c; cout<<"\n\t Enter number : "; cin>>a; cout<<"\n\t Enter number : "; cin>>b; cout<<"\n\t Enter number : "; cin>>c; if( a < b  && a < c){ cout<<"\n\t Smallest number is : "<<a; } else if( b < c && b < a ){ cout<<"\n\t Smallest number is : "<<b; } else { cout<<"\n\t Smallest number is : "<<c; } getch(); } Explanation  of Code The header tags. #include<iostream.h>  #include<conio.h&

Gender Male / Female / Other ( else if )

     Gender Male / Female / Other ( else if )     So here is the code given below how to use  if, else if , else   conditions in C++.  So here we go to the code. Just don't copy the code just go for its explanation given below the code. It may guide/help your for your learning and remembrance of the code. Gender Male / Female / Other #include<iostream.h> #include<conio.h> void main() {                    clrscr(); char gender;                       cout<<"\n\n\t M for male \n\t F for female \n\t Any letter for other";           cout<<"\n\n\t Enter gender : ";           cin>>gender;           if ( gender == 'M' || gender == 'm'){           cout<<"\n\t Male";           } else if ( gender == 'F' || gender == 'f'){           cout<<"\n\t Female";           } else {      cout<<"\n\t Other";           }      getch();             } Expl