Created
June 9, 2014 17:16
-
-
Save cynx/b40ef6988eefe2e95d4c to your computer and use it in GitHub Desktop.
C Program to count occurance of digits and white space and others
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//to count occurance of digits and white space and others | |
#include <stdio.h> | |
int main() | |
{ | |
int i,c,nwhites,nothers; | |
int ndigits[10]; | |
c=nwhites=nothers=0; | |
for (i=0; i<10; ++i) { | |
ndigits[i]=0; | |
} | |
while ((c=getchar())!=EOF) { | |
if(c>='0' && c<='9') | |
{ | |
++ndigits[c-'0']; | |
} else if (c == ' ' || c == '\n' || c == '\t') | |
++nwhites; | |
else | |
++nothers; | |
} | |
for(i=0;i<10;++i) | |
printf(" %d",ndigits[i]); | |
printf("\n%d %d",nwhites,nothers); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment