+ 1

How can i change char to int and send it to massiv in c++

/* Demak, boshladim created by A.Behzod bu dastur sonni shunchaki qabul qiladi va uni massivga joylaydi fayl <<bu max ko*paytma>> uchun maxsus */ #include<iostream> #include<math.h> using namespace std; int main() { char lg[3]; cout<<endl; cin >>lg[0]>>lg[1]>>lg[2];//belgilar for(int i=0; i<10; i++) { int son[10]; //massiv //massivga son kirityapti son[i] = (int)lg[i] - 48; cout << son[i];} main(); return 0; } So there is problem that 'i' is changing 0 when code repeat main() function But i want to send to son[i] integer number from char[lg] one by one And it is important that I should press any key durinng three number sended

27th Nov 2020, 10:58 AM
Behzod
Behzod - avatar
14 Réponses
+ 2
int son[10]; for(int i=0; i<3; i++) { son[i] = lg[i]; cout << son[i]<<endl; } This is enough. Behzod In your code, your are taking 3 inputs but converting 10 charecter (loop 10 times cycling..) and no need subtract a value or type cast (it will type cast implicitly from char to int.. Take initialization of son[10] out off loop...
27th Nov 2020, 12:50 PM
Jayakrishna 🇮🇳
+ 2
What is this code? why make main function recursive?
27th Nov 2020, 12:58 PM
Ipang
+ 2
Behzod Have you got the solution? I didn't exactly understand the program, maybe it's because I don't understand your language (Uzbek).
9th Dec 2020, 2:00 PM
Ipang
+ 2
Salon Hello Ipang my code is used for multiplication of two number Which are inputed as 1)Input->> 2 + enter (first number's digits are 2) 2)continue input->> 2 + enter (second number's digits are 2) 3)continue input->> 1 2 (separate it with probel ) 4)continue input ->> 1 3 (separate it with probel) Output is: 156 ( 12*13=156) This code works on high digit numbers also
9th Dec 2020, 2:59 PM
Behzod
Behzod - avatar
+ 2
Behzod 24 digit number is very big, I don't know if any integral data type supports that many digits. And being multiplied, it will grow bigger. Any thoughts on this matter?
9th Dec 2020, 3:12 PM
Ipang
+ 1
#include<iostream> using namespace std; int main() {//beginnig int x, y; cout<<"HELLO\nWELLCOME TO \nTHE CODE OF MULTIPLICATION OF VERY LONG\n "; cout<<"TWO NUMBERS\nXUSH KELIBSIZ¡¡¡\n\n"; cout<<"What is the amount of firs number: "; cin>>x; cout<<"\nWhat is the amount of second number: "; cin>>y; int a[100][100]={}; cout<<"\nType the number of first one by one using probel \n"; for (int i=1; i<=x; i++) { cin>> a[0][i]; } cout<<"\nType the number of second number one by one as first \n"; for (int i=1; i<=y; i++) {cin>> a[i][0]; } cout<<endl<<endl;; //katakch natijasi for (int k=1; k<=y; k++) for (int j=1; j<=x; j++) a[k][j] = a[0][j]*a[k][0] ; int b[200][2]={}; cout<<endl<<endl; for (int k=1; k<=y; k++) for (int j=1; j<=x; j++) b[k+j][0]+=a[k][j]; //tuzatish for (int i=x+y; i>1; i--) { b[i-1][0]+=b[i][0]/10;} //tuzatish
27th Nov 2020, 2:36 PM
Behzod
Behzod - avatar
+ 1
Behzod DM doesn't work, we discuss here I'm trying to understand ... First input defines first number digit Second input defines second number digit But why 1 2 and 1 3? Why not take the number 12 and 13?
9th Dec 2020, 3:05 PM
Ipang
+ 1
Is it ok if we read input as 12 and 13? I think I begin to understand better ...
9th Dec 2020, 3:08 PM
Ipang
+ 1
Basically you should enter 15 24 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 And 1 3 5 4 6 7 3 6 2 4 3 5 3 6 4 5 3 4 5 3 3 6 6 3 And you give multiple of them
9th Dec 2020, 3:08 PM
Behzod
Behzod - avatar
+ 1
I might try to help with small number of digits. But 15 ~ 24 digits, I don't know for sure ...
9th Dec 2020, 3:14 PM
Ipang
+ 1
Int first[]; Char dgt[] ; Cin>>dgt[1]>>dgt[2]>>...>>dgt[n]; For (int i=1; i<=n; i+8+) {First[i] = dgt[i] - 48; } This is consept of my problem But as you see there is another problem
9th Dec 2020, 3:27 PM
Behzod
Behzod - avatar
+ 1
Here it's using `int` I'm limiting up to 10 digits for each number. `int` can't go more than 10 digits. Test with input 3 3 1 2 3 4 5 6 https://code.sololearn.com/cp82IKXQUHiP/?ref=app
9th Dec 2020, 4:23 PM
Ipang
0
It is example for understanding how is it used for
9th Dec 2020, 3:06 PM
Behzod
Behzod - avatar
0
But i want input them without probel and as 12 not 1 2 And it will be used more comfortable
9th Dec 2020, 3:13 PM
Behzod
Behzod - avatar