Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

C Program for Counting Integer Inputs, Exercises of Computer Fundamentals

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

2011/2012

Uploaded on 07/31/2012

karthik
karthik 🇮🇳

4.6

(16)

95 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
/*
* intergerCount.c
*
* Created on: Nov 13, 2010
* Author: mohsan
*/
#include <stdio.h> // standard input out
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-9
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;
docsity.com
pf2

Partial preview of the text

Download C Program for Counting Integer Inputs and more Exercises Computer Fundamentals in PDF only on Docsity!

  • intergerCount.c
  • Created on: Nov 13, 2010
  • Author: mohsan */ #include <stdio.h> // standard input out

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;

docsity.com

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

docsity.com