accept ten numbers and print only odd numbers
Answers
// C++ program to print all Even
// and Odd numbers from 1 to N
#include <bits/stdc++.h>
using namespace std;
// Function to print even numbers
void printEvenNumbers(int N)
{
cout << "Even: ";
for (int i = 1; i <= 2 * N; i++) {
// Numbers that are divisible by 2
if (i % 2 == 0)
cout << i << " ";
}
}
// Function to print odd numbers
void printOddNumbers(int N)
{
cout << "\nOdd: ";
for (int i = 1; i <= 2 * N; i++) {
// Numbers that are not divisible by 2
if (i % 2 != 0)
cout << i << " ";
}
}
// Driver code
int main()
{
int N = 5;
printEvenNumbers(N);
printOddNumbers(N);
return 0;
}
Following are the program in python for the above question :
Explanation:
number=[]#take the list to store the number.
for x in range(10):#for loop which takes the 10 value as input.
value=int(input("Enter the "+str(x+1)+" number: "))#take the input from the user.
number.append(value)#adds the value on the list.
print("The odd number are : ",end=" ")#print the message.
for x in number:#loop to check the odd number.
if(x%2!=0):#check the condition for the odd number.
print(x,end=" ")#print the odd number.
Output:
- If the user inputs from 1 to 10, the the output as "The odd number are : 1 3 5 7 9".
Code Explantion :
- The above code is in python language which prints the odd number.
- There is a list that takes the number from the user and stored on the list.
- Then the for loop scans the element of the list and check the odd number.
- Then the odd number is printed on the screen.
Learn More:
- Python :brainly.in/question/14689905