Problem 5
Statement
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
What is the smallest number that is evenly divisible by all of the numbers from 1 to 20?
Solution
The code, in C.
#include <stdio.h>
int div(int a){
int b,i,j;
for(i=1;;i++){
b=1;
for(j=1;j<=a;j++)
if(i%j!=0){
b=0;
break;
}
if(b) return i;
}
return 0;
}
int main(void){
printf("%d\n",div(20));
return 0;
}
Answer
232792560
SPEAK / ADD YOUR COMMENT
Comments are moderated.
Posts