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);
}

ఔట్పుట్ తెరమీద
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()

ఔట్పుట్ తెరమీద మరోసారి ... (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()


కామెంట్‌లు

ఈ బ్లాగ్ నుండి ప్రసిద్ధ పోస్ట్‌లు

100% C prog to write content into a file and then read it back onto the console

Spic macay

శ్రీరస్తు.. రామలింగ 18-1-24 (సూరసాని వారి ఆహ్వానము)