easy
0 views
Print the Next Number
Read an integer and print the next consecutive integer (N+1)
Understand the Problem
Problem Statement
The program must accept a number and print its next number.
Constraints
- Input number must be a valid integer within standard integer range
- Output will be the input number incremented by 1
- No special handling required for edge cases
Examples
Example 1
Input
5Output
6Explanation
When the input is 5, the next consecutive integer is 5 + 1 = 6
Example 2
Input
99Output
100Explanation
When the input is 99, the next consecutive integer is 99 + 1 = 100
Solution
#include <stdio.h>
int main() {
int N;
scanf("%d", &N);
printf("%d", N + 1);
return 0;
}Time:O(1)
Space:O(1)
Approach:
C Solution Explanation:
#include <stdio.h>- Include standard input/output libraryint main()- Main function entry pointint N;- Declare integer variable to store inputscanf("%d", &N);- Read integer from standard input using format specifier %dprintf("%d", N + 1);- Print the result of N + 1 using format specifier %dreturn 0;- Return 0 to indicate successful execution
Visual Explanation
Loading diagram...