当前位置:网站首页>Implement a simple function to calculate the sum of all integers between M ~ n (m < n)

Implement a simple function to calculate the sum of all integers between M ~ n (m < n)

2022-04-23 18:02:00 OceanKeeper1215

Function interface definition :

int sum( int m, int n );

Sample referee test procedure :

#include <stdio.h>

int sum(int m, int n);

int main()
{    
    int m, n;

    scanf("%d %d", &m, &n);
    printf("sum = %d\n", sum(m, n));

    return 0;
}

/*  Your code will be embedded here  */

sample input :

-5 8

sample output :

sum = 21

My answer :

int sum(int m,int n)
{
	int he;
	for(m,n;m<=n;m++){
		he=he+m;
	}
	return he;
}

版权声明
本文为[OceanKeeper1215]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230545105387.html