+ 1
C
Help me in C #include <stdio.h> int noOfDigits(int n){ static int counter = 0; if (n == 0) return counter; else { counter++; noOfDigits(n/10); } } int main() { int num,fc; printf("Count the digits of a given num: \n "); printf(" input a num :"); scanf("%d", &num); fc = noOfDigits(num); printf("the num of digits on the num is %d \n", fc); return 0; }
6 Respostas
+ 2
Your else statement in noOfDigits() should return a value as well, since your function is forced to return integer.
+ 2
Mention your code in codebit then share link here and give description. where u have define function
int noOfDigit(int n)
here function return type is int type if it is anything apart from void then u need to use return any value here return type is int then u need to return any integer value .
#include <stdio.h>
int noOfDigits(int n){
static int counter = 0;
if (n == 0)
return counter;
else {
counter++;
noOfDigits(n/10);
}
return counter;
}
int main()
{
int num,fc;
printf("Count the digits of a given num: \n ");
printf(" input a num :");
scanf("%d", &num);
fc = noOfDigits(num);
printf("the num of digits on the num is %d \n", fc);
return 0;
}
+ 2
Dee , your code is very good made. There will be needed only an additional return statement in the else part as already Scoozak said. This is mandatory for non void functions. This can be done as here:
https://code.sololearn.com/cdPB5bGP74oo/?ref=app
+ 1
With A?
0
why its wrong ?
0
what shoud i write ?
return int ?