Question #27061

write a program that reads a three-digit integer number,separates the digits(using/and%),and outputs on the screen how many digit zero, digit one, and digit two the number contains.

Expert's answer

//main function

int main()

{

int coutforzero=0;//count for zero

int coutforone=0;//count for one

int coutfortwo=0;//count for two

char inputnumber[3];//arrau of three-digit integer number

printf("Enter three-digit integer number: ");//input number

scanf("%s",inputnumber);

for(int i=0;i<3;i++){

if((int)inputnumber[i]==0){

coutforzero++;//calculate number of zero

}

if((int)inputnumber[i]==0){

coutforone++;//calculate number of one

}

if((int)inputnumber[i]==0){

coutfortwo++;//calculate number of two

}

}

printf("

Number of zero %d",coutforzero);

printf("

Number of one %d",coutforone);

printf("

Number of two %d",coutfortwo);

return 0;

}

int main()

{

int coutforzero=0;//count for zero

int coutforone=0;//count for one

int coutfortwo=0;//count for two

char inputnumber[3];//arrau of three-digit integer number

printf("Enter three-digit integer number: ");//input number

scanf("%s",inputnumber);

for(int i=0;i<3;i++){

if((int)inputnumber[i]==0){

coutforzero++;//calculate number of zero

}

if((int)inputnumber[i]==0){

coutforone++;//calculate number of one

}

if((int)inputnumber[i]==0){

coutfortwo++;//calculate number of two

}

}

printf("

Number of zero %d",coutforzero);

printf("

Number of one %d",coutforone);

printf("

Number of two %d",coutfortwo);

return 0;

}

## Comments

## Leave a comment