functions in C & CPP
Title
Question
#include<iostream>
using namespace std;
double add(double a, double b)
{
double c = a + b;
}
int main()
{
double sum;
sum = add(50.4,4.5);
cout<<"sum is : "<<sum<<"\\n";
return 0;
using namespace std;
double add(double a, double b)
{
double c = a + b;
}
int main()
{
double sum;
sum = add(50.4,4.5);
cout<<"sum is : "<<sum<<"\\n";
return 0;
}
Output is
sum is : nan
May i know why the ans is nan for double data type? Same has already worked for int. Is there any problem with double or float data type.
C-and-Cpp Functions 06-07 min 20-30 sec
Answers:
Please modify the function as below
double add(double a, double b)
{double c = a + b;
return c;
}
The return type of your function is double so you are expected to return the value
Since double add(double a, double b); is a non-void function, you may need to return a double type at the end of the function.
Login to add comment