C Program to Calculate Simple Interest
Simple Interest is calculated on the principal amount for a given rate of interest and time period. It is commonly used in basic mathematical and financial calculations.
साधारण ब्याज की गणना मूलधन राशि, ब्याज दर तथा समय अवधि के आधार पर की जाती है। इसका उपयोग सामान्य गणितीय एवं वित्तीय गणनाओं में किया जाता है।
Formula of Simple Interest
Simple Interest = (P × R × T) / 100Where:
P = Principal Amount (मूलधन)
R = Rate of Interest per Year (वार्षिक ब्याज दर)
T = Time in Years (समय वर्षों में)
C Program
File Name: si.c
#include <stdio.h>int main(void){float p, r, t, si;printf("Enter Principal, Rate and Time:\n");if (scanf("%f %f %f", &p, &r, &t) != 3){printf("Invalid input!\n");return 1;}if (p < 0 || r < 0 || t < 0){printf("Values cannot be negative.\n");return 1;}si = (p * r * t) / 100.0f;printf("Simple Interest = %.2f\n", si);return 0;}
Output
Enter Principal, Rate and Time:10000 5 2Simple Interest = 1000.00
Explanation
Three variables
p,r, andtare used to store the principal amount, rate of interest, and time period.The
scanf()function accepts these three values from the user.The program checks whether the entered values are valid and non-negative.
The simple interest is calculated using the formula
(p * r * t) / 100.The
printf()function displays the calculated simple interest with two decimal places.मूलधन राशि, ब्याज दर तथा समय अवधि को स्टोर करने के लिए
p,rतथाtनाम के तीन वेरिएबल का उपयोग किया गया है।scanf()फंक्शन यूजर से इन तीनों वैल्यू को इनपुट करता है।प्रोग्राम यह जाँचता है कि दी गई वैल्यू सही तथा गैर-ऋणात्मक हैं या नहीं।
(p * r * t) / 100फॉर्मूले की सहायता से साधारण ब्याज की गणना की जाती है।printf()फंक्शन गणना किए गए साधारण ब्याज को दो दशमलव स्थानों तक प्रदर्शित करता है।
Important Points
The program uses
floatdata type because principal, rate, and time may contain decimal values.%.2fdisplays the result up to two digits after the decimal point.The program uses standard C input/output functions from
stdio.h.return 0indicates successful program execution.प्रोग्राम में
floatडेटा टाइप का उपयोग किया गया है क्योंकि मूलधन, ब्याज दर तथा समय में दशमलव मान हो सकते हैं।%.2fपरिणाम को दशमलव के बाद दो अंकों तक प्रदर्शित करता है।प्रोग्राम में
stdio.hकी स्टैंडर्ड C इनपुट/आउटपुट सुविधाओं का उपयोग किया गया है।return 0सफल प्रोग्राम निष्पादन को दर्शाता है।
Comments
Post a Comment