Find elements

C program to display all odd or even numbers 1 to n with label

C program to display all odd or even numbers 1 to n with label

In this article, we will discuss the concept of C  program to display all odd or even numbers from 1 to n with label using loops

In this post, we will learn how to find and display odd and even numbers from 1 to n with label using the loops.

Here, we will use for loop, while loop and do-while loop to find and display odd and even numbers from 1 to n in C programming language.

C program to display the odd or even numbers with label using loops

Using for loop

program 1

This program allows the user to enter the maximum numbers. It finds and displays even and odd numbers with the label from 1 to entered number using for loop.

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int num,i;
    printf("Enter the random number \n");
    scanf("%d",&num);//Takes input from the user

    printf("Display all odd and even number till %d",num);

printf("\n\n");

for(i=1; i<=num; i++){
    if(i%2==0){//Using modular operator to find odd or even
        printf("%d",i);
                printf(" Is Even");
        printf("\t");
    }

    else{
        printf("%d",i);
                printf(" Is Odd\t");
    }

}
getch();
    return 0;
}

When the above code is executed, it produces the following results

Odd and even numbers with label using for loop

 

Using while loop

program 2

This program allows the user to enter the maximum numbers. It finds and displays even and odd numbers with label 1 to entered number using while loop.

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int num,i;
    printf("Enter the random number \n");
    scanf("%d",&num);

    printf("Display all odd and even number till %d",num);

printf("\n\n");

i=1;
while( i<=num){
    if(i%2==0){
        printf("%d",i);
                printf(" Is Even");
        printf("\t");
    }

    else{
        printf("%d",i);
                printf(" Is Odd\t");
    }
     i++;

}
getch();
    return 0;
}

When the above code is executed, it produces the following results

Odd and even numbers using for loop with label

Using do-while loop

Program 3

This program allows the user to enter the maximum numbers. It finds and displays even and odd numbers with label 1 to entered number using do-while loop.

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int num,i;
    printf("Enter the random number \n");
    scanf("%d",&num);

    printf("Display all odd and even number till %d",num);

printf("\n\n");

i=1;
do{
    if(i%2==0){
        printf("%d",i);
                printf(" Is Even");
        printf("\t");
    }

    else{
        printf("%d",i);
                printf(" Is Odd\t");
    }
     i++;

}while( i<=num);
getch();
    return 0;
}

When the above code is executed, it produces the following results

Odd and even numbers using for loop with label

 

Similar post

C program to find the number is odd or even withusing loops

C++ program to find the number is odd or even withusing loops

Python program to find the number is odd or even withusing loops

 

Suggested for you

C language for loop

C language while loop

C language do-while loop

C language data type

C language variable

C language operator

 

 

Java program to check whether a number is Positive or Negative or Zero
C++ program to display all odd or even numbers 1 to n with label
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago

Java program to check odd or even using recursion

Java program to check odd or even using recursion In this tutorial, we discuss a…

2 months ago