Created
September 15, 2017 14:47
-
-
Save muhammadmuzzammil1998/555d7c316a2686820bbe06589cc3b0fd to your computer and use it in GitHub Desktop.
Carl Friedrich Gauss's anecdote of how he summed up 1 to 100 in an interesting manner using a for loop.
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
/* | |
* I was reading about Carl Friedrich Gauss's anecdote of how he summed up 1 to 100 | |
* in an interesting manner. So, I wanted to make it with a loop (I know, I am a | |
* lazy guy) and came up with this pretty quickly... so quickly that I thought I did | |
* it wrong but the output was same as the great mathematician. But I think that | |
* there is some another and easy way to do this, right? | |
*/ | |
#include <stdio.h> | |
int main() { | |
int i, j; | |
for (i = 0, j = 100; j > 0; i += j, j--); | |
printf("%d", i); | |
return 0; | |
} | |
// Output: 5050 |
nabeelomer: So the point of comment?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So the point of the exercise?