EVEN NUMBER

Q. Write a C Program to check whether the given number is Even or Not.

#include<stdio.h>
main()
{
    int num;
    scanf("%d",&num);
    if(num%2==0)
    printf("Even Number");
    else
    printf("ODD Number");
    }


Q. Write a C Program to Print first 10 Even Number starting from 1. Use For Loop, If-Else and Break;

#include<stdio.h>
main()
{
        int i,cnt=0;
        for(i=1; ;i++)
        {
            if (i%2==0)
                {
                cnt=cnt+1;
                if (cnt<=10)
                    printf("%d ",i);
                else
                    break;
                }
        }
}

4 comments:

  1. #include
    #include
    int main()
    {
    int i;
    for (i =0;i<=10;i=i+2)
    {
    printf("%d",i);
    }
    getch();
    return (0);

    or......


    #include
    #include
    int main()
    {
    int i;
    for (i =0;i<=10;i=i+2)
    {
    printf("\n");
    printf("%d",i);
    }
    getch();
    return (0);

    or......


    #include
    #include
    int main()
    {
    int i;
    int n;
    printf("program to print even number\n Enter tha limit:");
    scanf("%d",&n);
    for (i =0;i<=10;i=i+2)
    {
    printf("\n");
    printf("t\t%d",i);
    }
    getch();
    return (0);
    sir this..program easygoing..
    but some problem! exactly...output is not old program...

    ReplyDelete
  2. #include
    main()
    {
    int m=8;
    if(m%2==0)
    {
    printf("The m is even number");
    }
    else
    {
    printf("The m is odd number");
    }
    }

    ReplyDelete
  3. #include
    int main()
    {
    int r,num=0;
    for(r=1; ;r++)
    {
    if(r%2==0)
    {
    ++num;
    if(num<=10)
    printf("%d ",r);
    else
    break;

    }
    }
    }

    ReplyDelete