I am supposed to input in the above form. The first integer in each line decides the number of integers that follow. Since the first integer can vary, I do not know if it is possible with ‘scanf’.
I think that this code snippet solves your problem:
#include <stdio.h>
int main()
{
int x;
scanf("%d", &x);
for(int i = 0; i < x;i++)
{
int elem;
scanf("%d", &elem);
}
return 0;
}
What you need to take care of, is actually the 1st integer you read, that will control the for loop that will allow you to input all the other numbers…
Understood the code.That worked. I should give more time to understand scanf and cin completely.
Thanks. M commenting after successful submission on first attempt.