MSK Technologies

Home
Practice Programs
Java Programs Python Programs Java Quiz
Pages
Python Java Material PLSQL Material
Search A Job

Write a C-program to print even number or odd number based on the n value using for loop?

  1. Home
  2. C Language Programs

Write a C-program to print even number or odd number based on the n value using for loop?

Write a C-program to print even number or odd number based on the n value using for loop


#include <stdio.h>
int main() {
    int x,n;
    printf("Enter n value ");
    scanf("%d",&n);
    if(n%2==0)
    {
        for(x=1;x<=n;x++)
        {
            if(x%2==0)
            {
                printf("%d\n",x);
            }
        
        }
    }
    else
    {
        for(x=1;x<=n;x++)
        {
            if(x%2!=0)
            {
                printf("%d\n",x);
            }
        
        }
    }
  
    return 0;
}

Output:

Enter n value 20
2
4
6
8
10
12
14
16
18
20


Enter n value 21
1
3
5
7
9
11
13
15
17
19
21




More Programs


42 . Write a C-program to print even number or odd number based on the n value using for loop
43 . Write a C-program to print even number or odd number based on the n value using single for loop
44 . Write a C-program to count the number of divisible numbers in a given range(1-100)
45 . Write a C-program to print count the number of divisible numbers in a given range(1-100) without using loop
46 . Write a C-program to print factorial number using for loop
47 . Write a C-program to print factorial of n numbers using for loop
48 . Write a C-program to print sum of natural numbers using for loop
49 . Write a C-program to print sum of even numbers using for loop
50 . Write a C-program to print sum of odd numbers using for loop
51 . Write a C-program to print sum of even or odd numbers based on the n value using for loop
52 . Write a C-program to print sum of even or odd numbers based on the n value using single loop



Apply For The Job

Apply For Job

Java Material

Python Material

PLSQL Material

.Net Material

Java Practice Programs

400 Java Programs

Java Practice Programs

Write a java Program to check the given number is Palindrome or not

Write a Java program to check whether Java is installed on your computer or not

Write a Java program to compare two numbers

Write a Java Program to find Armstrong number

Write a Program to remove duplicate element in an array

Python Practice Programs

Python Program to Replace all Occurrences of ‘a’ with $ in a String

Write a python program to print lowercase names

Write a Python Program to check armstrong number of n digits

Write a python program to Checking if a File Exists or Not ?

Print out a set containing all the colors from a list which are not present in other list

Java Quiz

Java Quiz - 21

Java Quiz - 15

Java Quiz - 5

Java Quiz - 7

Java Quiz - 9

Courses
Java Python PLSQL .Net ADO.Net About Us
Quick Links
Daily Use English Sentences Daily General Knowledge General Knowledge Latest Update Inventions and Inventors జనరల్ నాలెడ్జ్ General Knowledge Spoken English Spoken Hindi GK Hindi Telugu Facts Unknown Facts Psychology Facts Motivation Quotes విటమిన్ - సి,డి,ఇ,కె Android
Spiritual
రాధాకృష్ణ భగవద్గీత Motivation Quotes Slokas Talapatra Nidhi ఆధ్యాత్మిక భక్తి ప్రపంచం Sadhguru Sai Motivation Quotes గౌతమ బుద్ధుడు Bhagavad Gita Quotes
Newsletter

Dolor amet sit justo amet elitr clita ipsum elitr est.

© sateeshm, All Right Reserved. Designed By sateeshm
Home Help FQAs