Printing even numbers till nth number using continue statement in C

 Continue Statement : It is used when we want to continue running the loop but stop processing the remaining code in it's body for this particular iteration.

Code goes like this : 

/* WAP that asks for a number a from user and then display only even numbers from 2 to n using continue statement */
#include<stdio.h>
int main()
{
    int i,num;
    printf("\n Enter a number:");
    scanf("%d",&num);
    printf("\n The even numbers from 2 to %d are:\n",num);
    for(i=1;i<=num;i++)
    {
        if(i%2!=0)
        continue;
        printf("\t%d",i);
    }
    return 0;   
}

Output : 

Share on Google Plus

About Nepali Xoro

Interested in Information Technology, Spreading Knowledge for Nepalease IT Students."Loves Traveling", Listen Music and Surfing web.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment