Oct 14, 2018 at 1:55pm UTC
Input a number from user having more than 10 digits and less than 45
Store 9 digit number at every index of int arr[5]
I have problem on how to take input from user
Example if user Enter =1234567898765543211234
int arr[5]={123456789,876554321,1234,0,0};
Example if user Enter 123456789987654321123456789454565456123457890
int array[5]={123456789,987654321,123456789,454565456,123457890}
Oct 14, 2018 at 3:30pm UTC
Read the input into a string, check that the size is right and then use substr to extract the 9 digits (add zeros if necessary) and use stoi to convert to int, finnaly store it in your array
Oct 14, 2018 at 4:09pm UTC
# include <iostream>
# include <string>
using namespace std;
int main()
{
string s ("1300000000000900000000100000000");
string s1[5]="";
s1[0]=s.substr(0,9);
s1[1]=s.substr(10,18);
cout << s1[0]<<endl;
cout << s1[1]<<endl;
return 0;
}
It is not giving correct value for s1[1];
Last edited on Oct 14, 2018 at 4:58pm UTC