100% prog to print average of no.s using functions
#include <stdio.h>
float sagaTu(int,int);//function prototyping
void main()
{
int p,q;
float avg;
printf("\n enter two integers:");
scanf("%d%d",&p,&q);
avg=sagaTu(p,q);
printf("\n average of given numbers %d & %d =%f as printed in main()",p,q,avg);
}
float sagaTu(a,b) //function definition
{
float z;
z=(float) (a+b)/2; //typecasting ; if u dont write float here, the output was only printing integer part.
printf("\n sagaTu of given numbers %d & %d =%f as printed in the called function",a,b,z);
return(z);
}
float sagaTu(int,int);//function prototyping
void main()
{
int p,q;
float avg;
printf("\n enter two integers:");
scanf("%d%d",&p,&q);
avg=sagaTu(p,q);
printf("\n average of given numbers %d & %d =%f as printed in main()",p,q,avg);
}
float sagaTu(a,b) //function definition
{
float z;
z=(float) (a+b)/2; //typecasting ; if u dont write float here, the output was only printing integer part.
printf("\n sagaTu of given numbers %d & %d =%f as printed in the called function",a,b,z);
return(z);
}
ఔట్పుట్ తెరమీద
enter two integers:2
3
sagaTu of given numbers 2 & 3 =2.500000 as printed in the called function
average of given numbers 2 & 3 =2.500000 as printed in main()
3
sagaTu of given numbers 2 & 3 =2.500000 as printed in the called function
average of given numbers 2 & 3 =2.500000 as printed in main()
ఔట్పుట్ తెరమీద మరోసారి ... (without typecasting)
enter two integers:8 3
sagaTu of given numbers 8 & 3 =5.000000 as printed in the called function
average of given numbers 8 & 3 =5.000000 as printed in main()
sagaTu of given numbers 8 & 3 =5.000000 as printed in the called function
average of given numbers 8 & 3 =5.000000 as printed in main()
కామెంట్లు
కామెంట్ను పోస్ట్ చేయండి
దయచేసి మీ సలహాలను సూచనలను స్పష్టంగా పేర్కొనగలరు. plz see that ur comments are 'acceptable' in a value based society.