1 Commits

Author SHA1 Message Date
4b0f689061 Create C branch 2020-06-22 11:30:32 +02:00
8 changed files with 270 additions and 49 deletions

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;
}
}

@@ -1,29 +0,0 @@
const MAX_LIMIT = 4000000
function fibonacci(index) {
if (index === 0) return 0;
let A = 0;
let B = 1;
for (let i = 0; i < (index - 1); i++) {
let C = A + B;
A = B;
B = C;
}
return B;
}
let sum = 0;
let currentNum = 0;
let i = 0;
while (currentNum < MAX_LIMIT) {
currentNum = fibonacci(i);
if (currentNum % 2 === 0) {
sum += currentNum;
}
i++;
}
console.log(sum);

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);
}

@@ -1,20 +0,0 @@
function primeFactorsOf(n) {
let k = 2;
let factors = [];
while (n >= k**2) {
if (n % k === 0) {
factors.push(k)
n = n/k;
} else {
k++;
}
}
factors.push(n);
return factors;
}
const SPECIAL_NUM = 600851475143;
const factorsOfSpecialNum = primeFactorsOf(SPECIAL_NUM);
console.log(Math.max.apply(null, factorsOfSpecialNum));

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

@@ -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

@@ -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

@@ -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;
}