How do you write a loop that will print the values in a 20-element array named quantity to the screen?

0 votes
asked Mar 29 by TylerBlachowiak (230 points)
I have been stuck on this question for a long time.

1 Answer

+2 votes
answered Mar 30 by Hitesh Maharjan (180 points)

#include <stdio.h>
#define SIZE 20
int main()
{
    int i,quantity[SIZE];
    for (i = 0; i < SIZE; i++)
    {
        printf("quantity[%i] = ",i);
        scanf("%i",&quantity[i]);
    }
    printf("\nOutput\n");
    for (i = 0; i < SIZE;i++)
    {
        printf("quantity[%i] = %i\n",i,quantity[i]);
    }

    return 0;
}

The highlighted for loop can be used to print the elements  of an array.

commented Mar 31 by TylerBlachowiak (230 points)
How can I do this with cout instead of printf and scanf?
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...