C Online Compiler
Example: Find Multiples Up To N (Simple Loop) in C
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Find Multiples Up To N (Simple Loop) #include <stdio.h> int main() { // Step 1: Declare variables for the number and the limit int number, limit, i; // Step 2: Prompt user for input printf("Enter the integer whose multiples you want to find: "); scanf("%d", &number); printf("Enter the upper limit (N): "); scanf("%d", &limit); // Step 3: Input validation (optional but good practice) if (number <= 0 || limit <= 0) { printf("Please enter positive integers for both the number and the limit.\n"); return 1; // Indicate an error } if (number > limit) { printf("The number must not be greater than the limit.\n"); return 1; // Indicate an error } // Step 4: Display header printf("Multiples of %d up to %d: ", number, limit); // Step 5: Loop to find and print multiples for (i = number; i <= limit; i += number) { printf("%d ", i); } printf("\n"); // Newline for clean output return 0; }
Output
Clear
ADVERTISEMENTS