Convert code from Python to C ++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Convert code from Python to C ++

n = input() n = int(n) max = 100 c = [[0 for x in range(max+1)] for x in range(max+1)] for i in range(101): c[i][0] = 1 c[i][i] = 1 for i in range(1, max+1): for j in range(1, i): c[i][j] = c[i-1][j] + c[i-1][j-1] sum=0 for i in range(1, n+1): prod = 1 for j in range(1, i+1): prod *= c[i][j] sum += prod print(sum) ......... My friends, I am learning several new languages ​​and I am converting any code I write into other languages.🤟🙏🥺 😃🥺🙏 Please if anyone can help convert this code from Python to C ++❤❤

31st Dec 2020, 7:33 AM
Shadow
Shadow - avatar
42 Answers
+ 4
Shadow i have converted ur python code to c++, here it is: #include <iostream> using namespace std; int main() { int n, i, j; cin >> n; const int max = 100; long double c[max][max] = {0.0}; for(i = 0; i < max; i++) { c[i][0] = 1; c[i][i] = 1; } for(i = 1; i < max; i++) for(j = 1; j < i; j++) c[i][j] = c[i-1][j] + c[i-1][j-1]; long double sum = 0; //long double because sum value could be very long for(i = 1; i < n+1; i++) { long double prod = 1; for(j = 1; j < i+1; j++) prod *= c[i][j]; sum += prod; } cout << to_string(sum); //im using to_string() function so we can see actual number not in e notations. } //end of program I hope this helps u, please try to run this program and also try to learn c++. Happy sololearning!!☺👍
2nd Jan 2021, 6:58 PM
MOHAN👨🏻‍💻
MOHAN👨🏻‍💻 - avatar
+ 26
Shadow Everyday we see some people come here looking for other people who will do their assignments. We don't mind helping when they show a will to try, but many of them are just looking for a quick getaway. It's obvious that we're not doing them a favour in learning if we do the assignment, rather we cultivate laziness, that they end up not understanding, and into trouble when questioned by lecturers. Please don't take this personal, no one is accusing you of anything. This is just because we need to take care not to destroy one's opportunity to learn, while we're here to help, that's all. Hope you understand 👍
31st Dec 2020, 8:42 AM
Ipang
+ 8
Shadow as I said, you have just started your C++ course on SoloLearn. Unless you know C++ from some other source, you should first advance in the C++ course. This isn't very hard to do if you know C++. Still, here are some steps you can follow: 1. All statements will end in semicolon 2. All variable names will be prefixed by their types when they are declared for the first time. For example, n is int, so you will declare n as `int n`. 3. You neither have list comprehensions in C++, nor do you need it in your code. Just replace the comprehension with the declaration of 2 dimensional int array with each inner array of size`max` 4. For loop can easily be changed as you are only iterating on a range 5. Converting input and output to the respective ways in C++ is also easy If you know C++, you will be able to follow the steps, else just learn more C++. Why else would you want to convert the code? Happy coding!
31st Dec 2020, 8:09 AM
XXX
XXX - avatar
+ 7
Thank you, but I learn so fast and I understand that I will find. If I have the code of this program in C + language, it is better for me to learn it. And I can compare it to Python, it gets easier. I started C ++ from scratch but it was hard for me to learn. Thanks, I think I have to start from scratch to get the answer, but I learned better that way.
31st Dec 2020, 8:24 AM
Shadow
Shadow - avatar
+ 6
Please show us your attempt first. Don't ask people to do work for you. Also, I recommend advancing furthur in the C++ course which you have just started.
31st Dec 2020, 7:59 AM
XXX
XXX - avatar
+ 6
I know, but I explained that this is not for me to escape and be lazy, but to learn faster, and it may be strange, but if I have programming and I would like to learn several languages together and do it for me. It is better and makes learning better. It's good that you are trying to do this so that others can answer for themselves, but my situation is different and why do you put these friends here and if you want to accept what you say and ask for help and guidance . Anyway, thank you, but I never intend to be lazy😊❤🙏
31st Dec 2020, 9:12 AM
Shadow
Shadow - avatar
+ 5
Shadow I do not at all think your question is bad. I just don't understand why would you want this converted to C++, when you don't know enough C++ to understand the converted code. That is why I want YOU to first learn, and then do it yourself. It will only benefit you and you'll get a stronger hold on C++
31st Dec 2020, 8:19 AM
XXX
XXX - avatar
+ 5
Shadow Thanks for understanding, And I didn't say you intend to be lazy, just said some people. I will leave you to continue your study with C++ now. As your knowledge expands and you get a clearer idea how to do this, make a sketch of the code and post it here. I'll try to help as I can, and when I can (or others will) 👌
31st Dec 2020, 9:29 AM
Ipang
+ 4
And you have the right not to give me the code or I am doing something wrong but I am still trying to find the C ++ code of this program and convert them together and get to know C ++ better I think my learning will be better. thanks anyway
31st Dec 2020, 8:27 AM
Shadow
Shadow - avatar
+ 3
🇺🇸 Anatoli🇧🇪🇪🇺 Thank you for your guidance and happy new year❤
4th Jan 2021, 10:39 AM
Shadow
Shadow - avatar
+ 2
And if you look at my page you will see that I started C ++ but I still can't convert the code I wrote to Python to C ++😊
31st Dec 2020, 8:03 AM
Shadow
Shadow - avatar
+ 2
True, this can be bypassed-but not unless you're a techie who knows what he's doing. I do not know why you think my question is so bad? I just wanted to do it the faster I learn. I was told here that friends can help you.🥺🤷‍♀️🤷‍♀️
31st Dec 2020, 8:15 AM
Shadow
Shadow - avatar
+ 2
there is no need to learn multiple languages at once( i already tried it and well now i know none of them ) and as a beginner to programming world you have to undrestand how to search your problem in google and stackOverFlow anyway for your answer there is something called Nuika on github or maybe you can convert it to c and then convert that to c++ again
31st Dec 2020, 11:34 PM
Matin PH
Matin PH - avatar
+ 2
Flash Matin PH there is no need of mentioning these projects. All Shadow wanted was the mentioned program to be converted to C++ just for learning purposes so they could relate the code written in C++ to the mentioned Python code. That is why me and Ipang said that they should first learn C++ and then convert it themselves so they could learn better. Happy coding👍!
1st Jan 2021, 5:35 AM
XXX
XXX - avatar
+ 2
Bhavya What is Shiny Body Syndrome? I go to university and I have to learn languages that I do not need, for example, I know Python, but I have to solve C ++ for university exercises, and this has made it difficult for me, and I have to use other languages besides my main language. Learn too🥺🤦🏻‍♀️
1st Jan 2021, 8:13 AM
Shadow
Shadow - avatar
+ 2
Flash That you said is the site?
1st Jan 2021, 8:14 AM
Shadow
Shadow - avatar
+ 2
Shadow just google, but this may not be useful for you as xxx mentioned. personally I learned Python then C and C++ and my first language was Java. so, I think you could do that as well. one more thing, instead of just converting line by line, try to learn solving the problem in C++ way. it could be useful.
1st Jan 2021, 8:21 AM
Flash
+ 2
Flash Thanks, but I wanted to do all my time for the language I like. But I have to learn other languages as well. Anyway, thank you for your guidance 🙏❤
1st Jan 2021, 8:24 AM
Shadow
Shadow - avatar
+ 2
MOHAN👨‍💻 😍😍❤❤ thank you ❤❤❤❤❤❤
4th Jan 2021, 10:41 AM
Shadow
Shadow - avatar
+ 2
🇺🇸 Anatoli🇧🇪🇪🇺 🤟🙏✌🏻✌🏻❤❤❤
4th Jan 2021, 11:55 AM
Shadow
Shadow - avatar