-->

Loop related programs using while,do..while and 'for' with 'if' structure

contd..
with  'nested loop'
---------------------------------------------------------------------------------------------------------------------------------
q1)Write a program to display all prime numbers between 0 and 100.
                                                                                                                                            solution
q2)Write a program to display first 20 prime numbers between 0 and 500.
                                                                                                                                          solution
q3)Write a program to display all Armstrong numbers between 0 and 1000.
                                                                                                                   
               here we are taking Armstrong number with 3 digit. but more digit also can be taken
                                                                                                                                          solution
q3)Write a program to display first 5 Armstrong numbers between 0 and 1000.
                                                                                                                 
                      here we are taking Armstrong number with 3 digit. but more digit also can be taken
                                                                                                                                          solution
q4)Write a program to display following numeric pattern.
      12345
      1234
      123
      12
      1                                                                                                                                solution

q5)Write a program to display following numeric pattern.
      12345
        1234
          123
            12
              1                                                                                                                       solution 
q6)Write a program to display following numeric pattern.
      1
      12
      123
      1234
      12345                                                                                                                       solution

q7)Write a program to display following numeric pattern.
      11111
      2222
      333
      44
      5                                                                                                                              solution
q8)Write a program to display following numeric pattern.
      11111
      2222
      333
      44
      5                                                                                                                             solution
q9)Write a program to display following numeric pattern.
      5
      44
      333
      2222
      11111                                                                                                                     solution

q10))Write a program to display following numeric pattern.
              1 1 1 1 1
              2 2 2 2 2
              3 3 3 3 3
              4 4 4 4 4
                                                                                                                                    solution
q11)Write a program to display following numeric pattern.
              1 1 1 1 1
                2 2 2
                  3
                 
                                                                                                                                   solution
q12)Write a program to display following star pattern.
     a)         *
               **                                                                                                                solution
             ***
           ****
         *****  


b)
      * * * * *
      * * * *
      * * *
      * *
      * 
                                                                                                                                 solution

q13)Write a program to display following numeric pattern.
                   1
                 2 2
               3 3 3
              4 4 4 4
            5 5 5 5  5                                                                                                      solution
q14)Write a program to display following numeric pattern.
              1 2 3 4 5
              6 7 8 9 10
              11 12 13 14 15
                                                                                                                                 solution
q15)Write a program to display following numeric pattern.
               1 2 3 4 5
               2 4 6 8 10
               3 6 9 12 15
                                                                                                                               solution
q16)Write a program to display following star pattern.
              *
           *     *                                                                                                          solution
        *            *
     *                   *
  *                          *
                                                                                                                or           solution

q17)Write a program to display following star pattern.
              *
             *     *                                                                                                       solution
             *            *
             *                   *
             * * * * * * * * *                    

                                                                                         or                                 solution

q18)Write a program to display following star pattern.
              *
           *     *                                                                                                          solution
        *            *
     *                   *
    * ** * * * * * *                   

                                                                                                        or                  solution

q19)Write a program to display following star pattern.
              *
             *     *                                                                                                       solution
             *            *
             *                   *
             * * * * * * * * *                  
             * *
             *     *
             *         *
             *             *
             *                  *
             *  * * * * * * * *
             *
             *
             *
q20)Write a program to display following star pattern.
         * * * * * *
           * * * *
            * * *
             * *
              *
              *
            * *                                                                                                                     solution
           * * *
         * * * *
       * * * * *
q21) Write a program to get following numeric pattern.
0
01
012
0123                                                                                                                             solution
012
01
0

q22) WAP to display following.

A
AB
ABC
ABCD
ABCDE
                                                                                                                                    solution

q23) WAP to get following

ABCDE
ABCD
ABC
AB
A

                                                                                                                                    solution

q24)WAP to get following.

       +
       +
++++++++   
       +
       +
                                                                                                                                   solution

q25) WAP to get following.
1
121
12321
1234321
123454321
                                                                                                                                                 solution 26) WAP to get following
