Advertisement
Guest User

Untitled

a guest
Jan 16th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <math.h>
  5.  
  6.  
  7. int randomNumber(void) //Returns a random number (use time as seed) on range [0 - 1000]
  8. {
  9. srand(time(NULL)); //using time as seed
  10. int random = rand() % 1000; //%1000 limits random number to be between 0 and 1000
  11.  
  12. return random; //returning random number
  13. }
  14.  
  15. int sumOfOdd(int random) //Returns the sum of odd numbers between 0 and the random number
  16. {
  17. int ranNum = random; //getting random number from randomNumber
  18. int sumCalc;
  19. int sum;
  20. if (ranNum % 2) //checking if it is odd or not for calculation purposes
  21. {
  22. sumCalc = (ranNum + 1) / 2; //if number is odd add +1
  23. }
  24. else
  25. {
  26. sumCalc = ranNum / 2;
  27. }
  28.  
  29. sum = pow(sumCalc, 2); //calculating sum of odd with formula (n)^2
  30. return sum;
  31. }
  32.  
  33. int isTetranacci(int sum)
  34. {
  35. int sumTetra = sum;
  36.  
  37. 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
  38. {
  39. printf("Number %d is Tetranacci\n", sumTetra);
  40. }
  41. else
  42. {
  43. printf("Number %d is not Tetranacci\n", sumTetra);
  44. }
  45. return 0;
  46. }
  47.  
  48.  
  49.  
  50. int main(void)
  51. {
  52. int random = randomNumber();
  53. printf("Random number: %d\n", random);
  54.  
  55. int sum = sumOfOdd(random);
  56. printf("Sum of odd numbers: %d\n", sum);
  57.  
  58. isTetranacci(sum);
  59.  
  60. return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement