I need to write a program in c language using the bloodshed.com compiler. The pr
ID: 3640657 • Letter: I
Question
I need to write a program in c language using the bloodshed.com compiler. The program problem is called "Grains of Rice." A company agrees to pay one of its employees in grains of rice instead of money. The employee receives one grain on the first day, two grains on the second day, four grains on the third day, eight grains on the fourth day, and so on. In other words, each succeeding day the employee receives twice as many grains as the previous day. The employee works for the company for 18 days. Write a program to determine the number of grains of rice that the employee receives on each day he or she works. Also, accumulate the total rice earnings. There is no input for this program. Output should consist of (at least) 18 lines, each with the day, number, the number of grains received that day, and the accumulated number of grains received to date.Day Number or Rice Grains Total Number of Rice Total Number of Rice
1 1 1 1
2 1 x 2 = 2 1 x 2 = 2 1+2 = 3
3 2 x 2= 4 4 x 2 = 8 1+2+4 = 7
4 4 x 2 = 8 8 x 2 = 16 1+2+4+8 = 15
5 8 x 2 = 16 16 x 2 = 32 1+2+4+8+16 = 31
Can someone please help me write this program in c?
Thanks
5 16 x 2= 32
6 32 x 2= 64
Explanation / Answer
#include<stdio.h>
int main()
{
int i;
unsigned long int n,t;
n = 1;
t = 0;
printf(" Day No. of Rice grains Total no. of rice grains ");
for(i=1 ; i<=18 ; ++i)
{
t = t+n;
printf(" %d %d %d",i,n,t);
n = n*2;
}
return 0;
}