arrow
arrow

loops

Number between 1 and 100


                            
                                #include<iostream>
                                    using namespace std;
                                    int main()
                                    {
                                        int num_1;
                                        while(num1!=101)
                                        {
                                            cout<<num1<<" "<<endl;
                                            num1++;
                                        }
                                        return 0;

                                    }
                                    
                            
                        

Make a program that asks for a test score between zero and ten. Show a message if the value is invalid and keep asking until the user enters a valid value


                        
                            // task-01
                            #include <iostream>
                            using namespace std;
                            int main()
                            {
                                int input;
                                cout << "Enter the test score between 1 and 10:" << endl;
                                cin >> input;
                                while (input < 0 || input > 10)
                                {
                                    cout << "INVALID INPUT:!" << endl;
                                    cout << "Again Enter the test score between 1 nd 10: " << endl;
                                    cin >> input;
                                }
                            
                                return 0;
                            }
                        
                    

Square


                        
                            #include <iostream>
                                using namespace std;
                                int main()
                                {
                                    cout << "How many stars to print: as square ";
                                    int howMany;
                                    cin >> howMany;
                                    cout << "Following are " << howMany << " stars" << endl;
                                    int i=1;
                                    while(i<=howMany)
                                    {
                                        int j=1;
                                        while(j<=howMany)
                                        {
                                            cout<<"*";
                                            j++;
                                        }
                                        cout<<endl;
                                    i++;
                                    }
                                    cout << endl;
                                
                                    return 0;
                                }
                                                                
                        
                    

Right triangle


                        
                            _________________________________________________________________
                            How many stars to print: as a triangle 7
                           Following are 7 stars
                           *
                           **
                           ***
                           ****
                           *****
                           ******
                           *******       
                            #include <iostream>
                                using namespace std;
                                int main()
                                {
                                    cout << "How many stars to print: as a triangle ";
                                    int howMany;
                                    cin >> howMany;
                                    cout << "Following are " << howMany << " stars" << endl;
                                    int i=1;
                                    while(i<=howMany)
                                    {
                                        int j=1;
                                        while(j<=i)
                                        {
                                            cout<<"*";
                                            j++;
                                        }
                                        cout<<endl;
                                    i++;
                                    }
                                    cout << endl;
                                
                                    return 0;
                                }
                                
                      output as:
                      ___________________________________________________________________
                      Shadow of revtangle:
                      How many stars to print: as a triangle 6
                      Following are 6 stars
                      ******
                      *****
                      ****
                      ***
                      **
                      *
                      #include <iostream>
                          using namespace std;
                          int main()
                          {
                              cout << "How many stars to print: as a triangle ";
                              int howMany;
                              cin >> howMany;
                              cout << "Following are " << howMany << " stars" << endl;
                              int i = howMany;
                              while (i >= 1)
                              {
                                  int j = 1;
                                  while (j <= i)
                                  {
                                      cout << "*";
                                      j++;
                                  }
                                  cout << endl;
                                  i--;
                              }
                              cout << endl;
                          
                              return 0;
                          }
                      ___________________________________________________________________________
                      Horizontal Image of triangle
                      How many stars to print: as a triangle 7
                      Following are 7 stars
                      *******
                       ******
                        *****
                         ****
                          ***
                           **
                            *
                            #include <iostream>
                              using namespace std;
                              int main()
                              {
                                  cout << "How many stars to print: as a triangle ";
                                  int howMany;
                                  cin >> howMany;
                                  cout << "Following are " << howMany << " stars" << endl;
                                  int i = 0;
                                  while (i < howMany)
                                  {
                                      int j = 1;
                                      while (j <= howMany)
                                      {
                                          if (j <= i)
                                          {
                                              cout << " ";
                                          }
                                          else
                                          {
                                              cout << "*";
                                          }
                                          j++;
                                      }
                                      cout << endl;
                                      i++;
                                  }
                                  cout << endl;
                              
                                  return 0;
                              }
                             ___________________________________________________________________________
                      


                        
                    

Pyramids


                        
                            Output as:
                            Enter a number :
                            7
                                   *
                                  ***
                                 *****
                                *******
                               *********
                              ***********
                             *************
                             _____________________________________________________
                             #include<iostream>
                                using namespace std;
                                int main()
                                {
                                    int n;
                                    cout<<"Enter a number :"<<endl;
                                    cin>>n;
                                    int i=0;
                                    while(i<n)
                                    {
                                        int j=0;
                                        while(j<=2*n)
                                    {
                                        if(j==n || (j>=(n-i) && j<=(n+i)))
                                        {
                                            cout<<"*";
                                        }
                                        else
                                        {
                                            cout<<" ";
                                        }
                                        j++;
                                    }
                                    cout<<endl;
                                        i++;
                                }    
                                    return 0;
                                }
                                
                        
                    

