How to Scanf inside loop if it is based on the user input

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Freshmen
    New Member
    • Sep 2015
    • 1

    How to Scanf inside loop if it is based on the user input

    for(int k=1;k<=num;k++)
    printf(\nPlease enter your desired seat %i: ",k)
    scanf("%i",&a);

    //num is declared if how many the user will input
    How to use scanf?
  • Clearner321
    New Member
    • Sep 2015
    • 22

    #2
    You can declare an array of int of enough size like
    Code:
    int array[100];
    And use scanf something like
    Code:
    for(k=0; k < num; k++)
    scanf("%d",&array[k])
    You can loop from k 0 to num-1 instead of 1 to num.

    Comment

    Working...