0

Storing digits of a number

Hii I want to store digits of number ,that has 85 digits ,in an array and then use some specific elements of this array and put them in diffrent arrays but my code doesn't work correctly. Can anyone help me? This is what I did Long long int digits[85]; String input; Cin>>input; For(int i=0;i<85;i++) { digits[i]=input[i]-'0'; } Long long int arr1[5][3]={{digits[0],digits[1],digits[2]},..} Thanks everyone helping this🙏🏼

12th May 2021, 3:48 PM
Sahaarr
Sahaarr - avatar
7 odpowiedzi
+ 1
Sahaarr You can try the stoi() function to convert string to int. stoi("10") 10
12th May 2021, 4:10 PM
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜ - avatar
+ 1
Share what you are inputting and the outputs you are getting and expecting.
12th May 2021, 7:52 PM
Jerry Hobby
Jerry Hobby - avatar
0
Mohan 333 it's a homework and unfortunatly I can't use this function:(
12th May 2021, 4:17 PM
Sahaarr
Sahaarr - avatar
0
Nikhil those 85digits are bitmap of a digital clock which contains only 1 and 0. When I enter the bitmap and put its digits in my array in a for loop, arr1 doesn't show the right elements. Also I need to use arr1 in other places so I can't define in a loop :((. Btw thank you so much for answering!
12th May 2021, 4:20 PM
Sahaarr
Sahaarr - avatar
0
Nikhil I wrote some functions to diagnose what numbers a array can make. Let me clarify it. I get the bitmap of a digital clock which contains 85 digits that are only 1 and 0. And then seperate every digit and put it as as elements of my array. Then I need to make arr1[5][3] to see what number it will make. For example if arr1={{1,1,1},{1,0,1},{1,0,1},{1,0,1},{1,1,1}} it will make the number 0(imagine it as a matrix,you'll see the shape will make the number 0 in digital form). Every number from 0 to 9 has a digital form and my function are written to diagnose them and return the number which is made
12th May 2021, 4:44 PM
Sahaarr
Sahaarr - avatar
0
The code you posted has a few typos in it. I fixed it, but not sure where your error was precisely. Here’s a working version. #include <iostream> using namespace std; int main() { long long int digits[85]; string input; cin>>input; for(int i=0;i<85;i++) { digits[i]=input[i]-'0'; } long long int arr1[5][3] = { {digits[0],digits[1],digits[2]}, {digits[5],digits[4],digits[3]} }; for(int x=0; x<5; x++) { for(int y=0; y<3; y++) { cout << "["<<x<<"]"<<"["<<y<<"]="<<arr1[x][y]<<", "; } cout << endl; } }
12th May 2021, 5:16 PM
Jerry Hobby
Jerry Hobby - avatar
0
Jerry Hobby thank you so much 🙏🏼 but for my program and input I don't get the accurate result 😔😔
12th May 2021, 7:07 PM
Sahaarr
Sahaarr - avatar