C语言中求两个整型的平均值(保留浮点数)
1、
#include <stdio.h>
int main(void)
{
int a, b;
puts("please input two integer.");
printf("a = "); scanf("%d", &a);
printf("b = "); scanf("%d", &b);
printf("(a + b) / 2 = %d\n", (a + b) / 2);
return 0;
}
↓
#include <stdio.h>
int main(void)
{
int a, b;
puts("please input two integer.");
printf("a = "); scanf("%d", &a);
printf("b = "); scanf("%d", &b);
printf("(a + b) / 2 = %f\n", (a + b) / 2);
return 0;
}
↓
#include <stdio.h>
int main(void)
{
int a, b;
puts("please input two integer.");
printf("a = "); scanf("%d", &a);
printf("b = "); scanf("%d", &b);
printf("(a + b) / 2 = %f\n", (a + b) / 2.0);
return 0;
}
↓
#include <stdio.h>
int main(void)
{
int a, b;
puts("please input two integer.");
printf("a = "); scanf("%d", &a);
printf("b = "); scanf("%d", &b);
printf("(a + b) / 2 = %f\n", (double)(a + b) / 2);
return 0;
}