>>226 課題1. #include <stdio.h> int main(void) { int n, i, count = 0; printf("n: "); scanf("%d", &n); for (i = 2; i * i <= n; i++) { count++; if (n % i == 0) { break; } } if (i * i > n) { printf("%d: %d\n", n, count); } return 0; }
次の1~4の仕様を満たすプログラムを作成しなさい。 1:main 関数において int 型の半径 r をキーボードから受け取る 2:円周( ring )を求める enshu 関数に r を値呼び出しで渡して円周を計算し、 その値を main 関数に return する 3:円の面積( area )を求める menseki 関数に r を参照呼出しで渡して面積を計算し、 その値を main 関数に return する 4:main 関数で return された円周と面積の値を下記の実行結果のように画面表示する
Error! Woops! We can't seem to unshorten that URL, this could be for a few reasons, it may not be a short URL in the first place, it may not be a real URL or could no longer be active or the service used to shorten the URL may not be compatible with Unshorten.It!
MatProduct(int M, int N, double A[M][N],double B[N][M],double C[M][M]){ int m,n,k; for(n=0;n<M;n++)for(m=0;m<M;m++)C[m][n]=0; for(n=0;n<M;n++)for(m=0;m<M;m++)for(k=0;k<N;k++)C[m][n]+=A[m][k]*B[k][n]; }
int main(void){ int matrix[I_SIZE][J_SIZE]={{1,2,3,0},{0,0,0,1},{2,0,0,2},{0,0,0,1}}; int A[I_SIZE*J_SIZE], IA[I_SIZE*J_SIZE], JA[I_SIZE*J_SIZE], IA_[I_SIZE]={0}; int *pA=A, *pIA=IA, *pJA=JA, i, j, c;
・void dot_crs_cpu(double *b, double *x, double *val, int *col_ind, int *row_ptr); ですが、引数に n を渡す必要があるのでは。 void dot_crs_cpu(int n, double *b, double *x, double *val, int *col_ind, int *row_ptr); として、153行目は dot_crs_cpu(n, vector_b,vector_x,val,col_ind,row_ptr);
これはたとえば void setPoint( int refx, int refy, int maxx, int maxy, int *pointx, int *pointy) {*pointx = rand()%(maxx-refx) + refx; *pointy = rand()%(maxy-refy) + refy; }
void recursiveDevide( int refx, int refy, int sizex, int sizey) { setPoint( refx, refy, sizex, sizey, &pointx, &pointy); }
gcc maze_test.c -o maze_test maze_test.c:11: error: expected specifier-qualifier-list before ‘_point’ maze_test.c:20: error: expected ‘;’, ‘,’ or ‘)’ before ‘=’ token maze_test.c: In function ‘RecursiveDivisionMethod’: maze_test.c:45: error: ‘for’ loop initial declaration used outside C99 mode maze_test.c:47: error: redefinition of ‘i’ maze_test.c:45: error: previous definition of ‘i’ was here (略)