Question #313806

A man takes a job for 30 days. His pay for the first day is calculated as square

of his joining date. Assume he’s

joining on 3rd of the month, then his starting

pay is Rs 9/. After that his pay for the consecutive days are twice the pay of

previous day .i.e. each day’s pay is twice the pay of previous day. Write a c

program using functions to find his total pay for 3

0 days.



Expert's answer

#include <stdio.h>

int main()
{
    int day;
    double total;
    total = 0;        
    printf("Enter day of the month: ");
    scanf("%d", &day);
    total = total + (day * day);    // first day
    for (int i=0; i<29; i++)        // 2 .. 30 days
    {
        total = total * 2;
    }
    printf("\n\nTotal pay for 30 days (Rs): %.0f", total);
    getchar();  
}
LATEST TUTORIALS
APPROVED BY CLIENTS