利用函数调用求 a^2 + b^2 + c^2, 其中a,b,c作为参数传入函数

利用函数调用求 a^2 + b^2 + c^2, 其中a,b,c作为参数传入函数

img

#include <stdio.h>
int f(int a,int b,int c) 
{
    return a*a+b*b+c*c;
}
int main()
{
    int a,b,c;
    printf("请输入a,b,c\n");
    scanf("%d%d%d",&a,&b,&c);
    printf("%d^2+%d^2+%d^2=%d\n",a,b,c,f(a,b,c));
    return 0;
}

#include "stdio.h"
#include <math.h>
int fun(int a, int b, int c) {
    int res = pow(a, 2) + pow(b, 2) + pow(c, 2);
    return res;
}
int main()
{
    // a^2 + b^2 + c^2
    int a, b, c;
    scanf("%d%d%d",&a,&b,&c);
    printf("%d", fun(a,b,c));
    return 0;
}