Я прочитал этот пост here и я следовал инструкциям, применяя их к простой программе, суммирует все числа ниже 1000 делится на 3 и 5Как раз, когда программа C
#include <stdio.h>
#include <time.h>
clock_t begin, end;
double time_spent;
begin = clock();
int sumDivisibleBy (div, limit) {
int h = (limit - 1)/div;
return div*h*(h+1)/2;
}
int main(void) {
int l = 1000;
int s = sumDivisibleBy(3,l) + sumDivisibleBy(5,l) - sumDivisibleBy(15,l);
printf("%d \n", s);
}
end = clock();
time_spent = (double)(end - begin)/CLOCKS_PER_SEC
printf("%f \n", time_spent)
Теперь, при вводе в терминале «сделать 1» (файл называется 1.c), это то, что я получаю:
cc 1.c -o 1
1.c:9:1: warning: data definition has no type or storage class [enabled by default]
begin = clock();
^
1.c:9:1: error: conflicting types for ‘begin’
1.c:6:9: note: previous declaration of ‘begin’ was here
clock_t begin, end;
^
1.c:9:1: error: initializer element is not constant
begin = clock();
^
1.c:20:1: warning: data definition has no type or storage class [enabled by default]
end = clock();
^
1.c:20:1: error: conflicting types for ‘end’
1.c:6:16: note: previous declaration of ‘end’ was here
clock_t begin, end;
^
1.c:20:1: error: initializer element is not constant
end = clock();
^
1.c:21:1: warning: data definition has no type or storage class [enabled by default]
time_spent = (double)(end - begin)/CLOCKS_PER_SEC
^
1.c:21:1: error: conflicting types for ‘time_spent’
1.c:7:8: note: previous declaration of ‘time_spent’ was here
double time_spent;
^
1.c:21:1: error: initializer element is not constant
time_spent = (double)(end - begin)/CLOCKS_PER_SEC
^
1.c:21:1: error: expected ‘,’ or ‘;’ at end of input
make: *** [1] Error 1
Почему это? Может кто-нибудь помочь, пожалуйста?
Спасибо @Jens :) проблема решена – Pigna
@Pigna Это хорошие новости. Теперь следующий шаг в переполнении стека - это * принять * ответ, который вы считаете наиболее полезным, щелкнув галочкой * слева. Это принесет вам два репутационных очков. – Jens
Почему ++ j и не j ++? – Pigna