Compare commits

...

4 Commits

Author SHA1 Message Date
BuildTools
f8373a9288 Removed comments
Signed-off-by: BuildTools <unconfigured@null.spigotmc.org>
2021-01-03 16:58:42 -05:00
BuildTools
ac760d6f42 :(
Signed-off-by: BuildTools <unconfigured@null.spigotmc.org>
2021-01-03 16:57:36 -05:00
BuildTools
7cec159017 added prompt for end
Signed-off-by: BuildTools <unconfigured@null.spigotmc.org>
2021-01-03 16:46:18 -05:00
BuildTools
aa17c68aa5 taking input from file
Signed-off-by: BuildTools <unconfigured@null.spigotmc.org>
2021-01-03 16:45:34 -05:00

11
sum.c
View File

@@ -11,11 +11,14 @@ int main() {
int size = 1; int size = 1;
int sum = 0; int sum = 0;
int pos = 0; int pos = 0;
int end_scan = 1;
int* arr = malloc(size * sizeof(int)); int* arr = malloc(size * sizeof(int));
while(TRUE) { while(end_scan) {
printf("Enter a number: "); printf("(Type EOF to end) Enter a number: ");
scanf("%d", &(arr[pos])); if (scanf("%d", &(arr[pos])) == EOF) {
end_scan = 0;
}
if( arr[pos] == 0 ) { if( arr[pos] == 0 ) {
break; break;
} }
@@ -30,7 +33,7 @@ int main() {
} }
free(arr); free(arr);
printf("You sum is: %d\n", sum); printf("Your sum is: %d\n", sum);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }