|Displaying even numbers from 1 to 20 in c| | display even numbers in c|

 C program to find even numbers from 1 to 20

code:



#include<stdio.h>
int main()
{
int i,n;
printf(" Even numbers from 1 to 20\n");
for(i=1; i<=20; i++)
{
if(i%2 == 0)
{
printf("%d\n",i);
}
}
return 0;
}

Explanation:

  • The first step is to declare the variables
  • Now we are using for loop to iterate untill 20 times
  • next we are using if statement to check the condition 
  • For example:
  • if i=3
  • then the if condition will be like "if(3%2==0)" the condition is false because 3%2 is 0.06 so the condition will not be executed 
  • after that it becomes i=4 then "if(4%2==0)" the condition is true so the statement will be executed.
  • that's all the statement gets executed untill the condition (i<=20) mets.

 

Output:


 




Comments

Popular posts from this blog

Use of Backslash "\n" in C language

COHESION AND COUPLING material

Coding and Testing in software engineering