Computer Science, asked by pvnanditha9, 1 day ago

how to write the c++ programme of these questions ? ( Programme of while loop ) ​

Attachments:

Answers

Answered by samarthkrv
1

Answer:

1)

#include <iostream>

int main() {

   int i = 0 , sum = 0;

       while(i < 100 && i!= 200){

           if(i%2 == 1){

               sum = sum + i;

           }

           i++;

       }

   std::cout<<"The sum of odd numbers from 100 to 200 is " <<sum;

   return 0;

}

2)

#include <iostream>

int main() {

   int n;

   std::cout<<"Enter the limit of natural numbers for finding the average:";

   std::cin>>n;

   int total = 0 , i = 1;

   double average;

       while(i <= n){

           total = total + i;

           i++;

       }

   average = (double)(total/n);

   std::cout<<"The average of the first "<<n<<" numbers is "<<average;

   return 0;

}

Explanation:

Similar questions