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:

#include<stdio.h>
#include<stdlib.h>
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);

    sum=Myfun(n,p);

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

    system("pause");
    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?

Recommended Answers

All 4 Replies

It would help if you told us what the output is if it's not 8.

when i input 2 and 2 it gives me output -1229383536

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;

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.

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.