In: Computer Science
Function defnition and the complete program are given below.Detailed comments are included for better under standing the code.Screen shot of the code and output are also attached.if find any difficulty,feel free to ask in comment section.Please do upvote the answer.Thank you
Function definition
int compareNum(double num)
{
//declaring double variable number
double number;
//prompt user to enter number
printf("Enter a number: ");
//reading number
scanf("%f",&number);
//if both are equal,return 0
if(num==number)
return 0;
//if num is less than user enterd double,return
-1
else if(num<number)
return -1;
//if num is greater than user enterd double,return
1
else
return 1;
}
Complete program
#include<stdio.h>
//function prototype declaration
int compareNum(double);
int main(void)
{
//declaring double variable d
double n;
//integer variable result
int result;
//prompt to enter double number
printf("Enter a double number: ");
//reading number
scanf("%f",&n);
//calling compareNum() function
result=compareNum(n);
//printing returned value
printf("%d",result);
return 0;
}
int compareNum(double num)
{
//declaring double variable number
double number;
//prompt user to enter number
printf("Enter a number: ");
//reading number
scanf("%f",&number);
//if both are equal,return 0
if(num==number)
return 0;
//if num is less than user enterd double,return
-1
else if(num<number)
return -1;
//if num is greater than user enterd double,return
1
else
return 1;
}
Screen shot of the code
Screen shot of the output