Print the following pattern.in c language only using for loop
only and please comment each step to make it understandable
5 5
5 4 4 5
5 4 3 3 4 5
5 4 3 2 2 3 4 5
5 4 3 2 1 1 2 3 4 5
CODE IN C:
#include<stdio.h>
int main()
{
int n;
printf("Enter the value of n : "); //the pattern is divide dinto
two patternS: the first is 5 54 543 5432 54321 and second is 5 45
345 2345 12345
scanf("%d",&n);
for(int i =n;i>=1;i--)
{
for(int j=n;j>=i;j--) //this loop is to print the first
pattern
{
printf("%d",j);
}
for(int k=i;k<=5;k++)//this loop is to print the second
pattern
{
printf("%d",k);
}
printf("\n");
}
}
First pattern is
5
5 4
5 4 3
5 4 3 2
5 4 3 2 1
Second pattern is
5
4 5
3 4 5
2 3 4 5
1 2 3 4 5
OUTPUT SNIPPET:
Get Answers For Free
Most questions answered within 1 hours.