Computer Science, asked by Phisher, 3 months ago

i am a programmer i need help in c language
print this pattern using loops
2
2 5
2 5 10
2 5 10 17
please give the right answer

Answers

Answered by anindyaadhikari13
0

Answer:

This is the required C program for the question.

#include <stdio.h>

int main()  {

   int n,i,j,a,b;

   printf("Enter number of rows for the pattern - ");

   scanf("%d",&n);

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

       a=2,b=3;

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

           printf("%d ",a);

           a+=b;

           b+=2;

       }

       printf("\n");

   }

   return 0;

}

Explanation:

  • At first, I have asked the user to enter the number of rows for the pattern.
  • Then, I have created a loop that iterates n times where n is the number of rows.
  • Then, another loop is created for displaying the columns. This loop iterates i times where i is the row number (as row number = number of cols on that row).
  • Then, I have initialized a = 2, b = 3
  • Inside the second loop, value of a is displayed. Value of a is incremented by 2 and value of b is incremented by 3.
  • After displaying the row, a new line is displayed.

See the attachment for output.

Attachments:
Similar questions