-
-
Save kunpengku/5881479 to your computer and use it in GitHub Desktop.
1234,算出每一位的和。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
int main(int argc,char *argv[]) | |
{ | |
int source; | |
int sum = 0; | |
source = atoi(argv[1]); | |
while(source/10) | |
{ | |
sum += source%10; | |
source /= 10; | |
} | |
sum += source;//最后再加上第一位。 | |
printf("sum = %d\n",sum); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
使用 argv[1] 前,最好先判断 argc 是否大于 2