This repository has been archived on 2023-10-26. You can view files and clone it, but cannot push or open issues or pull requests.
VSMechatronics/C9/ex8.c
2023-10-06 13:47:33 +01:00

33 lines
527 B
C

#include <stdio.h>
int main() {
int rc, start, end, sum = 0;
printf("Start: ");
rc = scanf("%d", &start);
if (rc != 1) {
printf("Please enter a real integer\n");
return 1;
}
printf("End: ");
rc = scanf("%d", &end);
if (rc != 1) {
printf("Please enter a real integer\n");
return 1;
}
if (start > end) {
printf("Please ensure that start value is smaller than end value\n");
return 1;
}
for (int i = start; i <= end; i++) {
printf("%d\n", i);
sum += i;
}
printf("Sum: %d\n", sum);
return 0;
}