In: Computer Science
Write a program that will print the whole numbers from a user-specified minimum to a user-specified maximum. Display the total amount of numbers printed.
Below is the C program to print whole number between minimum to maximum range provided by user. and total amount of numbers printed.
Both minimum and maximun numbers are inclusive
#include <stdio.h>
int main()
{
int minNumber, maxNumber, i;
int totalNumberPrinted = 0;
printf("Enter minimun number : ");
scanf("%d", &minNumber);
printf("Enter maximum number : ");
scanf("%d", &maxNumber);
//this minimun number and maximum number both inclusive
for (i = minNumber; i<= maxNumber; i++) {
printf("\n%d ",i);
totalNumberPrinted++;
}
printf("\nTotal numbers printed are : %d", totalNumberPrinted);
return 0;
}
Below is the output screenshot
Here assuming that user will give postive integers only as a input and maximun input number is greater than minimum number.