

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
This c program uses a switch statement and a while loop to count the number of times each integer from 0 to 9 is entered by the user. The program can process a maximum of 20 inputs. After each input, the user is prompted to enter another number. The final count for each integer is displayed at the end.
Typology: Exercises
1 / 2
This page cannot be seen from the preview
Don't miss anything!
int main() // main entry point into the program { // start of main int i,i,input; // variable declaration
// counter variable declaration int count0,count1,count2,count3,count4,count5,count6,count7,count8,count9; // counter initialization to zero count0=count1=count2=count3=count4=count5=count6=count7,count8=count9=0; printf("enter number (0-9)\n"); scanf("%d",&input); // user input integer i=1; // loop counter initialization while(i<=20) // loop condition that check for maximum 20 inputs { // switch statement to check each user input against case 0- switch(input){ case 0: count0++; // Increment statement if your input 0 break; // skipping other cases case 1: count1++; break; case 2: count2++; break; case 3: count3++; break; case 4: count4++; break; case 5: count5++; break; case 6: count6++; break; case 7: count7++; break; case 8: count8++; break; case 9: count9++; break;
default: printf("input out of range enter (0-9)\n"); } // end of switch statement printf("enter number (0-9)\n"); scanf("%d",&input); // user input i++; // increment of loop counter } // end of while loop
// displaying user final summary printf("0=%d,1=%d,2=%d,3=%d,4=%d,5=%d,6=%d,7=%d,8=%d,9=%d\n",count ,count1,count2,count3,count4,count5,count6,count7,count8,count9);
} // end of main program