Menu Close

In-C-What-is-the-sections-doing-and-What-is-the-output-from-the-sections-below-a-int-p-o-for-int-i-1-i-lt-30-i-if-i-5-0-p-i-cout-lt-lt-p-lt-lt




Question Number 85222 by Umar last updated on 20/Mar/20
In C++  What is the sections doing ? and  What is the output from the sections   below ?  a. int p=o;       for (int i=1; i<=30; i++){       if (i%5==0)        p+=i;           }         cout<<p<<endl;      b.  int count=2;        int g=0;        while (count<=50){        g=count;        cout<<g<<endl;        count +=2;         }         cout<<count<<endl;
InC++Whatisthesectionsdoing?andWhatistheoutputfromthesectionsbelow?a.intp=o;for(inti=1;i<=30;i++){if(i%5==0)p+=i;}cout<<p<<endl;b.intcount=2;intg=0;while(count<=50){g=count;cout<<g<<endl;count+=2;}cout<<count<<endl;
Commented by Umar last updated on 20/Mar/20
please help
pleasehelp
Commented by mr W last updated on 20/Mar/20
a.  typo here:  int p=0;    it is to calculate the sum of all  integers from 1 to 30 which are   divisible by 5.  output is p=105    b.  it is just to display the even integers  from 2 to 50, i.e. 2,4,6,...,50.
a.typohere:intp=0;itistocalculatethesumofallintegersfrom1to30whicharedivisibleby5.outputisp=105b.itisjusttodisplaytheevenintegersfrom2to50,i.e.2,4,6,,50.
Commented by Umar last updated on 20/Mar/20
thank you so much sir.
thankyousomuchsir.

Leave a Reply

Your email address will not be published. Required fields are marked *