• 締切済み

プログラムのフローチャートがかけません。

次のプログラムのフローチャート(流れ図)を書いてください。お願いします。 フローチャートの書き方は以下のwebから見れます。 http://sasuke.main.jp/furo.html #include<stdio.h> #include<math.h> #include<stdlib.h> #define MAX_DATA_NUMBER 400 int check_value(int x, char* error_message); int main(int argc ,char*argv[]){ int M=0 ,i=0,N,U double x[2][MAX_DATA_NUMBER],y_bunshi FILE *in_file; in_file = fopen(argv[1],"r"); M = 0; if(argc != 3){ printf("使い方: ./smooth 入力データファイル名 平滑化数N"); exit(1); } N = check_value(atof(argv[2]),"平滑化数は正の値を入力してください。\n使い方: ./smooth 入力データファイル名 平滑化数N"); if(argc == 3){ if( in_file == NULL){ printf("使い方: ./smooth 入力データファイル名 平滑化数"); exit(1); } } while( EOF != fscanf(in_file, "%lf", &x[0][M]) && M<MAX_DATA_NUMBER){ M++; } fclose(in_file); for(i=0;i<=N-1;i++){ y_bunshi = 0; for(U=0;U<=i+N;U++){ y_bunshi += x[0][U]; } x[1][i] = y_bunshi/(i+N+1); } for(i=N;i<M-N;i++){ y_bunshi = 0; for(U=1;U<=N;U++){ y_bunshi += x[0][i+U]; y_bunshi += x[0][i-U]; } y_bunshi += x[0][1]; x[1][i] = y_bunshi/(2*N+1); } for(i=M-N;i<=M-1;i++){ y_bunshi = 0; for(U=i-N;U<=M-1;U++){ y_bunshi += x[0][U]; } x[1][i] = y_bunshi/(M+N-i); } for(i=0;i<M;i++){ printf("%3d,%8.2f,%8.3f\n",i,x[0][i],x[1][i]); } return 0; int check_value(int x,char* error_message){ if( x <= 0.0){ printf(error_message); exit(1); return x; }

みんなの回答

  • kmee
  • ベストアンサー率55% (1857/3366)
回答No.1

コンパイルができない、つまり、動作しないプログラムからフローチャートを書くことは無理です。

