Ad

Chapter - 12: Console Input-Output

Define a function getfloat(), which would receive a numeric string from the keyboard, convert it to a float and return the float to the calling function.


Ad
D
Sections
3
Exercises
#include<stdio.h>
#include<conio.h>

double getfloat();

int main() /*Main is written to check the getfloat function*/
{
	double num;
	num = getfloat();
	printf("\nNumber : %lf\n", num);
	_getch();
	return 0;
}

double getfloat()
{
	double num = 0;
	char number[20];
	scanf("%s", number);
	sscanf(number, "%lf", &num);
	return num;
}
Ad

© 2024 Garbage Valuegarbage value logo