Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <math.h>
- int randomNumber(void) //Returns a random number (use time as seed) on range [0 - 1000]
- {
- srand(time(NULL)); //using time as seed
- int random = rand() % 1000; //%1000 limits random number to be between 0 and 1000
- return random; //returning random number
- }
- int sumOfOdd(int random) //Returns the sum of odd numbers between 0 and the random number
- {
- int ranNum = random; //getting random number from randomNumber
- int sumCalc;
- int sum;
- if (ranNum % 2) //checking if it is odd or not for calculation purposes
- {
- sumCalc = (ranNum + 1) / 2; //if number is odd add +1
- }
- else
- {
- sumCalc = ranNum / 2;
- }
- sum = pow(sumCalc, 2); //calculating sum of odd with formula (n)^2
- return sum;
- }
- int isTetranacci(int sum)
- {
- int sumTetra = sum;
- if ((sumTetra == 0 || sumTetra == 1 || sumTetra == 2 || sumTetra == 4 || sumTetra == 8 || sumTetra == 15 || sumTetra == 56 || sumTetra == 108 || sumTetra == 208 || sumTetra == 401 || sumTetra == 773 || sumTetra == 1490 || sumTetra == 2872 || sumTetra == 5536 || sumTetra == 10671 || sumTetra == 20569 || sumTetra == 39648 || sumTetra == 76424 || sumTetra == 147312 )) //checks if number is tetranacci number
- {
- printf("Number %d is Tetranacci\n", sumTetra);
- }
- else
- {
- printf("Number %d is not Tetranacci\n", sumTetra);
- }
- return 0;
- }
- int main(void)
- {
- int random = randomNumber();
- printf("Random number: %d\n", random);
- int sum = sumOfOdd(random);
- printf("Sum of odd numbers: %d\n", sum);
- isTetranacci(sum);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement