课上作业补交-main参数-21-11-15

main:

#include <stdio.h>
#include <stdlib.h>

int sum(int A);

int main(int argc, char *argv[]){
	int result = 0;
	result = sum(atoi(argv[1]));
	printf("各位相加的和是:%d\n",result);

	return 0;
}

sum:

int sum(int A){
	
	int result;
	result = 0;

	while(A > 0){
		result += A%10;
		A /= 10;
	}
	return result;
}

运行截图:

posted @ 2021-11-15 18:55  20191314汇仁  阅读(25)  评论(0编辑  收藏  举报