Find the sum of all the multiples of 3 or 5 below 1000

前端 未结 16 962
时光说笑
时光说笑 2020-12-10 16:41

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. I have the following code but the answer do

16条回答
  •  眼角桃花
    2020-12-10 17:11

    #include
    #include
    int main()
    {
        int x,y,n;
        int sum=0;
        printf("enter the valeus of x,y and z\n");
        scanf("%d%d%d",&x,&y,&n);
        printf("entered   valeus of x=%d,y=%d and z=%d\n",x,y,n);
        sum=x*((n/x)*((n/x)+1)/2)+y*((n/y)*((n/y)+1)/2)-x*y*(n/(x*y))*((n/(x*y))+1)/2;
        printf("sum is %d\n",sum);
        return 0;
    }
    // give x,y and n  as 3 5 and 1000
    

提交回复
热议问题