Sunday, November 29, 2020

Write a C program that reads two integers p and q, print p number of lines in a sequence of 1 to q in a line.

 /*Write a C program that reads 

two integers p and q, print 

p number of lines in a 

sequence of 1 to q in a line. 

Test Data :

Input number of lines: 5

Number of characters in a 

line: 6

Expected Output:

1 2 3 4 5 6

7 8 9 10 11 12

13 14 15 16 17 18

19 20 21 22 23 24

25 26 27 28 29 30

*/

#include <stdio.h>

int main()

{

  int num1,num2,i,j,k=1;

  printf("Input the number\

 number of lines: ");

  scanf("%d",&num1);

  printf("Number of character\

 in a line: ");

  scanf("%d",&num2);

  for(i=0;i<num1;i++)

  {

    for(j=0;j<num2;j++)

    {

      printf("%d ",k++);

    }

    j=0;

    printf("\n");

  }

  return 0;

}

No comments:

Post a Comment