Write a program that takes multiple inputs from user until a user enter a negative number. When a negative number is pressed. Program should be terminated and the sum of all positive integars should be displayed to user.


                        
                            #include <iostream>
                                using namespace std;
                                int main()
                                {
                                    int num;
                                    int sum = 0;
                                    while (num >= 0)
                                    {
                                        cout << "Enter a number :" << endl;
                                        cin >> num;
                                        if (num >= 0)
                                        {
                                            sum = sum + num;
                                        }
                                    }
                                    cout << "The sum of all the above positive numbers = " << sum << endl;
                                
                                    return 0;
                                }
                        
                    

Write a program to add, subtract, multiply and divide using switch case.


                        
                            #include <iostream>
                                #include <conio.h>
                                using namespace std;
                                int main()
                                {
                                    double num1;
                                    double num2;
                                    double cal;
                                    cout << "_______________________________________" << endl;
                                    cout << "----------Simple Calculator------------" << endl;
                                    cout << "_______________________________________" << endl;
                                    cout << endl;
                                    cout << "Enter a number 1 :" << endl;
                                    cin >> num1;
                                    cout << "Enter a number 2 :" << endl;
                                    cin >> num2;
                                    cout << "Press + to add the enter Numbers :" << endl;
                                    cout << "Press - to subtract the enter Numbers :" << endl;
                                    cout << "Press * to Multiply the enter Numbers :" << endl;
                                    cout << "Press / to divide the enter Numbers :" << endl;
                                    char ch = getch();
                                    switch (ch)
                                    {
                                    case '+':
                                    {
                                        cal = num1 + num2;
                                        cout << "The addition of the " << num1 << " and " << num2 << " = " << cal << endl;
                                        break;
                                    }
                                    case '-':
                                    {
                                        cal = num1 - num2;
                                        cout << "The subtarction of the " << num1 << " and " << num2 << " = " << cal << endl;
                                        break;
                                    }
                                    case '*':
                                    {
                                        cal = num1 * num2;
                                        cout << "The multiplication of the " << num1 << " and " << num2 << " = " << cal << endl;
                                        break;
                                    }
                                    case '/':
                                    {
                                        cal = num1 / num2;
                                        cout << "The division of the " << num1 << " and " << num2 << " = " << cal << endl;
                                        break;
                                    }
                                    }
                                
                                    return 0;
                                }
                        
                    

Write a program which counts number of vowels in a given string and tell every index where a vowel is found. You must have to perform this task using while loop and switch cases. (10 marks) Hint: Use String manipulations concepts here to get value from user and to initialize size.


                        
                            #include <iostream>
                                using namespace std;
                                int main()
                                {
                                    int size = 100;
                                    char ch[size];
                                    cout << "Enter the string :" << endl;
                                    cin.getline(ch, size);
                                    int n = 0;
                                    int i = 0;
                                    while (ch[i] != '\0')
                                    {
                                        switch (ch[i])
                                        {
                                        case 'a':
                                        {
                                            cout << "The vowel " << ch[i] << " is present at " << i << " index ." << endl;
                                            n++;
                                            break;
                                        }
                                        case 'e':
                                        {
                                            cout << "The vowel " << ch[i] << " is present at " << i << " index ." << endl;
                                            n++;
                                            break;
                                        }
                                        case 'i':
                                        {
                                            cout << "The vowel " << ch[i] << " is present at " << i << " index ." << endl;
                                            n++;
                                            break;
                                        }
                                        case 'o':
                                        {
                                            cout << "The vowel " << ch[i] << " is present at " << i << " index ." << endl;
                                            n++;
                                            break;
                                        }
                                        case 'u':
                                        {
                                            cout << "The vowel " << ch[i] << " is present at " << i << " index ." << endl;
                                            n++;
                                            break;
                                        }
                                
                                        case 'A':
                                        {
                                            cout << "The vowel " << ch[i] << " is present at " << i << " index ." << endl;
                                            n++;
                                            break;
                                        }
                                        case 'E':
                                        {
                                            cout << "The vowel " << ch[i] << " is present at " << i << " index ." << endl;
                                            n++;
                                            break;
                                        }
                                        case 'I':
                                        {
                                            cout << "The vowel " << ch[i] << " is present at " << i << " index ." << endl;
                                            n++;
                                            break;
                                        }
                                        case 'O':
                                        {
                                            cout << "The vowel " << ch[i] << " is present at " << i << " index ." << endl;
                                            n++;
                                            break;
                                        }
                                        case 'U':
                                        {
                                            cout << "The vowel " << ch[i] << " is present at " << i << " index ." << endl;
                                            n++;
                                            break;
                                        }
                                        }
                                
                                        i++;
                                    }
                                    cout<<"The total vowels in the string \""<<ch<<"\" = "<<n<<endl;
                                
                                    return 0;
                                }      

                        
                    

