Saturday, April 27, 2019

Take a count

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 
  

Test Case 2 
  
Input (stdin) 
562356 
  
Expected Output 
  


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

Parity

Problem Description Ram and Sita playing the parity game. Two types of parity are there. One is odd parity and next is even parity. Ram will...