assignment6_classXI

ASSIGNMENT6

(FOR LOOP,WHILE LOOP)  


QUESTIONS AND ANSWERS

Example:
Program to display numbers from 1 to 10 using for...loop.
void main()
{
    int x;
    for(x=1;x<=10;x++)
    {
       cout<<x;
   }
}
Program to display numbers from 1 to 10 using while...loop.
void main()
{
    int x;
    x=1;
    while(x<=10)
    {
       cout<<x; 

       x++;
     }
}

Q1. Program to display the sum of number from 1 to 10.
Example:
Step 1: declare two variable sum initialize with 0 and x for loop from 1 to 10.
Step 2: start the for loop from 1 to 10
Step 3: inside the for loop initialize the sum after adding the value of x;
Step 4: loop ends
Step 5: display the sum

Q2. Program to display the sum of odd numbers from 1 to 20.
Q3. Program to display the sum of evensum and oddsum from the given range of numbers starts from 5 to 30.
Q4. Program to display the sum of number which are divisible from 5 and 3 from the given range of number starts from 15 to 35.
Q5. Program to display all the leap years between 1900 to 2000.

Followers

Popular Posts

Recent Posts