TAble of 10


                        
                            #include <iostream>
                                using namespace std;
                                int main()
                                {
                                    int table;
                                    int n = 1;
                                    cout<<"Table of 10 "<<endl;
                                    while (n != 11)
                                    {
                                        table = 10 * n;
                                        cout << "10"
                                             << " * " << n << " = " << table << endl;
                                        n++;
                                    }
                                
                                    return 0;
                                }
                        
                    

For the Pyramid


                        
                            #include<iostream>
                                using namespace std;
                                int main()
                                {
                                   int num;
                                   cout<<"Enter a number:"<<endl;
                                   cin>>num;
                                   for(int i=0;i<num;i++){
                                       for(int j=1;j<(2*num);j++){
                                            if(j<=num+i && j>=num-i){
                                                cout<<"*";
                                            }
                                            else{
                                                cout<<" ";
                                            }
                                       }
                                       cout<<endl;
                                   }
                                
                                    return 0;
                                }
                                OUTPUT AS:
                                Enter a number:
                                10
                                *
                               ***        
                              *****       
                             *******      
                            *********     
                           ***********    
                          *************   
                         ***************  
                        ***************** 
                       *******************

                        
                    

DIMAOND


                        
                            #include<iostream>
                                using namespace std;
                                int main()
                                {
                                   int num;
                                   cout<<"Enter a number:"<<endl;
                                   cin>>num;
                                   for(int i=0;i<num;i++){
                                       for(int j=1;j<(2*num);j++){
                                            if(j<=num+i && j>=num-i){
                                                cout<<"*";
                                            }
                                            else{
                                                cout<<" ";
                                            }
                                       }
                                       cout<<endl;
                                   }
                                   
                                   for(int i=num-2;i>=0;i--){
                                       for(int j=1;j<(2*num);j++){
                                            if(j<=num+i && j>=num-i){
                                                cout<<"*";
                                            }
                                            else{
                                                cout<<" ";
                                            }
                                       }
                                       cout<<endl;
                                   }
                                
                                
                                    return 0;
                                }

                                OUTPUT AS:
                                Enter a number:
                                10
                                *
                               ***        
                              *****       
                             *******      
                            *********     
                           ***********    
                          *************   
                         ***************  
                        ***************** 
                       *******************
                        *****************
                         ***************
                          *************
                           ***********
                            *********
                             *******
                              *****       
                               ***
                                *
                        
                    

Hollow DIAMOND


                        
                            #include<iostream>
                                using namespace std;
                                int main()
                                {
                                
                                   int num;
                                   cout<<"Enter a number:"<<endl;
                                   cin>>num;
                                   for(int i=0;i<num;i++){
                                       for(int j=1;j<(2*num);j++){
                                            if(j==num+i || j==num-i){
                                                cout<<"*";
                                            }
                                            else{
                                                cout<<" ";
                                            }
                                       }
                                       cout<<endl;
                                   }
                                   for(int i=num-2;i>=0;i--){
                                       for(int j=1;j<(2*num);j++){
                                            if(j==num-i || j==num+i){
                                                cout<<"*";
                                            }
                                            else{
                                                cout<<" ";
                                            }
                                       }
                                       cout<<endl;
                                   }
                                    return 0;
                                }
                                Enter a number: 
                                10
                                *
                                * *        
                               *   *       
                              *     *      
                             *       *     
                            *         *    
                           *           *   
                          *             *  
                         *               * 
                        *                 *
                         *               * 
                          *             *
                           *           *
                            *         *
                             *       *
                              *     *
                               *   *
                                * *
                                 *
                        
                    

ARROW


                        
                            #include<iostream>
                                using namespace std;
                                int main()
                                {
                                   int num;
                                   cout<<"Enter a number:"<<endl;
                                   cin>>num;
                                   for(int i=0;i<num;i++){
                                       for(int j=1;j<(2*num);j++){
                                            if(j==num|| (j==num+i || j==num-i)){
                                                cout<<"*";
                                            }
                                            else{
                                                cout<<" ";
                                            }
                                       }
                                       cout<<endl;
                                   }
                                   for(int i=num-1;i>=0;i--){
                                       for(int j=1;j<(2*num);j++){
                                            if(j==num){
                                                cout<<"*";
                                            }
                                            else{
                                                cout<<" ";
                                            }
                                       }
                                       cout<<endl;
                                   }
                                    return 0;
                                }
                                Enter a number:
                                10
                                *
                               ***        
                              * * *       
                             *  *  *      
                            *   *   *     
                           *    *    *    
                          *     *     *   
                         *      *      *  
                        *       *       * 
                       *        *        *
                                *
                                *
                                *
                                *
                                *
                                *
                                *
                                *
                                *
                                *

                        
                    

