(i)Write a function in C Programming Language, isEven(), that takes an
integer value as argument and returns 1 if the latter is even, otherwise
returns 0 (zero).

(ii)The function isEven() is saved to the file 'usefulfunctions.h'. You are
required to write a C program that allows the user to enter integer
numbers. To end we use 0 (zero) as the last number. Your program
should make use of the isEven() function from 'usefulfunctions.h' and print
the odd numbers on screen.

I am having difficuty to answer the second part. I can not even start it. Help?

Recommended Answers

All 7 Replies

Do the assignment one small step at a time and you will soon be finished. First write the program to ask for the integers. Do you know how to use printf() and scanf()? Once you get that compiled and tested continue with the function IsEven(). Use the % mod operator to find out if the integer is odd or even. Any Number % 2 will tell you that. With that you should be able to finish the assignment.

yeah i did it. But its the second part of the question that i am stuck :( .

that allows the user to enter integer numbers.

Can you do that bit?

the first part i did try it. but the second part "to write a C program that allows the user to enter integer numbers. To end we use 0 (zero) as the last number. Your program
should make use of the isEven() function from 'usefulfunctions.h' and print
the odd numbers on screen." i am stuck with this

you need an infinite loop that does four four things

  1. display a prompt, such as "Enter an integer"
  2. Get user input using scanf() function
  3. Call IsEven() to determine if the integer is odd or even
  4. If odd print the number on the screen

Please post all the code you have written so far so that we can see what you have done.

include<stdio.h>
include<stdlib.h>
int isEVEN(int x);
int main()
{
    int one;
    int r;
    scanf("%d", &one);
    printf("%d", isEVEN(one));

    system("pause");
    return 0;
    }
int isEVEN(int x, int y)
{
    int r;
    while(x!=0);
    {
        r=x%2;
        if(r==0)
        return x=1;
        else
        return x=0;
}
}


This is for (i)

You don't need a loop in IsEven(). That function should have only one parameter, the integer that is to be tested (see the function prototype at line 1 of your program). Do remove the second parameter, and delete lines 14, 15, 16 and 22.

Your program also needs to include stdio.h using the #include statement.

After you have done the above, put lines 6 and 7 in a loop that terminated when you enter 0 for the integer.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.