07-26-2023, 03:49 PM
Example:
#include <stdio.h>
int main() {
short int userInput;
// Prompt the user to enter a short int value
printf("Enter a short int value: ");
scanf("%hd", &userInput);
// Perform a simple calculation and display the result
short int result = userInput * 2;
printf("Result: %d\n", result);
return 0;
}
Explanation:
In this example, the user is prompted to enter a short int value. The scanf function is used to read the user input as a short int, and it is stored in the userInput variable. Then, we perform a simple calculation (multiplication by 2) using the short int value and display the result using printf.
#include <stdio.h>
int main() {
short int userInput;
// Prompt the user to enter a short int value
printf("Enter a short int value: ");
scanf("%hd", &userInput);
// Perform a simple calculation and display the result
short int result = userInput * 2;
printf("Result: %d\n", result);
return 0;
}
Explanation:
In this example, the user is prompted to enter a short int value. The scanf function is used to read the user input as a short int, and it is stored in the userInput variable. Then, we perform a simple calculation (multiplication by 2) using the short int value and display the result using printf.