NBC 103 • Practical #1

Simple Interest & Temperature Conversion

Aim: To write a C program to calculate Simple Interest and convert temperatures between Fahrenheit and Celsius.

Step-by-Step Algorithm & Logic

  • 11. Start the program and include standard I/O library <stdio.h>.
  • 22. Declare float variables: principal, rate, time, si, fahrenheit, celsius.
  • 33. Read principal, rate, and time using scanf().
  • 44. Calculate Simple Interest: si = (principal * rate * time) / 100.0.
  • 55. Read temperature in Fahrenheit and convert: celsius = (fahrenheit - 32.0) * (5.0 / 9.0).
  • 66. Print calculated values with formatted decimal places and terminate.

Complete Tested Source Code

#include <stdio.h>

int main(void) {
    float principal, rate, time, si;
    float fahrenheit, celsius;

    // Simple Interest
    printf("=== Simple Interest Calculator ===\n");
    principal = 50000.0;
    rate = 7.5;
    time = 3.0;
    si = (principal * rate * time) / 100.0;
    
    printf("Principal: Rs. %.2f\n", principal);
    printf("Rate:      %.2f%% per annum\n", rate);
    printf("Time:      %.1f years\n", time);
    printf("Interest:  Rs. %.2f\n", si);
    printf("Total Due: Rs. %.2f\n\n", principal + si);

    // Temperature Conversion
    printf("=== Temperature Converter ===\n");
    fahrenheit = 98.6;
    celsius = (fahrenheit - 32.0) * (5.0 / 9.0);
    printf("%.2f F = %.2f C (Normal Body Temperature)\n", fahrenheit, celsius);

    return 0;
}

Sample Input:

Principal = 50000, Rate = 7.5, Time = 3, Fahrenheit = 98.6

Sample Output:

Interest = Rs. 11250.00
Total Due = Rs. 61250.00
98.60 F = 37.00 C

Practical Exam Viva Questions (Exp #1)

1 Questions
1

Why do we write 5.0 / 9.0 instead of 5 / 9 in C?