Write a program to calculate simple interest using a user defined function.
Answers
Answered by
7
Hello,
Algorithm:
Before write a program,first write algorithm
1) Declare a function.
2) Take input from user
3) Apply the formula
4) Take return value
Program:
#include<stdio.h>
#include<conio.h>
float CAL_SI(float P,float R, float Y)
{
float SI;
SI=P*R*Y/100.0;
return SI;
}
int main()
{
float P,R,Y,SI;
printf("Enter Principal Amount : ");
scanf("%f",&P);
printf("Enter Interest-Rate : ");
scanf("%f",&R);
printf("Enter Time Period : ");
scanf("%f",&Y);
SI=CAL_SI(P,R,Y);
printf("\nSimple-Interest : %f\",SI);
}
Output:
Enter Principal amount:2000.0
Enter Interest-Rate : 5.7
Enter Time Period: 2.0
Simple -Interest:228.0
Hope it helps you.
Algorithm:
Before write a program,first write algorithm
1) Declare a function.
2) Take input from user
3) Apply the formula
4) Take return value
Program:
#include<stdio.h>
#include<conio.h>
float CAL_SI(float P,float R, float Y)
{
float SI;
SI=P*R*Y/100.0;
return SI;
}
int main()
{
float P,R,Y,SI;
printf("Enter Principal Amount : ");
scanf("%f",&P);
printf("Enter Interest-Rate : ");
scanf("%f",&R);
printf("Enter Time Period : ");
scanf("%f",&Y);
SI=CAL_SI(P,R,Y);
printf("\nSimple-Interest : %f\",SI);
}
Output:
Enter Principal amount:2000.0
Enter Interest-Rate : 5.7
Enter Time Period: 2.0
Simple -Interest:228.0
Hope it helps you.
Answered by
8
A function is a block of code that performs a specific task. Every C program has at least one function, which is main(), and all the most trivial programs can define additional functions. Function can also be defined as the idea to put some repeatedly done task together by making block of statement which helps while instead of writing the same block of code again and again for different inputs, we can call the same block of statement in the program.
Similar questions