0% found this document useful (0 votes)
64 views

C

The document contains code for multiple functions that generate numeric patterns based on an input integer. The functions use loops and conditionals to print numbers and multiplication symbols in various arrangements. Some functions increment or decrement a counter variable to control the numbers printed on each line. The document seeks to demonstrate different approaches for programmatically generating numeric patterns of varying complexity.

Uploaded by

Haritha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views

C

The document contains code for multiple functions that generate numeric patterns based on an input integer. The functions use loops and conditionals to print numbers and multiplication symbols in various arrangements. Some functions increment or decrement a counter variable to control the numbers printed on each line. The document seeks to demonstrate different approaches for programmatically generating numeric patterns of varying complexity.

Uploaded by

Haritha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 7

n=4

1
2*2
3*3*3
4*4*4*4
4*4*4*4
3*3*3
2*2
1

n=3

1
2*2
3*3*3
3*3*3
2*2
1

void pattern(int num)


{
// write your code here
int i,j;
for(i=1;i<=n;i++)
{
printf("%d",i);
for(j=1;j<=i-1;j++)
printf("*%d",i);
printf("\n");
}

for(i=n;i>=1;i--)
{
printf("%d",i);
for(j=1;j<=i-1;j++)
printf("*%d",i);
printf("\n");
}
}

n=4, s=3

3
44
555
6666
6666
555
44
3

n=3, s=5

5
66
777
777
66
5

void pattern(int n,int s)


{
// write your code here
int i,j;
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
printf("%d",s);
printf("\n");
s++;
}
for(i=n;i>=1;i--)
{
s--;
for(j=1;j<=i;j++)
printf("%d",s);
printf("\n");
}
}

n=4

11112
32222
33334
54444

n=5
111112
322222
333334
544444
555556

n=4

11111
22222
33333
44444
void pattern(int n)
{
// write your code here
int i,j;
for(i=1;i<=n;i++)
{
for(j=1;j<=n+1;j++)
printf("%d",i);
printf("\n");
}
}
n=4
11112
32222
33334
54444
void pattern(int n)
{
// write your code here
int i,j;
for(i=1;i<=n;i++)
{
if(i%2==0)
printf("%d",i+1);
for(j=1;j<=n;j++)
printf("%d",i);
if(i%2==1)
printf("%d",i+1);
printf("\n");
}
}

n=5

55555
55155
55255
55355
55455
55555

n=3

333
313
323
333

n=4
44444
44144
44244
44344
44444

void pattern(int n)
{
// write your code here
int i,j;
if(n%2==1){
for(i=1;i<=n;i++)
printf("%d",n);
printf("\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(j==n/2+1)
printf("%d",i);
else
printf("%d",n);
}
printf("\n");
}
}
else
{
for(i=1;i<=n+1;i++)
printf("%d",n);
printf("\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n+1;j++)
{
if(j==n/2+1)
printf("%d",i);
else
printf("%d",n);
}
printf("\n");
}
}
}
n=4

1
2*3
4*5*6
7*8*9*10

7*8*9*10
4*5*6
2*3
1

void pattern(int n)
{
// write your code here
int i,j,a=1;
for(i=1;i<=n;i++)
{
printf("%d",a++);
for(j=1;j<=i-1;j++)
{
printf("*%d",a++);
}
printf("\n");
}

for(i=n;i>=1;i--)
{
a=(i*(i-1))/2+1;
printf("%d",a++);
for(j=1;j<=i-1;j++)
{
printf("*%d",a++);
}
printf("\n");
}
}

n=4
1
3*2
4*5*6
10*9*8*7
n=5
1
3*2
4*5*6
10*9*8*7
11*12*13*14*15
n=6
1
3*2
4*5*6
10*9*8*7
11*12*13*14*15
21*20*19*18*17*16

void pattern(int n)
{
// write your code here
int i,j,a=1;
for(i=1;i<=n;i++)
{
if(i%2==1)
{
a=a+i-1;
printf("%d",a++);
for(j=1;j<=i-1;j++)
{
printf("*%d",a++);
}
printf("\n");
}
else
{
b=a+i-1;
printf("%d",b--);
for(j=1;j<=i-1;j++)
{
printf("*%d",b--);
}
printf("\n");
}
}
}

void pattern(int n)
{
// write your code here
int i,j,a=1;
for(i=1;i<=n;i++)
{
if(i%2==1)
{
a=(i*(i-1))/2+1;
printf("%d",a++);
for(j=1;j<=i-1;j++)
printf("*%d",a++);
}
else
{
a=(i*(i+1))/2;
printf("%d",a--);
for(j=1;j<=i-1;j++)
printf("*%d",a--);
}
printf("\n");
}
}

n=4
1*2*3*4
9*10*11*12
13*14*15*16
5*6*7*8
N=5
1*2*3*4*5
11*12*13*14*15
21*22*23*24*25
16*17*18*19*20
6*7*8*9*10
N=6
1*2*3*4*5*6
13*14*15*16*17*18
25*26*27*28*29*30
31*32*33*34*35*36
19*20*21*22*23*24
7*8*9*10*11*12

void pattern(int n)
{
for(i=1;i<=(n+1)/2;i++)
{
printf("%d",a++);
for(j=1;j<=n-1;j++)
printf("*%d",a++);
printf("\n");
a=a+n;
}
if(n%2==0)
a=n*(n-1)+1;
else
a=n*(n-2)+1;
for(i=1;i<=n/2;i++)
{
printf("%d",a++);
for(j=1;j<=n-1;j++)
printf("*%d",a++);
printf("\n");
a=a-3*n;
}
}

1*2*3*4*17*18*19*20
--5*6*7*14*15*16
----8*9*12*13
------10*11
c=(n*(n+1))/2;
for(i=n;i>=1;i--)
{
//underscore
for(j=n;j>i;j--)
printf("--");
for(j=1;j<=i;j++)
printf("%d*",a++);
d=(i*(i-1))/2+1;
b=c+d;
printf("%d",b++);
for(j=1;j<i;j++)
printf("*%d",b++);
printf("\n");
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy