Chapter - 12: Console Input-Output

Define a function getint( ), which would receive a numeric string from the keyboard, convert it to an integer number and return the integer to the calling function. Sample usage of getint( ) is shown below:


D
Sections
2
Exercises
#include
int main()
{
int a;
a = getint();
printf("you entered %d\n", a);
return 0;
}

Ans:

#include<stdio.h>
#include<conio.h>

int getint();

int main()
{
	int num;
	num = getint();
	printf("\nNumber : %d\n", num);
	_getch();
	return 0;
}

int getint()
{
	int num = 0;
	char number[20];
	scanf("%s", number);
	sscanf(number, "%d", &num);
	return num;
}

© 2021 Garbage Valuegarbage value logo