Saturday, April 12, 2014

Printing all even numbers from a user provided range

In our last post we had shown you how to directly print all even numbers from a static range. If you have not read our previous post than we recommend to read it first by clicking the link printing even numbers using for loop before reading further.

In today's post we are going to show you the C programming code to print all even numbers from any range of numbers provided by the user.  The code is given below :


   int main()
       int i,start,end;
       printf("Enter starting number : ");
       printf("Enter ending number : ");

       for (i=start;i<=end;i++)
               printf(" %d\n",i);
       return 0;


Now this is the perfect code to solve our even number problem as you can see inside the loop it checks the " i " 's value each and every time it loops to find whether the current value of i returns the remainder as zero if divided by 2 if it does then its an even number.

Hope you liked our post if you have any suggestions or query please comment.

Happy Programming !

No comments :

Post a Comment