0
Please help me for interview question
Is anyone know how to solve this problem using java or c++ Input One number (N) where (N) is a positive integer Output: Countdown feom 100 to the number (N) separste even and odd numbers. Show even numbers in the first line and odd nunbers in the second line Test case Input 10 Output 100 98 96 94 92 99 97 95 93 91 Input 5 Output 100 98 96 99 97
4 Respuestas
+ 1
This code is your python version in C++
#include <iostream>
#include <vector>
using namespace std;
void print(vector<int> v){
for (int i = 0; i < (int) v.size(); i++){
cout << v[i] << " ";
}
cout << endl;
}
int main() {
int input;
cin >> input;
vector<int> odd, even;
for (int i = 0; i < input; i++){
if(i%2==0){
even.push_back(100-i);
}else{
odd.push_back(100-i);
}
}
cout<<"Even: ";
print(even);
cout<<"Odd: ";
print(odd);
return 0;
}
https://code.sololearn.com/cQq9qv56V82K/?ref=app
+ 1
I solved it with JAVA :
https://code.sololearn.com/cXjNUbNwjYoS/?ref=app
0
I just understand python language, but the company suggest me to use java or c ++, i apply for bootcamp program to a company.
Here my attempt using python
n = input('input your number ? ')
a = int(n)
b = [ ]
c = [ ]
for i in range(a)
If i%2 == 0:
b.append(100-i)
else:
c.append(100-i)
print(b)
print(c)
I am just confused, how to print in one line separately without using list
Please help me to solve this problem.
Thanks
0
Wah thanks for all suhu 🙏