Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

PLS EXPLAIN THIS PROGRAM

0 votes
asked May 17, 2018 by Mahmud Muhammad (230 points)
#include <iostream>
using namespace std;

int main()
{
    int number;

    cout << "Enter a number: ";

    cin >> number;

    while(number >= 1)
    {
        cout << number << " ";
        number--;
    }

    
    return 0;
}

1 Answer

0 votes
answered May 17, 2018 by muha
#include <iostream> //including the iostream library
using namespace std;    //using namespace so you dont have to type std:: e.g. std::cout<<

int main()      //main function starts here
{
    //this is where all your code goes
    
    int number;     //creating a variable number with the type integer

    cout << "Enter a number: ";     //this is outputting text to the console window

    cin >> number;                  //this gives number the value that is typed in to the console by the user

    while(number >= 1)              //while loop that checks if number is bigger than 1 if its true than the following thing will be done
    {
        cout << number << " ";      //this line is outputting the value of number and " "
        number--;                   //the value of number gets decremented by 1 until number reaches 0 than the loop-statement is false and the program ends
    }           

    
    return 0;                       
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...