Algorithm training for sum of squares

问题描述
  请用函数重载实现整型和浮点习型的两个数的平方和计算
输入格式
  测试数据的输入一定会满足的格式。
  2 222列,第1行整型,第2行浮点型)
输出格式
  要求用户的输出满足的格式。
  2 121列,第1行整型,第2行浮点型)
样例输入
一个满足题目要求的输入范例。
例:
2 2
3 4
3.1 4.1
样例输出
与上面的样例输入对应的输出。
例:
25
26.42
数据规模和约定
  输入数据中每一个数的范围。
  例:0<n,m<100, 0<=矩阵中的每个数<=1000

This question is not difficult, just pay attention to the output accuracy. But the author is a bit puzzled, the title requires the use of function overloading, I used the C language, and wrote the following code.

#include<stdio.h>
void pow(int a,int b){
    
    
	printf("%d\n",a*a+b*b);
}
void pow(double c,double d){
    
    
	printf("%0.2lf",c*c+d*d);
}
int main(){
    
    
	int a,b,m;
	double c,d,n;
	scanf("%d%d",&a,&b);
	scanf("%lf%lf",&c,&d);
	pow(a,b);
	pow(c,d);
	return 0;
}

Submitted on the official website of the Blue Bridge Cup showed a compilation error. The author thinks that the function is overloaded and the method name should be the same, but the author does not know what is going on when such an error is reported, but when I change it to two different method names It runs correctly.

Insert picture description here
After changing the method name

#include<stdio.h>
void pow1(int a,int b){
    
    
	printf("%d\n",a*a+b*b);
}
void pow2(double c,double d){
    
    
	printf("%0.2lf",c*c+d*d);
}
int main(){
    
    
	int a,b,m;
	double c,d,n;
	scanf("%d%d",&a,&b);
	scanf("%lf%lf",&c,&d);
	pow1(a,b);
	pow2(c,d);
	return 0;
}

Insert picture description here

Guess you like

Origin blog.csdn.net/mjh1667002013/article/details/114944393
Recommended