Basic Concept Of Function


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.

Note: If you want to know more about C function Click Here:

C program to calculate Simple Interest using function:-

#include<stdio.h>
int calculate();
int main()
{
float si;
si=calculate();
printf("The Simple Intrest of given data is %.2f",si);
return 0;
}
int calculate()
{
float principal, rate, time, si;
printf("Enter the Principal, Rate and Amount Respectively:-\n");
scanf("%f%f%f",&principal,&rate,&time);
si=(principal*rate*time)/100;
return si;
}

OUTPUT

C program to calculate Simple Interest using function


Calculate Simple Interest using function with argument but no return type:- 


#include<stdio.h>
void calculate(float , float , float );
int main()
{
float principal,time,rate,si;
printf("Enter Principal, Rate and Time respectively1:-\n");
scanf("%f%f%f",&principal,&rate,&time);
calculate(principal,rate,time);
}
void calculate(float principal, float rate, float time)
{
float si;
si=(principal*time*rate)/100;
printf("The Simple Interst of given value is %.2f",si);
}

OUTPUT

C program to calculate Simple Interest using function



Calculate Simple Interest using function with no argument and no return type:- 

#include<stdio.h>
int calculate();
int main()
{
calculate();
return 0;
}
int calculate()
{

float p,t,r,si;
printf("Enter Principal, Rate and Time respectively1:-\n");
scanf("%f%f%f",&p,&r,&t);
si=(p*t*r)/100;
printf("The Simple Interst of given value is %.2f",si);
return 0;
}

OUTPUT

C program to calculate Simple Interest using function


Calculate Simple Interest using function with  argument and  return type:- 

#include<stdio.h>
int calculate(float p, float t, float r);
int main()
{
float principal,time,rate,c;
printf("Enter Principal, Rate and Time respectively1:-\n");
scanf("%f%f%f",&principal,&rate,&time);
c = calculate(principal,time,rate);
printf("The Simple Interst of given value is %.2f",c);
return 0;
}
int calculate(float p, float t, float r)
{
int si;
si=(p*t*r)/100;
return si;
}

OUTPUT

C program to calculate Simple Interest using function

Share To:

Arogya Thapa Magar

Post A Comment:

0 comments so far,add yours