* * * * * 
* * * * *
* * * * * 
* * * * *                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 solution

27) WAP to get following
* * * * * 
      * * * * *
             * * * * * 
                      * * * * *     
                  * ****                                                                                            solution
                                                                                                                             
28)WAP to get following
                                     * * * * * 
                        * * * * *
                   * * * * * 
             * * * * * 
                                                                                                                      Solution


29)WAP to get following
                                     * * * * * 
                                    * * * * *
                                    * * * * * 
                                    * * * * *
                                   * * * * * * * * * * * * * * * * * 
                                                                   * * * * *
                                                                   * * * * * 
                                                               * * * * *
                                                                  * * * * *
                                                                                                                                                                                             solution
 30)WAP to get following
      * * * * *
             * * * * * 
                       * * * * *
                  * * * * * 
                       * * * * *
           * * * * *
  * * * * *
                                                                                                                       solution

31)WAP to get following.
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5

1 2 3 4 5

1 2 3 4 5



                                                                                                                                   solution

32)WAP to get following.



2 2 2 2 2 

0 0 0 0 0

2 2 2 2 2

0 0 0 0 0 

2 2 2 2 2



                                                                                                                                    solution

33)WAP to get following

          1 1 1 1 1

 0 0 0 0 0

1 1 1 1 1

0 0 0 0 0

         1 1 1 1 1 

                                                                                                                                  solution

34) WAp to get following.
          0 2 0 2 0
       0 2 0 2 0
       0 2 0 2 0
       0 2 0 2 0
       0 2 0 2 0
                                                                                                                                                                                                              solution 


35)WAp to get following.
      x x x x x
    x 0 0 0 x
    x 0 0 0 x
    x 0 0 0 x
    x x x x x
                                                                                                                                                                                         solution
36)WAP to get following.
     1 1 1 1 1
     1          1
     1          
     1           1
     1 1 1 1 1
                                                                                                                 solution
37)WAP to get following.
       1 0 1 0 1
       0 1 0 1 0
      1 0 1 0 1
      0 1 0 1 0
      1 0 1 0 1
                                                                                                                 solution
38)WAp to get following
11011
11011
00000
11011
11011
                                                                                                                 solution 
39)WAp to get following.
10001
01010
00100
01010
10001
                                                                                                                     solution
40)WAp to get following.
12345
23455
34555
45555
55555
                                                                                                                    solution
                       

 









Loop related programs using while,do..while and 'for' with 'if' structure

Here are collection of programs using loop. here,You have programs written in while,do..while and for loop separately. Some are done using all loops as a sample to make you understandable. Then programs preceded by them can be written in same manner.Some programs are with 'if structure' depending upon requirements by question.

Read them now.

you can use while,do..while and for loop

Q1) Write a program to print/display 1 to 10 natural numbers.
                                                                                                                     solution

Q2)   Write a program  to print/display 1 to n natural numbers.

                                                                                                                   solution

Q3) Write a program  to print/display all even numbers lying between 1 to n natural numbers.
                                                                                                                     solution

Q4) Write a program  to print/display all odd numbers lying between 1 and 100.
                                                                                                                     solution

Q5)   Write a program  to print/display 100 to 1 natural numbers.
                               
                                                                                                                       solution

Q6)Write a program  to input your name and address and to display them 40 times.
                                                                                                                     solution


Q7) Write a program to print/display 1,8,27... to 10th term.
                                                                                                                     solution
Q8) Write a program to print/display 2,4,6,8,10,12... to 15th term.
                                                                                                                     solution
q9)Write a program to display multiplication table of a number .
                                                                                                                     solution

q10)Write a program to print/display 1,6,11,16....nth term.
                                                                                                                     solution

q11)Write a program to print/display 1,111,1111,11111,.... to nth term.
                                                                                                                     solution
Q12)Write a program to get sum of 1 to 10 natural numbers.
                                                                                                                     solution
