Re: [問題] 九九乘法表不用迴圈是叫我直接從1列到81?

看板C_and_CPP (C/C++)作者 (順風相送)時間6年前 (2018/07/30 12:57), 編輯推噓1(101)
留言2則, 2人參與, 6年前最新討論串18/29 (看更多)
本來想要用 CUDA,但是 CUDA 好像不能算是 C,這樣會有爭議, 爭議不好,不要有爭議。 剛才想了想,C 其實也可以寫平行運算, 看,很簡單吧! /* https://ideone.com/XFt0Si */ #include <stdio.h> #include <omp.h> int main(void) { int n=0; omp_set_num_threads(64); #pragma omp parallel #pragma omp critical { printf("%d x %d = %d\n", n/8+2, n%8+2, (n/8+2)*(n%8+2)); n++; } return 0; } $ gcc -fopenmp mul.c $ ./a.out 2 x 2 = 4 2 x 3 = 6 2 x 4 = 8 2 x 5 = 10 2 x 6 = 12 2 x 7 = 14 2 x 8 = 16 2 x 9 = 18 3 x 2 = 6 3 x 3 = 9 3 x 4 = 12 3 x 5 = 15 3 x 6 = 18 3 x 7 = 21 3 x 8 = 24 3 x 9 = 27 4 x 2 = 8 4 x 3 = 12 4 x 4 = 16 4 x 5 = 20 4 x 6 = 24 4 x 7 = 28 4 x 8 = 32 4 x 9 = 36 5 x 2 = 10 5 x 3 = 15 5 x 4 = 20 5 x 5 = 25 5 x 6 = 30 5 x 7 = 35 5 x 8 = 40 5 x 9 = 45 6 x 2 = 12 6 x 3 = 18 6 x 4 = 24 6 x 5 = 30 6 x 6 = 36 6 x 7 = 42 6 x 8 = 48 6 x 9 = 54 7 x 2 = 14 7 x 3 = 21 7 x 4 = 28 7 x 5 = 35 7 x 6 = 42 7 x 7 = 49 7 x 8 = 56 7 x 9 = 63 8 x 2 = 16 8 x 3 = 24 8 x 4 = 32 8 x 5 = 40 8 x 6 = 48 8 x 7 = 56 8 x 8 = 64 8 x 9 = 72 9 x 2 = 18 9 x 3 = 27 9 x 4 = 36 9 x 5 = 45 9 x 6 = 54 9 x 7 = 63 9 x 8 = 72 9 x 9 = 81 -- 桃樂絲: 可是, 如果你沒有頭腦, 為什麼會說話? 稻草人: ㄝ, 我也不知... 但是有些人沒有頭腦也能說超~多話呢。 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 223.140.199.59 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1532926670.A.8BB.html

07/30 22:34, 6年前 , 1F
平行版XD 不考慮開個特大號char array讓64個一起塞嗎?
07/30 22:34, 1F

07/31 10:08, 6年前 , 2F
咦,樓上說的很有道理
07/31 10:08, 2F
文章代碼(AID): #1RNfhEYx (C_and_CPP)
討論串 (同標題文章)
文章代碼(AID): #1RNfhEYx (C_and_CPP)