Skip to content

Problem.20 done in C language #176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 30 additions & 30 deletions C/10. Summation_of_primes/Kavya-Shekar.c
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
// Problem 10 : Summation of primes
// The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
// Find the sum of all the primes below two million.
#include<stdio.h>
#include<math.h>
int prime(long n);
// return 1 if n is prime, else returns 0
int main()
{
long n = 2000000;
long sum = 2;
for(long i = 3; i<n; i++)
{
if(prime(i)) sum += i;
}
printf("%ld",sum);
}
int prime(long n)
{
for(long i=2;i<=sqrt(n);i++)
{
if(n%i==0) return 0;
}
return 1;
// Problem 10 : Summation of primes
// The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
// Find the sum of all the primes below two million.

#include<stdio.h>
#include<math.h>

int prime(long n);
// return 1 if n is prime, else returns 0

int main()
{
long n = 2000000;
long sum = 2;
for(long i = 3; i<n; i++)
{
if(prime(i)) sum += i;
}

printf("%ld",sum);
}

int prime(long n)
{
for(long i=2;i<=sqrt(n);i++)
{
if(n%i==0) return 0;
}

return 1;
}
34 changes: 34 additions & 0 deletions C/20.Factorial_digit_sum/Kavya-Shekar.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Problem 20 : Factorial digit sum
// n! means n × (n − 1) × ... × 3 × 2 × 1
// Find the sum of the digits in the number 100!

#include<stdio.h>

int main()
{
int a[200],n,counter,temp;
a[0]=1;
counter=0;
n = 100;
for(; n>=2; n--)
{
temp=0;
for(int i=0; i<=counter; i++)
{
temp=(a[i]*n)+temp;
a[i]=temp%10;
temp=temp/10;
}
while(temp>0)
{
a[++counter]=temp%10;
temp=temp/10;
}
}
int sum = 0;
for(int i=0;i<=counter;i++)
sum+=a[i];

printf("Sum of digits in 100 factorial : %d",sum);

}
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Happy Contributing! 😃
| 17 | [Number letter counts](https://projecteuler.net/problem=17) | | | | :white_check_mark: | | | | | | | | |
| 18 | [Maximum path sum I](https://projecteuler.net/problem=18) | | | | :white_check_mark: | | | | | | | | |
| 19 | [Counting Sundays](https://projecteuler.net/problem=19) | | | | | | | | | | | | |
| 20 | [Factorial digit sum](https://projecteuler.net/problem=20) | | :white_check_mark: | | :white_check_mark: | :white_check_mark: | | | | | | | |
| 20 | [Factorial digit sum](https://projecteuler.net/problem=20) | | :white_check_mark: | | :white_check_mark: | :white_check_mark: | | :white_check_mark: | | | | | |
| 21 | [Amicable numbers](https://projecteuler.net/problem=21) | | | | | | | | | | | | |
| 22 | [Names scores](https://projecteuler.net/problem=22) | | | | :white_check_mark: | | | | | | | | |
| 23 | [Non-abundant sums](https://projecteuler.net/problem=23) | | | | | | | | | | | | |
Expand Down Expand Up @@ -81,7 +81,6 @@ Happy Contributing! 😃
| 49 | [Prime permutations](https://projecteuler.net/problem=49) | | | | :white_check_mark: | | | | | | | | |
| 50 | [Consecutive prime sum](https://projecteuler.net/problem=50) | | | | :white_check_mark: | | | :white_check_mark: | | :white_check_mark: | | | |


## Thanks


Expand Down