User input and short int conversion in C - Printable Version +- QP School (https://qomplainerzschool.lima-city.de) +-- Forum: Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=3) +--- Forum: C 18 Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=32) +--- Thread: User input and short int conversion in C (/showthread.php?tid=5149) |
User input and short int conversion in C - Qomplainerz - 07-26-2023 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. |