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;
$$\mathrm{In}\:\mathrm{C}++ \\ $$$$\mathrm{What}\:\mathrm{is}\:\mathrm{the}\:\mathrm{sections}\:\mathrm{doing}\:?\:\mathrm{and} \\ $$$$\mathrm{What}\:\mathrm{is}\:\mathrm{the}\:\mathrm{output}\:\mathrm{from}\:\mathrm{the}\:\mathrm{sections}\: \\ $$$$\mathrm{below}\:? \\ $$$$\mathrm{a}.\:\mathrm{int}\:\mathrm{p}=\mathrm{o}; \\ $$$$\:\:\:\:\:\mathrm{for}\:\left(\mathrm{int}\:\mathrm{i}=\mathrm{1};\:\mathrm{i}<=\mathrm{30};\:\mathrm{i}++\right)\left\{\right. \\ $$$$\:\:\:\:\:\mathrm{if}\:\left(\mathrm{i\%5}==\mathrm{0}\right) \\ $$$$\:\:\:\:\:\:\mathrm{p}+=\mathrm{i};\:\: \\ $$$$\left.\:\:\:\:\:\:\:\right\} \\ $$$$\:\:\:\:\:\:\:\mathrm{cout}<<\mathrm{p}<<\mathrm{endl}; \\ $$$$ \\ $$$$ \\ $$$$\mathrm{b}.\:\:\mathrm{int}\:\mathrm{count}=\mathrm{2}; \\ $$$$\:\:\:\:\:\:\mathrm{int}\:\mathrm{g}=\mathrm{0}; \\ $$$$\:\:\:\:\:\:\mathrm{while}\:\left(\mathrm{count}<=\mathrm{50}\right)\left\{\right. \\ $$$$\:\:\:\:\:\:\mathrm{g}=\mathrm{count}; \\ $$$$\:\:\:\:\:\:\mathrm{cout}<<\mathrm{g}<<\mathrm{endl}; \\ $$$$\:\:\:\:\:\:\mathrm{count}\:+=\mathrm{2}; \\ $$$$\left.\:\:\:\:\:\:\:\right\} \\ $$$$\:\:\:\:\:\:\:\mathrm{cout}<<\mathrm{count}<<\mathrm{endl}; \\ $$
Commented by Umar last updated on 20/Mar/20
please help
$$\mathrm{please}\:\mathrm{help} \\ $$
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}. \\ $$$${typo}\:{here}: \\ $$$$\mathrm{int}\:\mathrm{p}=\mathrm{0}; \\ $$$$ \\ $$$${it}\:{is}\:{to}\:{calculate}\:{the}\:{sum}\:{of}\:{all} \\ $$$${integers}\:{from}\:\mathrm{1}\:{to}\:\mathrm{30}\:{which}\:{are}\: \\ $$$${divisible}\:{by}\:\mathrm{5}. \\ $$$${output}\:{is}\:{p}=\mathrm{105} \\ $$$$ \\ $$$${b}. \\ $$$${it}\:{is}\:{just}\:{to}\:{display}\:{the}\:{even}\:{integers} \\ $$$${from}\:\mathrm{2}\:{to}\:\mathrm{50},\:{i}.{e}.\:\mathrm{2},\mathrm{4},\mathrm{6},…,\mathrm{50}. \\ $$
Commented by Umar last updated on 20/Mar/20
thank you so much sir.
$$\mathrm{thank}\:\mathrm{you}\:\mathrm{so}\:\mathrm{much}\:\mathrm{sir}. \\ $$

Leave a Reply

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