done
This commit is contained in:
10
programs/p413/info.json
Normal file
10
programs/p413/info.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"language": "C",
|
||||
"name": "演習 4-13",
|
||||
"description": "1から$n$までの総和を求めるプログラム。",
|
||||
"output": {
|
||||
"type": "screenshot",
|
||||
"content": "./assets/p413.png"
|
||||
},
|
||||
"note": ""
|
||||
}
|
||||
BIN
programs/p413/main
Executable file
BIN
programs/p413/main
Executable file
Binary file not shown.
23
programs/p413/main.c
Normal file
23
programs/p413/main.c
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
int n;
|
||||
int sum = 0;
|
||||
|
||||
numInput:
|
||||
printf("Input integer: ");
|
||||
scanf("%d", &n);
|
||||
|
||||
if (n < 1) {
|
||||
puts("Error: Please type in non-zero positive integer.");
|
||||
goto numInput;
|
||||
}
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
sum += i;
|
||||
}
|
||||
|
||||
printf("ANS: %d", sum);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user