I don’t know if it’s okay to post about C programming here.
But I’ve been stuck with this one problem my whole day.
And it’s making me frustrated that I want to punch thru the monitor
What I’m trying to do is. input three numbers k , m , n.
and calculate the sum of all the multiples of k between m and n.
so it’s like m < multiple of k < n
int main (){
int i, k, m, n, sum = 0;
printf("Input 3 integers that are bigger than 1: \n");
scanf("%d%d%d", &k, &m, &n);
for(i = 1; (i > m) && (i < n); ++i ){
if(i % k == 0)
sum += i;
}
printf("%d\n", sum);
return 0;
}
output:
Input 3 integers that are bigger than 1:
3
6
20
0Program ended with exit code: 0
int i, k, m, n, sum = 0;
printf("Input 3 integers that are bigger than 1: \n");
printf("input k: ");
scanf("%d", &k);
printf("input m: ");
scanf("%d", &m);
printf("input n: ");
scanf("%d", &n);
for(i = ++m; i < n; ++i){
if(i % k == 0)
sum += i;
}
printf("%d\n", sum);
return 0;
}
Why wouldn’t C programming take this bold part right here:
for(i = 1; (i > m) && (i < n); ++i ){
if(i % k == 0)
sum += i;
}
Yea. C++ has been on my mind for quite some time now. I really want to make games and after getting so far in javascript, it seems like a bad idea to try to learn C++ at the same time.