c语言中定义函数和调用函数(将函数的返回值作为参数传递给其他函数,计算平方差)
1、将函数的返回值作为参数传递给其他函数,计算平方差
#include <stdio.h>
int sqr(int x)
{
return x * x;
}
int diff(int a, int b)
{
return (a > b ? a - b : b - a);
}
int main(void)
{
int n1, n2;
puts("please input two integers!");
printf("n1 = "); scanf("%d", &n1);
printf("n2 = "); scanf("%d", &n2);
printf("the diff is %d\n", diff(sqr(n1), sqr(n2)));
return 0;
}