My Visitors

Flag Counter

Wednesday 14 November 2012

Looping Structures

Q1.Write a program to display the following format using while loop:
      -------------
      a           b
      -------------
      1           5
      2           4
      3           3
      4           2
      5           1
     -------------


#include<iostream.h>
#include<conio.h>
void main()

{
 clrscr();

   int a=1,b=5;
   cout<<"----------\n";
   cout<<("a\tb\n");
   cout<<"----------\n";
   while(a<=5)
  {
  
    cout<<a<<"\t"<<b<<endl;
   a++;
   b--;
}
 cout<<"----------\n";

getch();

}


Q2. Write a program to display the following  format using while loop:
      ----------------
      num         sum
      ----------------
      1           1
      2           3
      3           6
      4           10
      5           15
      --------------



#include<iostream.h>
#include<conio.h>
void main()

{
 clrscr();

   int num=1,sum=0;
   cout<<"----------\n";
   cout<<("num\tsum\n");
   cout<<"----------\n";
   while(num<=5)
  {
  
    sum=sum+num;
  cout<<num<<"\t"<<sum<<"\n";
   num++;
}
 cout<<"----------\n";

getch();

}

Q3. Write a program that displays the sum of the following series using do-while loop.
1+1/4+1/8+......+1/100

#include<iostream.h>
#include<conio.h>
void main()

{
  clrscr();

   float c,r;
   c=4.0;
   r=1.0;
   do
{
    r=r+1.0/c;
    c=c+4;
}
   while(c<=100);
   cout<<"Result is "<<r;

getch();

}


Q4.Write a program to display alphabets from A to Z using for loop...

#include<iostream.h>
#include<conio.h>
void main()
{
 clrscr();

     char ch;
     for(ch='A';ch<='Z';ch++)
      cout<<ch;

getch();

}






13 comments:

  1. Hello Bro Please Kindly Upload Other Looping Structure Program

    ReplyDelete
  2. Replies
    1. ya program mja b send kr da agr ap k pass abi save h to

      Delete
  3. Kindly Upload Other Looping Structure Program

    ReplyDelete
    Replies
    1. if you got others programs then plz send me

      Delete
  4. piease kindly other looping structure upload

    ReplyDelete
  5. plz upload full exercise

    ReplyDelete
  6. i want full 52 questions pls

    ReplyDelete
    Replies
    1. sir i also want if you have kindly send me

      Delete
  7. sir plz send ful ex program plz

    ReplyDelete
  8. i need first 15 programs plz send me

    ReplyDelete
  9. I need while loop program of exercise

    ReplyDelete