Salem_c's Profile User Rating: ****-

Reputation: 1689 Grandmaster
Group:
Mentors
Active Posts:
3,209 (2.02 per day)
Joined:
30-May 10
Profile Views:
36,902
Last Active:
User is online 14 minutes ago
Currently:
Viewing Forum: C and C++

Previous Fields

Country:
Who Cares
OS Preference:
Who Cares
Favorite Browser:
Who Cares
Favorite Processor:
Who Cares
Favorite Gaming Platform:
Who Cares
Your Car:
Who Cares
Dream Kudos:
0
Icon   Salem_c has not set their status

Posts I've Made

  1. In Topic: parallelize matrix multiplication function dynamically and statically

    Posted 1 Oct 2014

    It looks to me like you're using all the cores to calculate all the results.

    You need to slice the work up into units you can give to each core.
    int numCores = 4;  // Is there something to tell you this?
    int rowsPerCore = matrixArows / numCores;
    for ( i = 0 ; i < numCores ; i++ ) {
       #pragma omp parallel for schedule(dynamic, chunk)
       for ( r = rowsPerCore * i ; r < rowsPerCore * (i+1) ; r++ ) {
          // etc
       }
    }
    
    
  2. In Topic: how come sscanf == 1 is true when the value in the string is 9a?

    Posted 1 Oct 2014

    Because the first character in the string could be interpreted as an integer, and then the conversion stopped.

    Conversion stops at the first character which doesn't match the format - and it doesn't have to be whitespace.
  3. In Topic: Newton-Raphon method / while loop

    Posted 1 Oct 2014

    > I still get the same error
    And a is still uninitialised.
  4. In Topic: strtok not grabbing arguments

    Posted 30 Sep 2014

    I suggest you start with
    int main ( int argc, char *argv[] ) {
      int i;
      for ( i = 0 ; i < argc ; i++ ) {
        printf("Arg %d = %s\n", i, argv[i] );
      }
      return 0;
    }
    
    


    And discover the difference between
    ./p6 what is going on
    and
    ./p6 "what is going on"
  5. In Topic: SIGFPE error!

    Posted 30 Sep 2014

    It would help if you could learn to indent code properly.
    #include <iostream>
    #include <math.h>
    using namespace std;
    int main()
    {
      long int T, a, b, n;
    
      int digit, flag1, flag2, count, ar[1001] =
          { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67,
        71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149,
        151, 157, 163, 167,
        173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229,
        233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313,
        317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383,
        389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467,
        479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557,
        563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643,
        647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719,
        727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823,
        827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887,
        907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997
      };
      cin >> T;
      while (T--) {
        cin >> a >> b;
        count = 0;
        for (long int i = a; i <= b; ++i) {
          flag1 = 0;
          flag2 = 0;
          n = i;
          if (n % 2 != 0 || n == 2) {
            while (n != 0) {
              digit = n % 10;
              if (digit == 1) {
                flag2 = 1;
                break;
              }
              n = n / 10;
            }
    
            //problem here.....????
            if (flag2 == 0) {
              for (int j = 0; ar[j] <= (int) sqrt(i) && j <= 1000; ++j) {
                if ((i % ar[j]) == 0) {
                  flag1 = 1;
                  break;
                }
              }
              if (flag1 == 0)
                ++count;
            }
          }
        }
        if (count == 0)
          count = -1;
        cout << count << endl;
      }
    
      return 0;
    }
    
    


    Further, just saying 'it crashes' tells us nothing.
    Especially when we have to guess what all the input value(s) you provide to the program.
    I just typed in 1 20 50 and it worked, so where does that leave you?

My Information

Member Title:
void main'ers are DOOMED
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:
Programming Languages:
C, C++, Perl, awk, various assemblers

Contact Information

E-mail:
Private

Comments

Page 1 of 1
  1. Photo

    fromTheSprawl Icon

    07 Sep 2012 - 02:38
    Please read my thread. I kid! Just want to say your forum avatar is awesome. ^^
  2. Photo

    Salem_c Icon

    26 Dec 2010 - 01:36
    Do not PM me for 1:1 support, or to try to get me to read your threads.
Page 1 of 1