C Exercises: Print all numbers between 1 to 100 which divided by a specified number and the remainder will be 3
C Basic Declarations and Expressions: Exercise-32 with Solution
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:
C Programming Code Editor:
Previous: Write a C program to check a given integer is positive even, negative even, positive odd or negative odd. Print even if the number is 0.
Next: Write a C program that accepts some integers from the user and find the highest value and the input position.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/c-programming-exercises/basic-declarations-and-expressions/c-programming-basic-exercises-32.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics