Friday, 21 November 2014

Break up the program that you wrote to solve above problem into two separate source files. The main function should be in one file & the calculation function must be in another file. And modify the program so that the interest rate is a symbolic constant and is no longer input from the keyboard. And put all the C preprocessor directives into a separate header file that is included in the two program source files.

#include "header.h"
main()
{
            float amt,interest;
            int year;

            float comp_int_calc(float,float,int);

            clrscr();

            printf("Enter the initial amount: ");
            scanf("%f",&amt);

            printf("Enter the Number of years: ");
            scanf("%f",&year);

            interest=comp_int_calc(amt,roi,year);
            printf("\nThe int is %.2f",interest);
            getch();
}


file-2.c

#include "header.h"
float comp_int_calc(float x,float y,int z)
{
            float i;
            i=x*pow((1+y/100),2);
            return(i-x);
}

header.h

#include<stdio.h>
#include<math.h>
#define roi 10

Then press Alt+P in Turbo C and enter a project file name, e.g. Q11.prj. Create a new project file of the same name e.g. Q11.prj and enter the following in it-

file-1.c
file-2.c
header.h

Now compile the project file and the desired output will be obtained.

No comments:

Post a Comment

Please write your doubts