Computer Science, asked by eyekapilgiri, 11 months ago

1
2 6
3 7 10
4 8 11 13
5 9 12 14 15

Answers

Answered by MickeyandMinnie
1

Answer:

Logic to print the given number pattern

C program to print the given number pattern using for loop

Input

Input N: 5

 C program to print the given number pattern

#include <stdio.h>

int main()

{

   int i, j, diff, value, N;

   printf("Enter rows: ");

   scanf("%d", &N);

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

   {

       diff = N-1; // Initialize difference to total rows - 1

       value = i;  // Initialize value to the current row number

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

       {

           printf("%-3d", value);

           value += diff; // Computes the next value to be printed

           diff--;        // Decrements the difference

       }

       printf("\n");

   }

   return 0;

}

Similar questions