関連するQ&A

  • 偏微分のプログラムについてです.

    (∂^2 u)/(∂x^2 )+(∂^2 u)/(∂y^2 )=2(x^2+y^2 ) 境界上でu(0,y)=u(x,0)=0,u(1,y)=y^2,u(x,1)=x^2である.点(0.5,0.5)の値を求めよ.その際きざみ幅を幾つか変化させることで,反復回数がどのように変化するか確かめよ. という問題です.自分で以下のプログラムを作ったのですが,コンパイルされません.ぜひどこがおかしいか教えてください. #include<stdio.h> #define EPS 10e-6 #define N 100 #define M 100 main(void){ int i,j; int n=19,m=19,r=0; double h,x0,S; double u1[N][M],u2[N][M]; h=2.0/(n+1); for(i=0;i<n+2;i++){ for(j=0;j<m+2;j++){ u1[i][j]=0.0; } } do{ for(i=0;i<n+2;i++){ u2[i][0]=0.0; u2[i][m+1]=0.0; } for(j=0;j<m+2;j++){ u2[0][j]=0.0; u2[n+1][j]=0.0; } for(i=1;i<n+1;i++){ for(j=1;j<m+1;j++){ u2[i][j]=(u1[i-1][j]+u1[i][j+1]+u1[i+1][j]+u1[i][j-1]+2.0*h*h)/4.0; } } r++; S=fabs(u1[(n+1)/2][(m+1)/2]-u2[(m+1)/2][(m+1)/2]); for(i=0;i<n+2;i++){ for(j=1;j<m+1;j++){ u1[i][j]=u2[i][j]; } } } while(S>EPS); x0=u2[(n+2)/2][(m+2)/2]; printf("きざみ幅=%lf\n",h); printf("反復回数=%d\n",r); printf("点(0.5,0.5)=%lf\n",x0); }

  • 並べ替えのプログラム

    整数を20個入力し、まずそのまま表示してその後大きい順に並べ替えて表示するプログラムを作っているのですが、最大値しか表示されません。多分for文の3重ループの中がおかしいと思うのですがよくわかりません。 #include <stdio.h> int main(int argc, char* argv[]) { int c,i,x,max; int sav = 0; int before[20]; int after[20]; int check[20] = {0}; printf("整数を20個入力してください: "); for(i = 0; i < 20; i++) { scanf("%d",&before[i]); } printf("\n"); printf("BEFORE\n"); for(i = 0; i < 20; i++) { printf("%d\n",before[i]); } printf("\n"); max = 0; for(c = 0; c < 20; c++) { for(x = 0; x < 20; x++) { for(i = 0; i < 20; i++) { if(before[i] > max && check[i] == 0) max = before[i]; sav = i; } if(check[sav] == 0) check[sav] = 1; after[19 - x] = max; } } printf("AFTER\n"); for(x = 0; x < 20; x++) { printf("%d\n",after[x]); } return 0; } よろしくお願いします。

  • ラベリング処理プログラム

    画像のラベリング処理プログラムを作っているんですが どうもうまく実行できません。よければ教えていただけないでしょうか。 #include<stdio.h> #include<stdlib.h> int column, row; unsigned char val[4] = {0,0,0,0}; unsigned char tmp[255]; int pos_y[4] = {-1, 0, 1, 0}; int pos_x[4] = {0, 1, 0, -1}; int i, j, x, y, label, level, label1; int label_count = 1; unsigned char *in, *out; void labeling_main(); void labeling_search(); void labeling_main() { for(i = 0; i < y; i++){ for(j = 0; j < x; j++){ printf("aaa\n"); if(out[i * x + j] == 255){ printf("bbb\n"); fflush(stdout); out[i * x + j] = label_count; labeling_search(label_count, i, j); label_count++; } } } } void labeling_search(int label_count, int x, int y) { for(i = 0; i < 4; i++){ if(out[(pos_y[i] + y) * x + (pos_x[i] + x)] == 255){ out[(pos_y[i] + y) * x + (pos_x[i] + x)] = label_count; labeling_search(label_count,(pos_y[i]+y),(pos_x[i]+x)); } } printf("ccc\n"); } int main(int argc, char *argv[]) { int result; int head, Magic; unsigned char *image, *in, *out, *res, *ros; FILE *fin, *fout; if(argc!=3){ printf("Usage : %s input output\n",argv[0]); exit(1); } fin = fopen(argv[1],"rb"); /* -------------------- ヘッダ取得ここから -------------------- */ fgets(tmp,255,fin); if(tmp[0]!='P') return 0; sscanf(tmp,"P%d",&Magic); if(Magic < 1 || Magic > 6) return 0; do fgets(tmp,255,fin); while(tmp[0]=='#'); sscanf(tmp,"%d %d",&x,&y); if(x < 1 || y < 1) return 0; fgets(tmp,255,fin); sscanf(tmp,"%d",&level); /* ヘッダの確認 */ printf("P%d\n",Magic); printf("%d %d\n",x,y); printf("%d\n",level); /* 画素の読み込み */ in = (unsigned char *)malloc(sizeof(unsigned char) *x*y); fread(in,sizeof(unsigned char),x*y,fin); fout = fopen(argv[2],"wb"); fprintf(fout,"P%d\n",Magic); fprintf(fout,"# My new PGM\n"); fprintf(fout,"%d %d\n",x, y); fprintf(fout,"%d\n",level); fwrite(out, sizeof(unsigned char),x*y, fout); out = (unsigned char *)malloc(sizeof(unsigned char) *x*y); //2値画像 for (i = 0; i < y; i++) { for (j = 0; j < x; j++){ if(in[i * x + j] > 120){ out[i * x + j] = 0; }else if(in[i * x + j] <= 120){ out[i * x + j] = 255; } } } labeling_main(); printf("Max label number:%d\n",label_count); free(in); free(out); fclose(fin); fclose(fout); } コンパイルは通るのですが実行するとlabeling_mainの if文でセグメンテーションが出てしまいます。

  • プログラムの作成

    Cで、キ-ボ-ドから整数を1個(mとする)、実数を1個(xとする)それぞれ入力し、 S=Σ(n=0からmまで)1/2n+1×(x-1/x+1)^2n+1 の値を求めるプログラムを作ってみたのですが、あってるかどうかわかりますか? #include<stdio.h> #include<math.h> main() { double y=0; int i,m,x; printf(\" Input m: \") scanf(\"%lf\", &m); printf(\" Input x: \") scanf(\"%lf\", &x); for(i=0; i <= m; i++) { y += 1/(2*i+1)*pow((x-1)/(x+1),2*i+1) } printf(\" S = %d\n\", y) }

  • CUDAプログラムが実行できません。

    行列の加算プログラムを作成したいのですが、どうもGPUとのやり取りがうまくいってないみたいです。 コンパイルは通るのですが、ホスト側で0を渡して計算結果をデバイス側から返すはずなのですが、計算結果ではなく0が返ってきます。 なので、GPUとのやり取りの部分だけを抜粋したプログラムを載せるので、ご指摘よろしくお願いします。 環境はUbuntu12.04.、CUDA5.0、GPUはtesla k20です。 #include <stdio.h> #include <malloc.h> #include <stdlib.h> #include <cublas.h> #define N 64 #define BLOCK 16 __global__ void matrixMul(int* inMatA); int main(int argc,char** argv){ //cudaError_t CuErr; int matrixSize=sizeof(unsigned int)*N*N; int* hMatA; hMatA=(int*)malloc(matrixSize); int x,y; for(x=0;x<N;x++){ for(y=0;y<N;y++){ hMatA[x*N+y]=1; } } printf("hMatA \n"); for(x=0;x<N;x++){ for(y=0;y<N;y++){ printf("%d ",hMatA[x*N+y]); } printf("\n"); } int* dMatA; cudaMalloc((void**)&dMatA, matrixSize); cudaMemcpy(dMatA, hMatA, matrixSize, cudaMemcpyHostToDevice); dim3 block(BLOCK,BLOCK); dim3 grid(N/BLOCK,N/BLOCK); matrixMul<<<grid,block>>>(dMatA); cudaThreadSynchronize(); cudaMemcpy(hMatA, dMatA, matrixSize, cudaMemcpyDeviceToHost); printf("hMatA \n"); for(x=0;x<N;x++){ for(y=0;y<N;y++){ printf("%d ",hMatA[x*N+y]); } printf("\n"); } free(hMatA); cudaFree(hMatA); cudaThreadExit(); } __global__ void matrixMul(int* inMatA){ int x,y; for(y=0;y<N;y++){ for(x=0;x<N;x++){ inMatA[x+y*N]=0; } } }

  • プログラムの練習問題をやっていたのですが、練習問題の答えのような実行結

    プログラムの練習問題をやっていたのですが、練習問題の答えのような実行結果にならないので教えていただけませんか? 下記に記したプログラムを実行すると x=9 y=-9 [ 9]*[-9]=[ -81],[ 9]*[-8]=[ -72],[ 9]*[-7]=[ -63],・・・・ ・・・・ [10]*[-9]=[ -90],[10]*[-8]=[-80],・・・・ ・・・・ のようになるのですが、 x=9 y=-9 [ 9]*[-9]=[ -81],[10]*[-9]=[-90],・・・ [ 9]*[-8]=[ -72],[10]*[-8]=[-80],・・・ [ 9]*[-7]=[ -63],・・・ ・・・・ のようにするためにはどうすればいいですか? #include <stdio.h> int main(void) { int x,y,m,n; printf("x="); scanf("%d",&x); printf("y="); scanf("%d",&y); for(m=x;m<=x+3;m++) { printf("\n"); for(n=y;n<=y+14;n++) { printf("[%2d]*[%2d]=[%4d],",m,n,m*n); } printf("\n"); } return(0); }

  • c言語のプログラムで行列の積を計算する

    指定された行・列数(それぞれ10以下とする)の行列 X, Y の積 Z = X × Y を求めるプログラムを作成せよ.行列の要素はすべて整数とする. このプログラムで行と列の成分を入力するときに、1列になってしまうのですがどうしたらちゃんと入力できますか? int main(void) { double A[10][10]; double B[10][10]; int i,j,m,n,p,k; printf("行列xの行数は?:"); scanf("%d",&m); printf("行列xの列数(行列yの行数)は?:"); scanf("%d",&n); printf("行列yの列数は?:"); scanf("%d",&p); printf("行列xを入力してください。\n"); for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { scanf("%d", &A[i][j]); } } printf("行列yを入力してください。\n"); for (i = 0; i < n; i++) { for (j = 0; j < p; j++) { scanf("%d", &B[i][j]); } }

  • C言語について プログラムが動きません

    ゲームのプログラムを作りたいものです。 今、試作の途中の段階で以下のようなプログラムを作ってみたのですが、 コアダンプが表示されてうまく起動しません。 どの点を変更すればいいのか、教えてください。 使っている言語はC言語です。 よろしくお願いいたします。 #include <stdio.h> #include <string.h> struct monster{ int type; /* タイプ */ char trick[25]; /* 技 */ char trick2[25]; /* 技2 */ int tricktype; /* 技1のタイプ */ int tricktype2; /* 技2のタイプ */ int trickeffect; /* 技1の威力 */ int trickeffect2; /* 技2の威力 */ char name[10]; /* 名前 */ int attack; /* 攻撃力 */ int diffence; /* 防御力 */ int speed; /* 素早さ */ /* 1,fire 2,water 3,nature 4,thunder 5,wind */ }; char names[5][10] = {"v", "w", "x", "y", "z"}; main(){ int s = 0; int a[3]; int i; int m; struct monster monster[5] = { { 1, "a", "b", 1, 2, 120, 80, "v", 60, 60, 60}, { 2, "a", "b", 2, 3, 120, 80, "w", 60, 60, 60}, { 3, "a", "b", 3, 4, 120, 80, "x", 60, 60, 60}, { 4, "a", "b", 4, 5, 120, 80, "y", 60, 60, 60}, { 5, "a", "b", 5, 1, 120, 80, "z", 60, 60, 60}, }; printf("好きなモンスターを3つ選んでください\n\n"); while (s < 1){ for (i = 0; i++; i<3){ printf("%d体目を選んでください。\n\n", i+1); for(m = 0; m++; m < 4) printf("%d, %s\n", m+1, monster[m].name); printf("5, %s\n\n", monster[4].name); scanf("%d", a[i]); printf("%d体目 : %s\n\n", i+1, monster[a[i]-1].name); } printf("これでよろしいですか?\n"); for(i = 0; i++; i<2) printf("%d体目 : %s ", i+1, monster[a[i]-1].name); printf("3体目 : %s\n\n", monster[a[2]-1].name); printf("1、はい 2、いいえ\n"); scanf("%d", &i); if(i=1) return s = 1; else return s = 0; } }

  • 複素数の絶対値について

    このプログラムでx2[i]y2[i]の絶対値の2乗がほしいんですけどどうすればよろしいで しょうか?? #include <stdio.h> #include <stdlib.h> #include <math.h> #define PI 3.14159265358979323846 /*省略*/ /* FFT main routine */ int fft(n, x, y) /*省略*/ /*** Main Program ***/ #define N 256 int main(argc, argv) int argc; char *argv[]; { FILE *fp; int i; static float x1[N], y1[N], x2[N], y2[N], x3[N], y3[N]; if ((fp = fopen(c1.txt, "r")) ==NULL){ printf ("File Open Error \"%s \" file.\n", c1.txt); exit(1); } for (i = 0; i < N; i++) { fscanf(fp, "%f", &x1[i]); x2[i] = x1[i] ; y1[i] = y2[i] = 0; } if (fft(N, x2, y2)) return EXIT_FAILURE; for (i = 0; i < N; i++) { x3[i] = x2[i]; y3[i] = y2[i]; } if (fft(-N, x3, y3)) return EXIT_FAILURE; printf(" Original data Fourier Transformed Inverse Transformed\n"); for (i = 0; i < N; i++) printf("%4d | %6.3f %6.3f | %6.3f %6.3f | %6.3f %6.3f\n", i, x1[i], y1[i], x2[i], y2[i], x3[i], y3[i]); return EXIT_SUCCESS; }

  • プログラムの改良。

    うまく改良できなくて困っています。 このプログラムを #include <stdio.h> #include <stdlib.h> /* データ用変数 */ struct xy {  int x;  int y; } *hil; int idx; /* ヒルベルトスキャン */ void hilbert(int n, int p, int x, int y) {  if (n>1) {   hilbert(n/2, (p+4)%8, x+(p&1)*(n/2), y+((p>>1)&1)*(n/2));   hilbert(n/2, p, x+((((p>>1)^(p>>2)))&1)*(n/2), y+(~(p^(p>>2))&1)*(n/2));   hilbert(n/2, p, x+(~p&1)*(n/2), y+(~(p>>1)&1)*(n/2));   hilbert(n/2, 7-p, x+(~((p>>1)^(p>>2))&1)*(n/2), y+((p^(p>>2))&1)*(n/2));  } else {   hil[idx].x=x; hil[idx].y=y; idx++;  } } int main(void) {  int i,n;  /* nの入力と領域確保 */  printf("n? "); scanf("%d",&n);  if((hil=(struct xy*)malloc(sizeof(struct xy)*(1<<n)*(1<<n)))==NULL) {   printf("malloc error\n"); return -1;  }  /* ヒルベルトスキャン */  idx=0; hilbert((1<<n),4,0,0);  /* データ表示 */  for (i=0; i<idx; i++) {   printf("%d ([d %d]\n",i,hil[i].x,hil[i].y);  }  /* 領域開放 */  free(hil);  return 0; } 実行結果はn?8 0 [0 0] 1 [0 1] ・ ・ 65534 [0 254] 65535 [0 255] と表示されます。これを buf[0]=img[hil[0].x][hil[0].y][0] buf[1]=img[hil[0].x][hil[1].y][0] ・ ・ buf[65534]=img[hil[0].x][hil[254].y][0] buf[65535]=img[hil[0].x][hil[255].y][0] と表示させたいのですがうまくできません。どこを改良すればいいでしょうか?お願い致します。 buf[]の中身は0から256*256-1を表しています。