PRINT PATTERN BE LIKE AS:


                        
                            Enter a number:
                            10
                            ********* *********
                            ********   ********
                            *******     *******
                            ******       ******
                            *****         *****
                            ****           ****
                            ***             ***
                            **               **
                            *                 *
                                                                  
                            *                 *
                            **               **
                            ***             ***
                            ****           ****
                            *****         *****
                            ******       ******
                            *******     *******
                            ********   ********
                            ********* *********


                            #include<iostream>
                                using namespace std;
                                int main()
                                {
                                   int num;
                                   cout<<"Enter a number:"<<endl;
                                   cin>>num;
                                   for(int i=0;i<num;i++){
                                       for(int j=1;j<(2*num);j++){
                                            if(j<=num+i && j>=num-i){
                                                cout<<" ";
                                            }
                                            else{
                                                cout<<"*";
                                            }
                                       }
                                       if(i==num-1){
                                           break;
                                       }
                                       cout<<endl;
                                   }
                                   for(int i=num-1;i>=0;i--){
                                       for(int j=1;j<(2*num);j++){
                                            if(j<=num+i && j>=num-i){
                                                cout<<" ";
                                            }
                                            else{
                                                cout<<"*";
                                            }
                                       }
                                       cout<<endl;
                                   }
                                    return 0;
                                }
                        
                    

HAlf DIAMOND


                        
                            #include <iostream>
                                using namespace std;
                                int main()
                                {
                                    int num;
                                    cout << "Enter the  number:" << endl;
                                    cin >> num;
                                    for (int i = 1; i <= num; i++)
                                    {
                                        for (int j = 0; j < i; j++)
                                        {
                                            cout << "*";
                                        }
                                        cout << endl;
                                    }
                                    for (int i = num - 1; i > 0; i--)
                                    {
                                        for (int j = 0; j < i; j++)
                                        {
                                            cout << "*";
                                        }
                                        cout << endl;
                                    }
                                
                                    return 0;
                                }

                                out put as:
                                Enter the  number:
                                10
                                *
                                **
                                ***
                                ****
                                *****
                                ******
                                *******
                                ********
                                *********
                                **********
                                *********
                                ********
                                *******
                                ******
                                *****
                                ****
                                ***
                                **
                                *

                        
                    

Computer Guess game


                        
                            #include <iostream>
                                #include <cstdlib>
                                #include <ctime>
                                using namespace std;
                                int main()
                                {
                                    int x = time(0);
                                    srand(x);
                                    int compGuess;
                                    int userGuess;
                                    bool flag = false;
                                    cout << "The computer Enter the number " << endl;
                                    cout << "Now you guess the number that computer enter" << endl;
                                    compGuess = (rand() % 10) + 1;
                                    // cout<<compGuess;
                                    cout << "You have only three trials" << endl;
                                    for (int i = 1; i <= 3; i++)
                                    {
                                        cout << i << " try:" << endl;
                                        cin >> userGuess;
                                        if (userGuess == compGuess)
                                        {
                                            flag = true;
                                            break;
                                        }
                                        else if ((compGuess - userGuess <= 2 && compGuess - userGuess >= 1) || (compGuess - userGuess >= -2 && compGuess - userGuess <= -1))
                                        {
                                            if (i <= 2)
                                            {
                                                cout << "You are very close to the number:" << endl;
                                            }
                                        }
                                        else
                                        {
                                            if (i <= 2)
                                            {
                                                cout << "You are not close to the number:" << endl;
                                            }
                                        }
                                    }
                                    if (flag == false)
                                    {
                                        cout << "You lose the game!" << endl;
                                        cout << "The number enter by the computer is equal to the " << compGuess << endl;
                                    }
                                    if (flag == true)
                                    {
                                        cout << "You win the game!" << endl;
                                        cout << "The number enter by the computer is equal to the " << compGuess << endl;
                                    }
                                
                                    return 0;
                                }
                        
                    

Whats make this website differents from others?

Amazing Feature That Increase your Productivity

If you don't find any problem,in this website and if you have a very difficult assignment question that is not present on internet ,then you dont bother yourself,we are here to solve every problem of your life you just click on the Problem asking button and write your problem we slove the code of your problem and sent you on your email addres that you put in the sin up form.