Write a program that reads an integer value n from the user
Write a program that reads an integer value n from the user and prints a pattern of numbers that is shown below for n = 5 and n = 3. Generate the pattern separately using each loop given below for loop while loop for loop Sample input/output (using for loop): Test Case 1: Enter the number: 5 0 0 1 0 1 2 0 1 2 3 0 1 2 3 4 0 1 2 3 4 5 Test case 2 Enter the number: 3 0 0 1 0 1 2 0 1 2 3
Solution
#include<stdio.h>
int main()
{
printf(\"enter n :\");
int n;
scanf(\"%d\",&n);
printf(\"\ using for loop \ \");
for(int i=0;i<=n;i++)
{
for(int j=0;j<=n;j++)
{
if(j<=i)
printf(\"\\t %d\",j);
}
printf(\"\ \");
}
printf(\"\ using while loop\");
int i=0,j=0;
while(i<=n)
{
while(j<=n)
{
if(j<=i)
printf(\"\\t %d\",j);
}
printf(\"\ \");
}
printf(\"\ using do while \ \");
int i=0,j=0;
do
{
do
{
if(j<=i)
printf(\"\\t %d\",j);
}while(j<=n)
printf(\"\ \");
}while(i<=n)
return 0;
}
