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> | |
| uint64_t square(uint8_t index) { | |
| // the number of grains on a given square | |
| if (index < 1 || index > 64) { | |
| return 0; | |
| } | |
| return (uint64_t)1 << (index - 1); | |
| } |
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
| // Calculates (1 + 2 + ... + n)^2 | |
| unsigned int square_of_sum(unsigned int n) { | |
| unsigned int sum = (n * (n + 1)) / 2; | |
| return sum * sum; | |
| } | |
| // Calculates (1^2 + 2^2 + ... + n^2) | |
| unsigned int sum_of_squares(unsigned int n) { | |
| return (1LL * n * (n + 1) * (2 * n + 1)) / 6; | |
| } |
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
| bool leap_year(int year){ | |
| if(year % 400==0 || (year % 4 == 0 && year % 100! =0)) { | |
| printf("%d is a leap year\n", year); | |
| return true; | |
| } | |
| return 0; | |
| } |