int main() { const char* string = (char *)malloc(50); const char* sub = (char *)malloc(19); int a = 8; float b = 9.4444; int c = 2; int d; printf("Before swapping: a = %d c = %d\n", a , c); a = a + c; c = a - c; a = a - c; printf("After swapping: a = %d c = %d\n", a , c); string = "This is the company namded apple inc"; sub = "is"; printf("Substring: %d\n", isSubstring(string, sub)); printf("Position of the MSB is: %d\n", msbPos(3)); printf("Is bit set: %d\n", isBitset(8,4)); printf("%x to little endian %x\n", a, BigToLittle(a)); printf("%d is a power of 2: %d\n", a ,isPowerof2(a)); printf("%s after reversed: %s\n", string, reverse(string)); printf("%s is palindrome: %d\n", string, isPalindrome(string)); printf("%d is a prime number: %d\n",a, isPrimeNumber(a)); primeNumber(20); printf("\nFibonacci Series: "); fibonacci(15); printf("\n"); printf("Factorial of %d: %d\n", a, factorial(a)); printf("%s after reversing: %s\n", string, reverseString(string)); printf("Nearest int of %f is: %d\n", b, nearestInt(b)); printf("%d", (-1%8)); return 0; }
//Main function int main(int argc, const int * argv[]) { #ifdef DEBUG //in Debug mode that shows program execution time clock_t startTime; startTime = clock(); #endif // DEBUG //container, which holds all threads for easy managment vector<thread*> threadsVector; //thread creation, for every function different thread //after this point all functions will start working thread fibonacci(fibonaccisSequence); thread primeNumber(primeNumberFinder); //put all created threads in vector threadsVector.push_back(&fibonacci); threadsVector.push_back(&primeNumber); //complete all active threads for (size_t i = 0; i < threadsVector.size(); i++) { threadsVector.at(i)->join(); } #ifdef DEBUG //in Debug mode that shows program execution time startTime = clock() - startTime; cout << "\nPROGRAM execution time is: " << ((float)startTime) / CLOCKS_PER_SEC << " seconds.\n" << endl; #endif // DEBUG return 0; }
static HashTable *HashMakeTable( int num_pnts ) { HashTable *hash; hash = (HashTable *) calloc( sizeof(HashTable), 1 ); hash->size = primeNumber( (int)(num_pnts * 1.5) ); hash->points = (HashPoint *) calloc( sizeof(HashPoint), hash->size ); hash->addPoint = addPoint; hash->searchPoint = searchPoint; hash->getEntry = getEntry; return hash; }
int main() { int N; scanf("%d",&N); int counter=1; if(N==1) counter=0; else if(N==2) counter=1; else { for(int i=3; i<=N; i++) { if( i%2==0 ) continue; if( primeNumber(i) ) counter++; } } printf("%d", counter ); return 0; }
/** answer is -59231 */ int main(int argc, char *argv[]) { std::set<long> bchoices = primeList(1000); long c = 1e6; std::set<long> primeset = primeList(c); int ma = -1000; int mb = -1000; int mnum = -1; for(auto bi = bchoices.begin(); bi != bchoices.end() ; ++ bi) { int b = *bi; int lb = static_cast<int>(std::sqrt(b)); for(int a = -b ; a < 1000 ; ) { int num = primeNumber(a,b,primeset); if(num==-1) { std::cout<<"over"<<std::endl; c = 2*c; primeset = primeList(c); } else if(num>mnum) { mnum = num; ma = a; mb = b; a += 2; } else { a += 2; } } } std::cout<<ma<<' '<<mb<<' '<<ma*mb<<' '<<mnum<<std::endl; }