Now we will see how printf() and scanf() function works together to perform a particular work.
We will write a program to calculate the Simple Interest. where the principle, rate of interest and the time in years will be taken from the user.
#include<stdio.h>
#include<conio.h>
void main()
{
float si, p, r; /* declaration of float type variables */
int t; /* declaration of integer type variables */
clrscr(); /* used to clear screen */
printf(“Enter the principle amount = Rs ”); /* Printing of user friendly statement */
scanf(“%f”, &p); /* Inputting the value of float type variable p from the user */
printf(“\nEnter the rate of interest = ”); /* Printing of user friendly statement */
scanf(“%f”, &r); /* Inputting the value of float type variable r from the user */
printf(“\nEnter the time in years = ”); /* Printing of user friendly statement */
scanf(“%d”, &t); /* Inputting the value of integer type variable t from the user */
si=(p*t*r)/100; /* logical operation for calculating the simple interst */
printf(“Therefore the Simple Interest = Rs %.2f”, si); /* Printing the output with the user-friendly statement */
getch(); /* pause the output screen */
}
The output of this program is as follows:
Enter the principle amount = Rs 250
Enter the rate of interest = 8.5
Enter the time in years = 5
Therefore the Simple Interest = Rs 106.25
We will write a program to calculate the Simple Interest. where the principle, rate of interest and the time in years will be taken from the user.
#include<stdio.h>
#include<conio.h>
void main()
{
float si, p, r; /* declaration of float type variables */
int t; /* declaration of integer type variables */
clrscr(); /* used to clear screen */
printf(“Enter the principle amount = Rs ”); /* Printing of user friendly statement */
scanf(“%f”, &p); /* Inputting the value of float type variable p from the user */
printf(“\nEnter the rate of interest = ”); /* Printing of user friendly statement */
scanf(“%f”, &r); /* Inputting the value of float type variable r from the user */
printf(“\nEnter the time in years = ”); /* Printing of user friendly statement */
scanf(“%d”, &t); /* Inputting the value of integer type variable t from the user */
si=(p*t*r)/100; /* logical operation for calculating the simple interst */
printf(“Therefore the Simple Interest = Rs %.2f”, si); /* Printing the output with the user-friendly statement */
getch(); /* pause the output screen */
}
The output of this program is as follows:
Enter the principle amount = Rs 250
Enter the rate of interest = 8.5
Enter the time in years = 5
Therefore the Simple Interest = Rs 106.25
No comments:
Post a Comment
Please give your valuable comments or queries if you fell its helpful or if you like the contents of the site. Thanks...