146k views
3 votes
Write a program that calculates how many days it takes to accumulate at least $1,000,000 if someone deposits one penny on the first day, two pennies the second day, four pennies on the third day and continues to double each day. The output should display the number of days.

Java Script.

User Jfmg
by
5.0k points

1 Answer

2 votes

Answer:

#include<stdio.h>

int DaysRequired(double);

void tableHeader();

void tableHeader(){

printf("DAYS DEPOSIT BALANCE \\");

}

int DaysRequired(double money){

double deposit=0.01;

double balance=0.01;

int days=1;

tableHeader();

printf("%-10d%-15.2f%-15.2f\\",days,deposit,balance);

while(balance<money){

days++;deposit*=2;balance+=deposit;

printf("%-10d%-15.2f%-15.2f\\",days,deposit,balance);

}

return days;

}

int main(){

double amount;

int days;

printf("Enter Amount of money you want to Accumulate :");

scanf("%lf",&amount);

days=DaysRequired(amount);

printf("No of Days Required %d\\",days);

return 0;

}

Step-by-step explanation:

See attached image for the output

Write a program that calculates how many days it takes to accumulate at least $1,000,000 if-example-1
User Mike Muller
by
4.9k points