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.
#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;
}
}
}
Comments
Leave a comment