Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
4b0f689061 |
21
LICENSE
21
LICENSE
@ -1,21 +0,0 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2025 h7x4 <h7x4@nani.wtf>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
@ -1,5 +0,0 @@
|
||||
# Project Euler
|
||||
|
||||
This is a private repository for solutions to the [Project Euler](https://projecteuler.net/) excersizes.
|
||||
|
||||
Switch branch to find solutions written in different languages.
|
35
src/Task2.c
Normal file
35
src/Task2.c
Normal file
@ -0,0 +1,35 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int fib(int a) {
|
||||
if(a==0){
|
||||
return 0;
|
||||
}else if(a==1){
|
||||
return 1;
|
||||
} else {
|
||||
return (fib(a-1) + fib(a-2));
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
int count = 0;
|
||||
int result = 0;
|
||||
|
||||
while(1){
|
||||
int x = fib(count);
|
||||
|
||||
if(x>4000000){
|
||||
printf("%d", result);
|
||||
break;
|
||||
}
|
||||
|
||||
if(x%2==0){
|
||||
result = result + x;
|
||||
}
|
||||
count = count+1;
|
||||
}
|
||||
|
||||
}
|
||||
|
120
src/task20.c
Normal file
120
src/task20.c
Normal file
@ -0,0 +1,120 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
int isPrime(int n){
|
||||
for(int i=2;i<sqrt(n);i++){
|
||||
if(n%i==0){
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*Returns amount of primes between 0 and n*/
|
||||
int amountPrimes(int n){
|
||||
int x=0;
|
||||
|
||||
for (int i = 2; i < n; i++)
|
||||
{
|
||||
if (isPrime(i)){
|
||||
x+=1;
|
||||
}
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
/*Returns array with primes between 0 and n*/
|
||||
int * primesIn(int n){
|
||||
|
||||
int x = amountPrimes(n);
|
||||
|
||||
int * primes;
|
||||
primes = malloc(sizeof(int)*x);
|
||||
x=0;
|
||||
|
||||
for (int i = 2; i < n; i++)
|
||||
{
|
||||
if (isPrime(i)){
|
||||
primes[x]=i;
|
||||
x+=1;
|
||||
}
|
||||
}
|
||||
|
||||
return primes;
|
||||
|
||||
}
|
||||
|
||||
/*Factorial of n*/
|
||||
long fact(int n){
|
||||
if (n==1){
|
||||
return 1;
|
||||
} else {
|
||||
return n*fact(n-1);
|
||||
}
|
||||
}
|
||||
|
||||
/*Retrieves the amount of factors in a number*/
|
||||
int factoramount(int n){
|
||||
|
||||
if (isPrime(n)){
|
||||
return 1;
|
||||
} else {
|
||||
for
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*Returns array with factors of n*/
|
||||
int * factorize(int n){
|
||||
|
||||
int x = amountPrimes(n);
|
||||
|
||||
int * primes;
|
||||
primes = malloc(sizeof(int)*x);
|
||||
|
||||
if(isPrime(n)) {
|
||||
|
||||
} else {
|
||||
for (size_t i = 2; i < n; i++)
|
||||
{
|
||||
if (i%j==0)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(){
|
||||
|
||||
int * primes = primesIn(100);
|
||||
|
||||
for (size_t i = 0; i < amountPrimes(100); i++){
|
||||
printf("Prime: %d\n", *(primes+i));
|
||||
}
|
||||
|
||||
|
||||
int * factCounter[amountPrimes(100)]
|
||||
|
||||
for (size_t i = 1; i < 100; i++){
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
long x = fact(100);
|
||||
|
||||
//SUM OF DIGITS OF X
|
||||
|
||||
printf("%ld\n", x);
|
||||
|
||||
}
|
35
src/task3.c
Normal file
35
src/task3.c
Normal file
@ -0,0 +1,35 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
int isPrime(long n){
|
||||
for(int i=2;i<sqrt(n);i++){
|
||||
if(n%i==0){
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
long count=1;
|
||||
int big=0;
|
||||
long number=600851475143;
|
||||
|
||||
while(count<number){
|
||||
if(isPrime(count)){
|
||||
//printf("Prime: %ld \n", count);
|
||||
if (number%count==0){
|
||||
printf("New big: %ld \n", count);
|
||||
big=count;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
count+=1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
39
src/task4.c
Normal file
39
src/task4.c
Normal file
@ -0,0 +1,39 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(){
|
||||
|
||||
int biggest = 0;
|
||||
|
||||
for (int i = 100; i < 1000; i++)
|
||||
{
|
||||
for (int j = 100; j < 1000; j++)
|
||||
{
|
||||
int x=i*j;
|
||||
int z=x;
|
||||
int y=0;
|
||||
|
||||
while (x != 0)
|
||||
{
|
||||
y = y * 10;
|
||||
y = y + x%10;
|
||||
x = x/10;
|
||||
}
|
||||
|
||||
//printf("%d - %d\n", y, z);
|
||||
|
||||
if (y==z & y>biggest){
|
||||
biggest = z;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
printf("%d\n", biggest);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
13
src/task48.c
Normal file
13
src/task48.c
Normal file
@ -0,0 +1,13 @@
|
||||
#include <std.io>
|
||||
|
||||
int main{
|
||||
|
||||
long a=0
|
||||
|
||||
for(int i=0;i<=1000;i++){
|
||||
a+=(i^i);
|
||||
}
|
||||
|
||||
printf("%ld", a);
|
||||
|
||||
}
|
28
src/task5.c
Normal file
28
src/task5.c
Normal file
@ -0,0 +1,28 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main(){
|
||||
|
||||
int x=5;
|
||||
|
||||
while(1){
|
||||
|
||||
|
||||
for (int i = 2; i <= 20; i++)
|
||||
{
|
||||
if (x%i!=0){
|
||||
break;
|
||||
}
|
||||
if(i==20){
|
||||
printf("%d\n", x);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
x+=1;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user