C Language Nested Loops Set 4

Get the following Output:

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

Source Code:

19. Using For Loop

#include <stdio.h>
 int main()
 {
     int i,j;
     for(i=1;i<=5;i=i+1)
     {
         for(j=1;j<=i;j++)
         {
             printf("%d ",j);
         }
         printf("\n");
     }
 return 0;
 }

Source Code:

20. Using While Loop

 /* using while loop */

 #include <stdio.h>
 int main()
 {
     int i=1,j;
     while(i<=5)
     {
         j=1;
         while(j<=i)
         {
             printf("%d ",j);
             j++;
         }
         printf("\n");
         i++;
     }
     return 0;
 }

Get the following Output:

2
2 4
2 4 6
2 4 6 8
2 4 6 8 10

Source Code:

21. Using For Loop

#include <stdio.h>
 int main()
 {
     int i,j;
     for(i=1;i<=5;i=i+1)
     {
         for(j=1;j<=i;j++)
         {
             printf("%d ",j*2);
         }
         printf("\n");
     }
 return 0;
 }

Source Code:

22. Using While Loop

 /* using while loop */

 #include <stdio.h>
 int main()
 {
     int i=1,j;
     while(i<=5)
     {
         j=1;
         while(j<=i)
         {
             printf("%d ",j*2);
             j++;
         }
         printf("\n");
         i++;
     }
     return 0;
 }

Get the following Output:

1
1 3
1 3 5
1 3 5 7
1 3 5 7 9

Source Code:

23. Using For Loop

#include <stdio.h>
 int main()
 {
     int i,j;
     for(i=1;i<=5;i=i+1)
     {
         for(j=1;j<=i;j++)
         {
             printf("%d ",j*2-1);
         }
         printf("\n");
     }
 return 0;
 }

Source Code:

24. Using While Loop

 /* using while loop */

 #include <stdio.h>
 int main()
 {
     int i=1,j;
     while(i<=5)
     {
         j=1;
         while(j<=i)
         {
             printf("%d ",j*2-1);
             j++;
         }
         printf("\n");
         i++;
     }
     return 0;
 }

C Language Programming Tutorial

C Language Tutorial Home    Introduction to C Language     Tokens     If Condition     goto statement and Labelname     Switch Statements     For loop     While Loop    Do while loop     break and continue    Functions    Recursion    Inbuild Functions    Storage Classes    Preprocessor    Arrays    Pointers     Structures and Unions    File Handling     Projects