Print numbers between 1 and 100 with a specific remainder
Print numbers between 1 and 100 with a specific remainder
Write a C program to print all numbers between 1 and 100 which are divided by a specified number and the remainder will be 3.
Pictorial Presentation:
C Code:
#include <stdio.h>
int main() {
int x, i; // Declare variables for user input and loop counter
printf("Input an integer: ");
scanf("%d", &x); // Prompt user for an integer
for(i = 1; i <= 100; i++) // Loop through numbers from 1 to 100
{
if((i%x) == 3) { // Check if the remainder of i divided by x is 3
printf("%d\n", i); // Print i if the condition is met
}
}
return 0;
}
Input data: 25
Sample Output:
Input an integer: 3 28 53 78
Flowchart:
For more Practice: Solve these Related Problems:
- Write a C program to print all numbers between 1 and 100 that leave a remainder of 1 when divided by a user-specified divisor.
- Write a C program to display numbers between 1 and 100 that are congruent to a specified value modulo a given number.
- Write a C program to print all numbers between 1 and 100 that give a remainder of 4 when divided by a given integer.
- Write a C program to list numbers between 1 and 100 that are one less than a multiple of a user-provided number.
Go to:
PREV : Check if an integer is positive/negative and even/odd.
NEXT : Find the highest value and its position from inputs.
C Programming Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.