Answer to Question #278791 in C++ for Ralph

Question #278791

Write a program that a the user to enter a number n display the first and odd number example if N is equal to five the first five odd numbers are 1,3,5,7,and 9.


1
Expert's answer
2021-12-12T12:19:17-0500
#include<iostream>
using namespace std;
int main(){
	cout<<"Enter a number:  ";
	int n;
	cin>>n;
	int x = 1;
	int count = 0;
	while(true){
		if(x%2 !=0){
			cout<<x<<" ";
			count++;
		}
		x++;
		if(count==n){
			break;
		}
	
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog