-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathC_10_odd_multiple.cpp
More file actions
40 lines (33 loc) · 1 KB
/
C_10_odd_multiple.cpp
File metadata and controls
40 lines (33 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <stdio.h>
// Function to calculate the first 10 odd multiples
int* oddMultiples(int input, bool show=true) {
int factor = 1;
int count = 0;
int odd_mul[10];
// check if input is even there is no odd multiple
if (input % 2 == 0) {
printf("Input is even. Please enter an odd integer.\n");
return NULL; // Return NULL if the input is even
} else {
printf("The first 10 odd multiples of %d are: \n", input);
while (count < 10) {
int multiple = input * factor;
if (multiple % 2 != 0) {
odd_mul[count] = multiple;
if (show) {
printf("%d\n", multiple);
}
count++;
}
factor++;
}
}
return odd_mul;
}
int main() {
int input;
printf("Enter an input integer: ");
scanf("%d", &input);
int* odd_multiple = oddMultiples(input); // Call the function, pass false if you do not want to show result
return 0;
}