by CodeChum Admin
In life, good things take time.
Let's make a simple program that mirrors this beautiful idea where we ask the user for two integer inputs. The first one would represent the starting number and the second one would represent the next n integers after it.
For example, if the first number inputted is 2 and the second number inputted is 3, then the output would be 3, 4, 5 because these are the next 3 integers after 2.
Instructions:
Input
1. Starting integer
2. Number of integers
Output
Enter·starting·integer:·2
Enter·how·many·next·integers:·3
3·4·5
#include <stdio.h>
void slowDisplay(int start, int cnt) {
if(cnt == 0)
return;
else
{
printf("%d ", ++start);
slowDisplay(start, (cnt-1));
}
}
int main()
{
int start, num;
printf("Enter starting integer: ");
scanf("%d", &start);
printf("Enter how many next integers: ");
scanf("%d", &num);
slowDisplay(start, num);
getchar();
return 0;
}
Comments
Leave a comment