In this post I will tell you how to write C program to calculate Simple Interest . So, without any further delay let's get started.
Code:
#include<stdio.h>
int main(){
int principal;
float rate,time,simpleInterest;
printf("Enter principal amount \n");
scanf("%d",&principal);
printf("Enter rate of interest\n");
scanf("%f",&rate);
printf("Enter time(means year)\n");
scanf("%f",&time);
simpleInterest=(principal*rate*time)/100;
printf("Simple Interset=%f\n",simpleInterest);
return 0;
}
Logic: We know that in S.I.=P*R*T/100 .Here P means principal amount ,R means rate at which it is increasing. And last T is time for which money is given .And multiplication of P*R*T divides by 100 . Gives us Simple Interest .Now I show you code screen shot for your comfort . I paste screen shot Here int principal; is called variable declaration in c language and here int is datatype means simply we said to compiler that you take value in principal in form of integer numbers .Float is also datatype and I will discuss this particular topic in detail in another post. And scanf here take value in variables using format specifier like %d for int ,%f for float etc. And you will eager to see output of this program.
Output:
And I hope you will try by yourself on your pc and also try for other numbers . And last most important tip for you guys that always &(means at this address ) while taking input through user.
I hope this might helpful to you.
Thanks for reading
No comments:
Post a Comment