Long input | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Long input

#include <iostream> using namespace std; int main() { unsigned long long int c; cin>>c; while(c>=10){ c/=10; } cout<<c; return 0; } If I give input as: 93099339395097728908 It doesn't give the correct output which is 9 why???

4th Jul 2021, 8:45 AM
HK Lite
HK Lite - avatar
5 Answers
+ 3
Your value might be or is longer than max value allowed by that type , for max value you can check by using, cout<<ULLONG_MAX; Also go through the following article, https://www.google.com/amp/s/www.geeksforgeeks.org/maximum-value-of-unsigned-long-long-int-in-c/amp/
4th Jul 2021, 9:36 AM
Abhay
Abhay - avatar
+ 2
A.S. it does not print the correct output for larger input how can I fix it, use the input I mentioned in the question.
4th Jul 2021, 8:55 AM
HK Lite
HK Lite - avatar
0
What u want to know this code is working it will c/10 will sperate your last number . Use cout inside loop and print values u will understood how its working #include <iostream> using namespace std; int main() { unsigned long long int c; cin>>c; while(c>=10){ c/=10; cout<<c<<" "; } return 0; }
4th Jul 2021, 8:50 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
HK Lite stores your data in form of strings array after that conver it into int
4th Jul 2021, 9:30 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
you can also use auto keywords but it cannot store big integers
4th Jul 2021, 9:46 AM
A S Raghuvanshi
A S Raghuvanshi - avatar