Here is the question: Write a program containing a function that takes has 2 integer parameters x and y and
returns the value of x^2 + y^2.
My codes:

int Myfun(int x,int y);
int main()
    int n,p,k,sum=0;

    printf("Enter 1st integer: ");
    scanf("%d", &n);
    printf("Enter 2nd integer: ");
    scanf("%d", &p);


    printf("%d\n", sum);

    return (1);

int Myfun(int x, int y)
    int n,p,sum=0;

    sum = sum+(n*n)+(p*p);

    return (sum);


ny problem is when i enter the two integers suppose 2 and 2 it should have given the output of 8 but instead it gives a different output. Need help about what is wrong with my codes?

Edited by nitish.mohiputlall: missed something

4 Years
Discussion Span
Last Post by robsonminag

The output of your function will always be zero. Try to figure that out!
Write a single line in your function: return x*x + y*y;

Edited by ddanbe: change edit


tell me the numbers and an answer for those two numbers, email me those numbes at laequi@yahoo.com and I´ll email you back the right code for that.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.