Return to Snippet

Revision: 50186
at August 15, 2011 08:51 by kyhle


Initial Code
#include <stdio.h>

// count the digit, white space, and others
int main()
{
	char c,nwhite,nother;

	int ndigit[10];
	
	nwhite = 0;
	nother = 0;

	for(int i = 0; i < 10; i++) 
		ndigit[i] = 0;

	while( (c = getchar()) != EOF ) {
		if ( c >= '0' && c <= '9' )
			++ndigit[c-'0'];
		else if ( c == '\n' || c == '\t' || c == ' ')
			++nwhite;
		else
			++nother;
	}

	printf("The number of white space is: %d\n",nwhite);
	printf("The number of other char is: %d\n",nother);

	int j = 9;
	while( j !=0 ){
		printf("The number of digit %d is",j);
		printf("%d\n",ndigit[j]);
		--j;
	}
	return 0;
}

Initial URL

                                

Initial Description

                                

Initial Title
count digits, white space and others

Initial Tags

                                

Initial Language
C