Sheela gave a number to Jonnes and ask him to count the number of digits in a number. Sheela tries one simple logic to do that. So she decided to apply this concept in C.
Test Case 1
Input (stdin)
3452
Expected Output
4
Test Case 2
Input (stdin)
562356
Expected Output
6
Solution
#include <stdio.h>
int main()
{
long long num;
int count = 0;
scanf("%lld", &num);
while(num != 0)
{
count++;
num /= 10;
}
printf("%d", count);
return 0;
}
Test Case 1
Input (stdin)
3452
Expected Output
4
Test Case 2
Input (stdin)
562356
Expected Output
6
Solution
#include <stdio.h>
int main()
{
long long num;
int count = 0;
scanf("%lld", &num);
while(num != 0)
{
count++;
num /= 10;
}
printf("%d", count);
return 0;
}
No comments:
Post a Comment