Answers for "Write a C program to check whether a given number is even or odd and also check if is positive or negative."

C
1

c program to tell whether a number is an integer is even or odd

#include <stdio.h>
int main()
{
    int Num;
    printf("Test Data: ");
    scanf("%d", &Num);
    if(Num % 2 ==0)
    {
        printf("%d is an even integer", Num);
    }
    else
    {
        printf("%d is an odd integer", Num);
    }

}
Posted by: Guest on April-19-2021
0

a program to find the numbers of positive, negative, odd and even numbers in a set of numbers in C

#include <stdio.h>
void main ()
{
    int a[100];
    int num,i;
    printf("How many numbers do you want to enter? : ");
    scanf("%d",&num);
    fflush(stdin);
    for (i=0;i<num;i++)
    {
        printf("Enter %d number: ",i+1);
        scanf("%d",&a[i]);
    }

    int p=0,n=0,z=0,e=0,o=0;

    for(i=0;i<num;i++)
    {
        if(a[i]>0)
           p++;
        else if (a[i]<0)
            n++;
        else
            z++;

        if(a[i]%2==0)
            e++;
        else o++;
    }

    printf("Number of positive numbers entered = %dn",p);
    printf("Number of negative numbers entered = %dn",n);
    printf("Number of zeros entered = %dn",z);
    printf("Number of even numbers = %dn",e);
    printf("Number of odd numbers = %dn",o);
}
Posted by: Guest on June-24-2021

Code answers related to "Write a C program to check whether a given number is even or odd and also check if is positive or negative."

Code answers related to "C"

Browse Popular Code Answers by Language