Pages

Friday, July 1, 2016

C Program to Calculate Simple Interest based on given values.


#include<stdio.h>
int main()
{
 float p, r, n, si;
 
 printf("Enter your principle amount:");
 scanf("%f",&p);
 
 printf("Enter your rate of interest:");
 scanf("%f",&r);
 
 printf("Enter number of years:");
 scanf("%f",&n);
 
 si = (p*r*n)/100;
 
 printf("Simple Interest is %.2f", si);
 return 0;
}

Output of program

Enter your principle amount:1000
Enter your rate of interest:12
Enter number of years:2
Simple Interest is 240.00

2 comments:

  1. why is written %2f in printing si

    ReplyDelete
    Replies
    1. %.2f will help us in printing a number with two decimal points (like 240.00).

      Delete