#include <stdio.h>
unsigned long long grains(int n) {
unsigned long long res = 1;
for (int i = 1; i < n; i = i + 1) {
res = res * 2;
}
return res;
}
int main() {
int x;
scanf("%d", &x);
printf("%d", unsigned long long grains(int x));
}
This code calculates the number of grains on a chessboard square (2^(n-1)) and tries to print it. The `grains` function works correctly for positive `n`, but the `main` function has a syntax error when calling it.
- In `printf`, the function call `unsigned long long grains(int x)` is written incorrectly. In C, you call a function by its name with arguments, not by redeclaring its type and parameters.
- The `printf` format specifier `%d` is for `int`, but the function returns `unsigned long long`. You need a different format specifier for that type.