Please write and comment in C-CODE Please write and comment in C-CODE You may re
ID: 640954 • Letter: P
Question
Please write and comment in C-CODE
Please write and comment in C-CODE You may remember that old story about the inventor of chess and how happy that king was for this invention. He rewarded the inventor.. In our version we will assume that we put corn kernels on the chessboard, best regards from Monsanto! Write a function double() to compute the overall amount of corn that will be on the chessboard. Compute the weight and compare the overall weight to the world corn production. Google all necessary data.Explanation / Answer
#include <stdio.h> // printf
#include <math.h> // pow
// this function calculates the number of corn on chessboard and returns the value
double calculate(){
int num = 64, i = 0; // num is number of chessboard squares(64)
double sum = 0; // Initialize sum to 0
// this for loop does sum = 2^0 + 2^1 + ... + 2^63
// since, every time it goes through the loop we are adding 2^i to the sum
// and i value goes from 0 to 63
for(i = 0; i < num; ++i){
sum += pow(2, i);
}
// return the value
return sum;
}
int main(){
printf("Total Number of corn Kernels are %.0f ", calculate());
// print number of corn kernels
return 0;
}