In: Computer Science
Hello!
Formater for double is %lf
which means long float.
The function declaration and definition has done before the main function itself.
Functionality:
// GetLetter function
This function takes 2 double arguments and adds each other and assigns the result to another double variable c. And type conversion of this variable takes place which means converts double to char and returns this char.
Here we have used pass by value , means new address is allocated and the duplicate of values a and b is stored in new address. So because of this original value will not be effected and prevents the loss of information.
// Main function
Here the values a and b are taken from user and calls the function GetLetter by passing these a and b values.
And the returned value gets printed.
CODE:
#include <stdio.h>
char GetLetter(double a,double b){
// takes a and b and added each other
// and assigns to c
double c = a + b;
// returns the c after type casting
// the double is converted to equivalent
return ((char)c);
}
int main() {
double a,b;
char letter;
// asks user for a and b
printf("Enter a and b: ");
// gets a and b
scanf("%lf %lf",&a,&b);
printf("%lf & %lf\n",a,b);
// calls the GetLetter func and returns
// the char to letter char variable
letter = GetLetter(a,b);
// prints the letter
printf("the letter is %c",letter);
return 0;
}
OUTPUT:
Hope this helps and clear.
I strive to provide the best of my knowledge so please upvote if you like the content.
Thank you!