By using while loop and add all the even numbers and odd numbers from 1 to 50.
Answers
Explanation:
Print all odd number until
50
Odd number from 1 to 50 are
1
3
5
7
9
11
13
15
17
19
21
23
25
27
29
31
33
35
37
39
41
43
45
47
49
Program 5
In this program, we print all even number from 1 to n using the do-while loop
Print all even number using do -while loop
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,num;
printf("Print all even number until \n");
scanf("%d",&num);//Reads input from user and stored in variable num
printf("Even number from 1 to %d are\n",num);
i=1;
do{//loop for iterates from 1 to maximum
if(i%2==0)
{
printf("%d\n",i);
}
i++;
}
while(i<=num);
getch();
return 0;
}
When the above code is executed, it produces the following results
Print all even number until
50
Even number from 1 to 50 are
2
4
6
8
10
12
14
16
18
20
22
24
26
28
30
32
34
36
38
40
42
44
46
48
50
Program 6
In this program, we print all odd number from 1 to n using the do-while loop
Print all odd number using do while loop
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,num;
printf("Print all odd number until \n");
scanf("%d",&num);//Reads input from user and stored in variable num
printf("Odd number from 1 to %d are\n",num);
i=1;
do{//loop for iterates from 1 to maximum
if(i%2==1)
{
printf("%d\n",i);
}
i++;
}
while(i<=num);
getch();
return 0;
}
When the above code is executed, it produces the following results
Print all odd number until
50
Odd number from 1 to 50 are
1
3
5
7
9
11
13
15
17
19
21
23
25
27
29
31
33
35
37
39
41
43
45
47
49
Suggested for you
For loop in C language
While loop in C language
Do while loop in C language
Operator in C language
Data type in C language
Variable in C language
Java code to display all even or odd number from 1 to n
C program to separate Odd and Even numbers from an array
Related posts:
program to find largest number among three numbers in Java
C program to find middle among three number using function
Java program: Find the frequency of each character in the string
program to display even and odd number in the given range
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.
NEXT Electricity bill Calculation program using function in Cpp »
PREVIOUS « Java code to display all even or odd number from 1 to n
Leave a Comment
SHARE
PUBLISHED BY
Karmehavannan
TAGS:
C examplesC languageoperator
2 YEARS AGO
RELATED POST
Python code: Find the frequency of each character in the string
C++ program: Find the frequency of each character in the string
C program: Find the frequency of each character in the string
RECENT POSTS
CALCULATIONS
Use of C program to subtraction of two numbers using recursion
Use of C program to subtraction of two numbers using recursion In this tutorial, we…
5 months ago
CALCULATIONS
Use of C++ program to subtraction of two numbers using recursion
Use of C++ program to subtraction of two numbers using recursion In this tutorial, we…
5 months ago
CALCULATIONS
Use of Java program to subtraction of two numbers using recursion
Use of Java program to subtraction of two numbers using the recursion In this tutorial,…
5 months ago
CALCULATIONS
Java program to subtract two number using method
Java program to subtract two number using method In this tutorial, we will discuss the Java…
5 months ago
CALCULATIONS
Python program to subtract two number using Function
Python program to subtract two number using Function In this tutorial, we will discuss the Python…
5 months ago
CALCULATIONS
C++ program to subtract two number using Function
C++ program to subtract two number using Function In this tutorial, we will discuss the…
5 months ago
FIND US
Address
Global information technology
Puloly south, PointPedro
Jaffna, Srilanka
Hours
Monday—Friday: 9:00AM–5:00PM
Saturday & Sunday: 11:00AM–3:00PM
ARCHIVES
Archives
FOOTER MENU
About Us
disclaimer
Privacy Policy
Contact
CATEGORIES
Categories
TAG
"String.h" header file in c language (17) C++ patterns (30) C++ programs (68) C examples (72) C language (158) concept in Oop (5) C pattern (38) Cpp language (125) Data structure (11) Data types and variables (1) difference between (1) Exception (2) flow of control (40) Function in C (7) function in Python (2) Hello world (4) history (1) inheritance (1) Java language (170) Java pattern (30) Java programs (64) keyword in Java (41) methods (13) operator (95) Pattern (101) pointer programs (3) pre-defined function (15) Python 3.0 (12) Python language (57) python program (39) Referance /object Data types (1) User defined function (5) “math.h” header file (16)