0% found this document useful (0 votes)
23 views1 page

Pattren

The program takes an input N and prints a pattern of numbers. It uses nested for loops to print dashes for spacing, then numbers incremented from variables A and B in each row. Variable B is adjusted each row to continue the incrementing pattern from the last number of the previous row. The output is a 4x4 pattern using the numbers 1 through 17 when N=4.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views1 page

Pattren

The program takes an input N and prints a pattern of numbers. It uses nested for loops to print dashes for spacing, then numbers incremented from variables A and B in each row. Variable B is adjusted each row to continue the incrementing pattern from the last number of the previous row. The output is a 4x4 pattern using the numbers 1 through 17 when N=4.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

PATTREN PROGRAM

#include<stdio.h>
int main()
{
int n=4,i,j,a=1,b,k,c=0,l;
b=n*n+1;
for(i=n;i>0;i--)
{
for(k=0;k<n-i;k++)
{
printf("-");
}
for(j=1;j<=i;j++)
{
printf("%d*",a++);
}
for(l=1;l<=i;l++)
{
printf("%d*",b++);
}
b=b+1-2*(i);
printf("\n");
}
}
Output:N=4

Here I took the input variable as n and assign a value 4. So, it takes four rows where each row is indexed
with the variable I, and the column with j and k is the variable used for spaces.
Here the 1st for loop repeats until from n to 1times, for each loop it gives k times of ‘-‘ symbol(k repeats
from 0 to n-i times) and the values are printed based on the conditions we have written in the for loop of j
and l, which repeats from 1 to i times.
In j for loop we increment the value of variable ‘a’ to 1 which is initialized to 1 and printed the value
before ‘*’. Here variable ‘a’ is used to print 1 to 10 while n=4.
In l for loop we increment the value of variable ‘b’ to 1 which is initialized to (n*n+1) in each row and
printed the value before ‘*’. Here variable ‘b’ is used to print 11 to 17 while n=4.
For example in the first row the value of b is incremented from 17 to 20 and in the second we need to
increment the value of b from 14 to n-1 so we assigned the value of b as b+1-2*(i) after completion of j
and l for loop. And again the I for loop starts in next line.

You might also like