Answer to Question #192591 in C for Prasanna

Question #192591

A worker takes a job for 5 days. His pay for the day 1 is Rs. X, for day 2 is Rs. 2X and so on. Develop a C program to find the total salary.


1
Expert's answer
2021-05-12T14:56:47-0400
#include <stdio.h>

double salary(double firstDay, int nDays) {
    double totalSalary = 0;
    int i;

    for (i=1; i<=nDays; i++) {
        totalSalary += i*firstDay;
    }
    return totalSalary;
}

int main() {
    double x, totSalary;

    printf("Enter a salary for the first day (Rs.): ");
    scanf("%lf", &x);
    totSalary = salary(x, 5);
    printf("The salary total job is Rs. %.2lf\n", totSalary);

    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Assignment Expert
13.05.21, 09:23

Dear Prasanna S.K, You're welcome. We are glad to be helpful. If you liked our service please press like-button beside answer field. Thank you!

Prasanna S.K
13.05.21, 07:17

Thanks you very much It's really very helpful

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS