20 Respostas
+ 2
3x5..its very easy
include <iostream>
using namespace std;
int main() {
int n{3},m{5};
for(int j{};j<n;++j){
if((j&1)==0){
for(int i{1};i<=m;++i){cout<<i+m*j<<" ";}
}else{for(int u=m;u>0;--u){cout<<u+m*j<<" ";}
}
cout<<"\n";
}
}
It's simple way, if you need more, so put some logics also
+ 2
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
for (int j = 0; j < n; j++) {
for (int i = 0; i < m; i++) {
int num = i + 1 + m * j;
if (j % 2 == 1) {
num = (j + 1) * m - i;
}
cout << setw(4) << num;
}
cout << endl;
}
return 0;
}
In this C++ version, the map() function from Python is replaced with the cin function to read input from the user. The loop over the range of n and the inner list comprehension are replaced with nested for loops. The join() function is replaced with the setw() function from the iomanip library to format the output. The pow() function is replaced with the modulo operator % and the conditional statement if (j % 2 == 1) to alternate the direction of the sequence on odd rows.
Note that this C++ code assumes that the iostream and cmath libraries have been included at the beginning of the code.
+ 1
why not simply learn C++?
if you managed to learn Python, you can learn C++.
Even if you can feed the code to ChatGPT and get a C++ equivalent, you'd still have to know C++ to be able to debug it.
0
I dont think you can… why do you need to convert it into C++?
0
a study assignment, we were allowed only in c++, and I only know pyton
0
So you need to find someone who can translate it for you?
0
Yes...
0
The first one is more successful, but the second one COULD be as sucessful and faster, but its a small risk…
0
Oh shoot i deleted the other post
0
It said the first option was to try to dm a mentor, second explain the code to me and i translate it
0
According to the given numbers n and m, fill a two-dimensional array of size
n×m with numbers from 1 to n×m with a “snake”, as shown in the example.
Input data format
Two numbers n and m are entered, each of which does not exceed 20.
Output data format
Output the resulting array, allocating exactly 4 to the output of each element
the symbol.
that is, it should go from one to some number from left to right, and then from right to left
0
nxm as in n*m? What is snake?
0
let's say we introduce 3×5
1 2 3 4 5
10 9 8 7 6
11 12 13 14 15
0
why all the numbers?
0
Well, I'm trying to explain what a "snake" is
0
yes- but why all numbers? i know what 3x5 is…
0
as an example
0
ah- pls continue
0
bro took my spotlight lmao