求和用的float初始化,最后40分
查看原帖
求和用的float初始化,最后40分
940105
hp1596321楼主2023/3/19 22:18
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
int main()
{
	int n = 0;
	int k = 0;
	scanf("%d%d", &n, &k);
	int x = 0;
	float s1 = 0;
	float s2 = 0;
	int count1 = 0;
	int count2 = 0;
	for (int i = 1; i < n+1; i++)
	{
		if (i%k == 0)
		{
			count1++;
			s1 = s1 + i;
		}
		else 
		{
			count2++;
			s2 = s2 + i;
		}
	}
	printf("%.1lf %.1lf", s1 / count1, s2 / count2);
	/*printf("%.1lf %.1lf", s1*1.0 / count1, s2*1.0 / count2);*/
	return 0;
}
2023/3/19 22:18
加载中...