[ create a new paste ] login | about

Link: http://codepad.org/CWep1Tuz    [ raw code | output | fork ]

C, pasted on Apr 23:
int countdigit (int number,int digit){
	int d,n,count=0;
		n=number;
	while (n!=0){

		d=n%10;
		n=n/10;
		if (d==digit) count ++;}
		return count;
	}
	
#include<stdio.h>

int main(void)
{
	
	int x,t;
	printf("Input an integer: ");
	x=123;
	t=countdigit(x,2);
	
	printf("Number of digit 2: %d",t);
}


Output:
1
2
Input an integer: Number of digit 2: 1
Exited: ExitFailure 20


Create a new paste based on this one


Comments: