daily pastebin goal
56%
SHARE
TWEET

Untitled

a guest Jun 14th, 2018 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string>
  4. #include <iostream>
  5. #include <string.h>
  6.  
  7.  
  8. // other includes and definitions
  9.  
  10. /* YOUR CODE HERE */
  11.  
  12. using namespace std;
  13.  
  14. // define your datatype here
  15. typedef struct{
  16. int Array[200]={0};
  17. string ifneedstring;
  18. }  myType;
  19.  
  20. // convert from string to myType
  21. myType convert(string s){
  22.     for(int i=0; i<s.length()/2; i++)
  23.     {
  24.         swap(s[i],s[s.length()-i-1]);
  25.     }
  26.     myType number;
  27.     for(int i=0; i<s.length(); i++)
  28.     {
  29.         number.Array[i]=s[i]-'0';
  30.     }
  31.     cout<<s.length();
  32. }
  33. // convert from myType to string
  34. string toStr(myType m){
  35.     int n = sizeof(m.Array)/sizeof(m.Array[0]);
  36.     for(int i=0; i<n/2; i++)
  37.     {
  38.         swap(m.Array[i],m.Array[n-i-1]);
  39.     }
  40.     myType number;
  41.     /*for(int i=0; i<n; i++)
  42.     {
  43.         number.Array[i]=s[i]-'0';
  44.     }*/
  45.  
  46. }
  47.  
  48. // compute a factorial
  49. myType myFactorial(int n);
  50.  
  51. // finds the next prime, bigger than n
  52. myType myPrime(myType n);
  53.  
  54. // finds d to the power of (positive) p
  55. myType myPow(double d, int p);
  56.  
  57. // finds (natural) logarithm of d
  58. myType myLog(double d);
  59.  
  60. // finds sinus of d
  61. myType mySin(double d);
  62.  
  63. // finds square root of d
  64. myType mySqrt(double d);
  65.  
  66. // finds a value of PI with n digits of precision (zeroes afterwards)
  67. myType myPi(int n);
  68.  
  69. // computes an average of n valus in an array
  70. myType myAvg(myType *data, int n);
  71.  
  72. // search for a value in an array of n numbers and return an index
  73. int myFind(myType *data, int n, myType value);
  74.  
  75. // sorts data in an array of n numbers by (optimized) bubble sort algorithm
  76. void mySort(myType *data, int n);
  77.  
  78. myType myFactorial(int n){
  79.     /* YOUR CODE HERE */
  80. }
  81. myType myPrime(myType n){
  82.     /* YOUR CODE HERE */
  83. }
  84. myType myPow(double d, int p){
  85.     /* YOUR CODE HERE */
  86. }
  87. myType myLog(double d){
  88.     /* YOUR CODE HERE */
  89. }
  90. myType mySin(double d){
  91.     /* YOUR CODE HERE */
  92. }
  93. myType mySqrt(double d){
  94.     /* YOUR CODE HERE */
  95. }
  96. myType myPi(int n){
  97.     string pinumber="1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679";
  98.     cout<<"3.";
  99.     myType pi;
  100.     pi.ifneedstring[0]='3';
  101.     pi.ifneedstring[1]='.';
  102.     for(int i=0;i<n;i++)
  103.     {
  104.         pi.ifneedstring[i+2]=pinumber[i];
  105.         cout<<pinumber[i];
  106.     }
  107.     cout<<endl;
  108.     return pi;
  109. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top