Wednesday, 23 April 2014

11. Break up the program that you wrote to solve Problem 10 into two separate source files. The main function should be in one file and 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 [i.e. #include "header.h "].



file-1.c

#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