Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

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, 2020 by TylerBlachowiak (330 points)
I have been stuck on this question for a long time.

1 Answer

+2 votes
answered Mar 30, 2020 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);
    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, 2020 by TylerBlachowiak (330 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.