32 Answers
New AnswerHey guys I try to resolve this problem Requirements: A natural number N is entered from the keyboard.The first N numbers that are odd are displayed in ascending order Restrictions and specifications : 0<N<1000000 Exemples: Input data: 5,3 Output data 1 3 5 7 9 1 3 5
1/26/2021 3:44:04 PM
Andrei Macovei32 Answers
New Answer> Ok and how to do that? Take the code you have written and change it according to what i wrote. I think my description is already a detailed instruction and straight forward to follow
A hint for you Andrei Macovei : as I undestood your imput are two integers separated with comma not one number. So have to receive two numbers. How, try to find out it.
It says print first N odd numbers, not odd numbers up to N. So either let nr count 1 2 3 ... N and figure out the mathematical operations to apply to each nr to get output 1 3 5 ... or start at 1, increase in steps of 2 and figure out when you have to stop
If you like this will help you Andrei Macovei : https://code.sololearn.com/cTcHQ83uJhZt/?ref=app
Andrei Macovei for this problm u need to use array u can easily do it first define a number how much u want to enter then take user input how many values u want to print
JaScript as I understood, example is really 2 examples: input => output 5 => 1 3 5 7 9 3 => 1 3 5
I tried that : #include <iostream> using namespace std; int main(){ int n,nr; cin>>n; while(nr<=n){ nr++; if(nr%2==1) cout<<nr; } return 0;}
Here i have used predefined element if u want u can take from user use cin with for loop #include <iostream> using namespace std; int main(){ int n,i=0; int array[]={1, 2, 3, 4, 5, 6 ,7 ,9 ,11, 13}; cout<<"how many numbers u want to print\n"; cin>>n; while(i<n){ if(array[i]%2==1) { cout<<array[i]<<" "; } i++; } return 0; }
Syrah Algena 0<N<1,000,000 Do you really want to write that array down? And if you fill it in a loop, then output in another loop, you can instead just output directly
Andrei Macovei you don't have to change much, just follow one of my suggestions. I'd prefer the first. Delete the if statement and instead output in every iteration, but not nr but the odd number calculated from nr 1=>1, 2=>3, 3=>5, 4=>7, 5=>9, ... 100=>199 It's just basic math
SoloLearn Inc.
4 Embarcadero Center, Suite 1455Send us a message