q13)Write a program  to get/sum of all even numbers lying between 1 to n natural numbers.
                                                                                                                     solution
q14)Write a program  to print/display all characters from a to z.
                                                                                                                     solution
q15)Write a program  to print/display all ascii values of letters from A to Z and a to z..
                                                                                                                     solution
Q16)Write a program to print/display 11111,1111,111,11,1 to nth term.
                                                                                                                     solution
Q17)Write a program to convert binary no. into decimal number system.
                                                                                                                     solution
Q18)Write a program to convert decimal number into binary.
                                                                                                                     solution
Q19)Write a program to convert decimal number into octal.
                                                                                                                     solution
Q20)Write a program to convert decimal number into Hexadecimal.
                                                                                                                     solution
q21)Write a program to convert hexadecimal number into decimal .
                                                                                                                     solution
q22)Write a program to convert octal no. into decimal number system.
                                                                                                                     solution
q23)Write a program to convert binary no. into octal number system.
                                                                                                                     solution
q24)Write a program to convert binary no. into hexadecimal number system.
                                                                                                                     solution
q25)Write a program to convert hexadecimal number into binary number system.
                                                                                                                     solution

q26)Write a program to get factorial value of a positive number
                 if number =5 then its factorial value=5x4x3x2x1=120
                                                                                                                     solution
q27)Write a program to print/display all factors of  number 'n'.
        e.g.    if n= 6 then factors are1,2,3,6.(all can divide it)
                                                                                                                    solution
q28)Write a program to print/display all perfect square numbers lying between 1 and 'n'.
        e.g.    if n= 20 then perfect squares are 1,4,9,16....
                                                                                                                    solution
q29)Write a program to print/display 1+1,1+2,1+3,1+4,1+5,....           to nth term.
                                                                                                                     solution
q30)Write a program to print/display 1+1/1,1+1/2,1+1/3,1+1/4,1+1/5,....           to nth term.
                                                                                                                     solution
q31)Write a program to test whether a number is prime or not.
                                                                                                                     solution
q32)Write a program to get sum of 1+1,1+2,1+3,1+4,1+5,....           to nth term.
                                                                                                                     solution
q33)Write a program to test whether a number is palindrome or not.
                                                                                                                     solution
                                                                                                                    solution
q34)Write a program to get series 0,1,1,2,3,5,8....15th term.
                      (it is called Fibonacci series)
                                                                                                                     solution
q35)Write a program to reverse a number.
                       123=321                                                                                solution

q36)Write a program to get sum of all digits present in a number.
                   e.g    123=3+2+1=6                                                                   solution
q37)Write a program to get/display digits which are in even position present in a number.
                   e.g    123=2                                                                               solution

q38)Write a program to get/display digits which are odd positioned in a number.
                   e.g    123=1 and 3                                                                      solution

q39)Write a program to get/display digits which are even in a number.
                   e.g    12345=2 and 4                                                                   solution
q40)Write a program to get/display digits which are odd  in a number.
                   e.g    12345=1 and 3 and 5                                                          solution
q41)Write a program to read age of any 100 persons and count the number of persons in the age group between 20 and 40.

                                                                                                                       solution

Q42)Write a program to get 0.9,0.99,0.999,0.9999.....nth terms.
                                                                                                                       solution

         

q43)Write a program to get sum of (2x3)/5+(4x5)/7+(6x7)/9+,....           to nth term.
                                                                                                                     solution

q44)Write a program to get sum of 12x1+23x3+34x5+..............................nth terms.
                                                                                                                    solution

q45)Write a program to get sum of 1+3/4+7/16+15/64..............................nth terms.
                                                                                                                    solution

q46)Write a program to get sum of x+ x2/2+x3/3+x4/4+.............................nth terms.
                                                                                                                    solution

q47)Write a program to count number of digits present in a number.
         e..g. in 453=3 digits                                                                           solution
   

continue with nested loop