Write a code snippet to accept integer values coming from a user into an array named snippet and takes in 25 items using a do while loop
Done in C language. (The logic would be same for other languages as well)
#include <stdio.h>
int main()
{
int totalItems = 0,snippet[25];
do{
printf("Enter a number: ");
scanf("%d",&snippet[totalItems]);
totalItems+=1;
}while(totalItems!=25);
return 0;
}
Here we use a variable totalItems, when its value reaches 25 we
end the do while loop.
on each loop the user input is added to the snippet array and then
the variable totalItems is incremented.
Get Answers For Free
Most questions answered within 1 hours.