Get the following Output:
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
Source Code:
1. Using For Loop
/* Using for loop */
#include <stdio.h>
int main()
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=5;j++)
{
printf("%d ",j);
}
printf("\n");
}
return 0;
}
2. Using while Loop
/* using while loop */
#include <stdio.h>
int main()
{
int i=1,j;
while(i<=5)
{
j=1;
while(j<=5)
{
printf("%d ",j);
j++;
}
printf("\n");
i++;
}
return 0;
}
Get the following Output:
2 4 6 8 10
2 4 6 8 10
2 4 6 8 10
2 4 6 8 10
2 4 6 8 10
Source Code:
3. Using For Loop
/* Using for loop */
#include <stdio.h>
int main()
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=2;j<=10;j=j+2)
{
printf("%d ",j);
}
printf("\n");
}
return 0;
}
4. Using while Loop
/* using while loop */
#include <stdio.h>
int main()
{
int i=1,j;
while(i<=5)
{
j=1;
while(j<=5)
{
printf("%d ",j*2);
j++;
}
printf("\n");
i++;
}
return 0;
}
Get the following Output:
1 3 5 7 9
1 3 5 7 9
1 3 5 7 9
1 3 5 7 9
1 3 5 7 9
Source Code:
5. Using For Loop
/* Using for loop */
#include<stdio.h>
int main()
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=9;j=j+2)
{
printf("%d ",j);
}
printf("\n");
}
return 0;
}
6. Using while Loop
/* using while loop */
#include <stdio.h>
int main()
{
int i=1,j;
while(i<=5)
{
j=1;
while(j<=5)
{
printf("%d ",j*2-1);
j++;
}
printf("\n");
i++;
}
return 0;
}




