×

C Programs

C Basic & Conditional Programs

C Looping Programs

C String Programs

C Miscellaneous Programs

Input an unsigned integer value using scanf() in C

Here, we are going to learn how to input an unsigned integer values using scanf() function in C programming language?
By IncludeHelp Last updated : March 10, 2024

Problem statement

Here, we have to declare an unsigned integer variable and read its value using scanf() function in C.

Input an unsigned integer value using scanf()

The data type to declare an unsigned integer is: unsigned int and the format specifier that is used with scanf() and print() for unsigned int type of variable is "%u".

C program to input an unsigned integer value

#include <stdio.h>

int main(void) 
{
	unsigned int value;

	printf("Enter an unsigned int value: ");
	scanf("%u", &value);
	printf("value: %u\n", value);

	//input again 
	printf("Enter an unsigned int value again: ");
	scanf("%u", &value);
	printf("value: %u\n", value);

	//input again
	printf("Enter an unsigned int value again: ");
	scanf("%u", &value);
	printf("value: %u\n", value);

	return 0;
}

Output

Enter an unsigned int value: 123712
value: 123712
Enter an unsigned int value again: -1
value: 4294967295
Enter an unsigned int value again: 25501
value: 25501

Note: See the input second and its result, when we provide -1 to an unsigned integer value, it assigns "maximum value to an unsigned int" to the variable.

C scanf() Programs »

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.