Write a program in the c programming language to print all the even numbers up to the inputted number by using the for loop statement. Below is the solution of the C program –
/* Write a C Program to print all the even numbers up to the inputted number*/ #include<stdio.h> void main() { int i,n; printf("Enter any number \n"); scanf(" %d ",&n); printf("even numbers up to inputted number are - \n"); for(i=2;i<=n;i+=2) { printf(" %d \t",i); } getch(); }
Input- Enter any number – 20
Output- Even numbers up to inputted number are – 2 4 6 8 10 12 14 16 18 20
There is also a second method to make this same program. You can also use ‘ if ‘ statement in the for loop section of the program to print the even numbers. Below is the for loop section of the same C program –
for(i=1;i<=n;i++) { if(i%2=0) { printf("%d t",i); } }
Nice progtaming
Nice programming and essy solution
Best formula
thanx for programming but i want to know the logic behind this program
.
i mean how this increment operator worked
Temp=0+n;
Sum=tem+n;
Printf(“even no’s:=%d”,Sum);
Im give logic.its too help to show the even no……..
#include
#include
int main() {
int num1,num2,i;
printf(“Enter the Starting number : “);
scanf(“%d”,&num1);
printf(“Enter the Ending number : “);
scanf(“%d”,&num2);
for(i=num1;i<=num2;i++){
if(i%2==0){
printf(" %d ",i);
}
}
}
Well, this substance has just blown up my mind!
So many interesting facts and critical examples that I am astonished and highly pleased with the information you give us.
The topic is burning as well, so I suggest I will read it as I did
with this article https://allbdlive.com/fartknocker/. Last but not least is I can share this information with friends
of mine and get their pleasure from the specified material
also. Let such info be!