0% found this document useful (0 votes)
66 views5 pages

Assignment 2

The document contains 5 C programs that print patterns using loops. The first program prints increasing numbers on each line. The second program prints a triangle with spaces. The third program prints a mirrored triangle with stars. The fourth program prints increasing numbers in each row. The fifth program prints a pattern of Ws and Hs framed by spaces.

Uploaded by

Raj
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)
66 views5 pages

Assignment 2

The document contains 5 C programs that print patterns using loops. The first program prints increasing numbers on each line. The second program prints a triangle with spaces. The third program prints a mirrored triangle with stars. The fourth program prints increasing numbers in each row. The fifth program prints a pattern of Ws and Hs framed by spaces.

Uploaded by

Raj
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/ 5

1/A

#include <stdio.h>

int main() {

int n;

printf("Enter the base length\n");

scanf("%d",&n);

for(int i = 1; i <= n; i++) {

for(int j = 0; j < i; j++) {

printf("%d ", i);

printf("\n");

return 0;

1/B

#include <stdio.h>

int main()

int i, j, rows;

printf("Enter number of rows: ");

scanf("%d", &rows);
for(i=1; i<=rows; i++)

for(j=i; j<rows; j++)

printf(" ");

for(j=1; j<=i; j++)

printf("%d",i);

printf("\n");

return 0;

#include<stdio.h>

int main() {

int rows, coef=1, space, i, j;

printf("Enter number of rows: ");

scanf("%d", &rows);

for (i=0; i<rows; i++) {

for (space=1; space <= rows-i; space++)

printf(" ");
for (j=0; j<=i; j++) {

if (j==0 || i==0)

coef = 1;

else

coef=coef*(i-j+1)/j;

printf("%4d", coef);

printf("\n");

return 0;

#include<stdio.h>

int main() {

int rows, i, j, space;

printf("Enter number of rows: ");

scanf("%d", &rows);

for (i=rows; i>=1; --i) {

for (space=0; space<rows-i; ++space)

printf(" ");

for (j=i; j<=2*i-1; ++j)

printf("* ");

for (j=0; j<i-1; ++j)

printf("* ");

printf("\n");

return 0;
}

4.

#include<stdio.h>

int main() {

int rows, i, j, number= 1;

printf("Enter number of rows: ");

scanf("%d", &rows);

for (i=1; i<=rows; i++) {

for (j=1; j<=i; ++j)

{ printf("%d ", number);

++number;

printf("\n");

return 0;

5.

#include <stdio.h>

int main()

int i, j, rows, columns;


printf("Enter number of rows: ");

scanf("%d", &rows);

printf("Enter number of columns: ");

scanf("%d", &columns);

for(i=1; i<=rows; i++)

for(j=1; j<=columns; j++)

if(i==1 || i==rows)

printf("W ");

else if (j==1 || j==columns)

printf("H ");

else

printf(" ");

printf("\n");

return 0;

You might also like