티스토리 뷰

C언어/ProjectEuler

ProectEuler 1번

Cand0 2017. 10. 19. 22:10
문제 : 10보다 작은 자연수 중에서 3 또는 5의 배수는 3, 5, 6, 9 이고, 이것을 모두 더하면 23입니다.
1000보다 작은 자연수 중에서 3 또는 5의 배수를 모두 더하면 얼마일까요?


풀이 :
#include<stdio.h>
int main()
{
 int b = 0;
 int c = 0;
 int d = 0;
 int e = 0;
 int i = 1;
 while (b<1000)
 {
  int a = 3;
  c = c + b;
  b = a*i;
  i++;
 }
 printf("%d \n", c);

 i = 1;
 b = 0;
 while (b<1000)
 {
  int a = 5;
  d = d + b;
  b = a*i;
  i++;
 }
 printf("%d \n", d);
 i = 1;
 b = 0;
 while (b<1000)
 {
  int a = 15;
  e = e + b;
  b = a*i;
  i++;
 }
 printf("%d \n", e);
 printf("%d", c + d - e);
 return 0;
}

 

'C언어 > ProjectEuler' 카테고리의 다른 글

ProjectEuler 6번  (0) 2017.10.19
ProjectEuler 5번  (0) 2017.10.19
ProjectEuler 4번  (0) 2017.10.19
ProjectEuler 3번  (0) 2017.10.19
ProjectEuler 2번  (0) 2017.10.19
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2025/02   »
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
글 보관함