#include <stdio.h>
int main() {
int num, count_pos = 0, count_neg = 0;
// Prompting the user to input a whole number
printf("Enter a whole number: \n");
scanf("%d", &num);
// Loop for positive numbers
for (int i = 1; i <= num; i++) {
if (i % 7 == 0) {
count_pos++;
}
}
// Loop for negative numbers
for (int i = -1; i >= num; i--) {
if (i % 7 == 0) {
count_neg++;
}
}
// Adding the counts together
int total_count = count_pos + count_neg;
if(num<=0)
{
total_count = total_count +1;
}
// Displaying the count to the user
printf("%d numbers between 1 and %d are \ndivisible by seven with no remainder.\n", total_count, num);
return 0;
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter