Created
June 5, 2019 02:17
-
-
Save ghoomfrog/83cf10281fea7994d3a931db5a4a1b83 to your computer and use it in GitHub Desktop.
Program to quickly sum integers from a start to an end.
This file contains hidden or 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> | |
#include <stdlib.h> | |
int main(int argc, char** argv) { | |
// if at least 2 arguments are given to the program | |
if (argc > 2) { | |
// first integer | |
long long f = atoll(argv[1]); | |
// last integer | |
long long l = atoll(argv[2]); | |
printf("%lli\n", (long long)((((l-f)+1)/2.0)*(f+l))); | |
} | |
// if 1 arguments is given to the program | |
else if (argc == 2) { | |
// last integer | |
long long l = atoll(argv[1]); | |
printf("%lli\n", (l/2)*(1+l)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment