Docsity

C Program for Counting Integer Inputs, Exercises of Computer Fundamentals

Toggle sidebar
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