In this tutorial you will learn about the C Program to Print Odd Numbers in Array and its application with practical example.
C Program to Print Odd Numbers in Array
In this tutorial, we will learn to create a C program that will Print Odd Numbers in Array using C programming.
Prerequisites
Before starting with this tutorial we assume that you are best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- While loop in C programming.
- Conditional Statements in C programming.
- Arithmetic operations in C Programming.
Program to Print Odd Numbers in Array
In c programming, it is possible to take numerical input from the user and Print Odd Numbers in Array with the help of a very small amount of code. The C language has many types of header libraries which has supported function in them with the help of these files the programming is easy.
The odd numbers are those numbers that are not completely divisible by 2. which means the reminder should not be zero.
With the help of this program, we can Print Odd Numbers in Array.
Algorithm:-
1 2 3 4 5 6 7 8 9 |
1. Declaring the variables for the program. 2. Taking the input number from the user. 3. Storing in array. 4. Calculating the odd numbers from the array. 5. Printing the result numbers. |
Program to Print Odd Numbers in Array:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#include <stdio.h> int main() { //declaring the variables for the program int arry[5],i; //taking input from the user printf("Enter 5 Numbers:\n"); /*For accepting 5-integer numbers from user*/ for(i=0;i<5;i++) scanf("%d",&arry[i]); //printing the odd numbers in the out put printf("Odd Numbers in Array are:\n"); for(i=0;i<5;i++) { if(arry[i]%2!=0) //Check number is odd printf("%d ",arry[i]); } return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- arry[5]= it will hold the integer value of the input.
- i = it will hold the integer value.
Input message for the user for five integer values.
Input for loop for taking array elements.
Program Logic Code.
Printing output odd digits