TheAlgorithms-C/project_euler/problem_1/sol4.c

35 lines
805 B
C
Raw Normal View History

2020-06-05 19:20:25 +03:00
/**
* \file
* \brief [Problem 1](https://projecteuler.net/problem=1) solution
*
* An Efficient code to print all the sum of all numbers that are multiples of 3
* & 5 below N.
*/
2019-06-11 16:32:34 +03:00
#include <stdio.h>
2020-06-05 19:20:25 +03:00
/** Main function */
int main()
{
int t;
2019-06-11 16:32:34 +03:00
printf("Enter number of times you want to try");
scanf("%d", &t);
while (t--)
2019-06-11 16:32:34 +03:00
{
unsigned long long N, p = 0, sum = 0;
2019-06-11 16:32:34 +03:00
printf("Enter the value of N ");
scanf("%lld", &N); // Take input of N from user
for (int i = 0; i < N; i++)
{
if (i % 3 == 0 || i % 5 == 0)
{
sum = sum + i;
}
}
printf("%lld\n", sum); // print the sum of all numbers that are
// multiples of 3 & 5 below N
2019-06-11 16:32:34 +03:00
}
return 0;
}