Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please write and comment in C language only, to recieve points You may remember

ID: 640955 • Letter: P

Question

Please write and comment in C language only, to recieve points

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;
}