初歩的な質問なんですが

フォーラム(掲示板)ルール
フォーラム(掲示板)ルールはこちら  ※コードを貼り付ける場合は [code][/code] で囲って下さい。詳しくはこちら
K-I

初歩的な質問なんですが

#1

投稿記事 by K-I » 18年前

#include <stdio.h>
void main(void)
{
int a,b;

for (a=2;a<11;a++)
		for (b=1;b<10;b++){
			printf("%2d\n",a);
			printf("%2d\n",b);
}		}
結果
2
1
2
2
2
3
2
4
2
5
2
6
2
7
2
8
2
9
3
1
3
2
3
3
3
4
3
5
3
6
3
7
3
8
3
9
4
1
4
2
4
3
4
4
4
5
4
6
4
7
4
8
4
9
5
1
5
2
5
3
5
4
5
5
5
6
5
7
5
8
5
9
6
1
6
2
6
3
6
4
6
5
6
6
6
7
6
8
6
9
7
1
7
2
7
3
7
4
7
5
7
6
7
7
7
8
7
9
8
1
8
2
8
3
8
4
8
5
8
6
8
7
8
8
8
9
9
1
9
2
9
3
9
4
9
5
9
6
9
7
9
8
9
9
10
1
10
2
10
3
10
4
10
5
10
6
10
7
10
8
10
9
なんですが
これを
2
1
3
2
4
3
と表示させたいんですがどうしたらいいんでしょうか?
いろいろ試してみたんですがこの方法じゃ私がやりたいことは出来ないんでしょうか?
どなたかアドバイスお願いします。結果長くてすみません

組木紙織

Re:初歩的な質問なんですが

#2

投稿記事 by 組木紙織 » 18年前

どのように表示すれば良いかが十分分かりません。
もう少し詳しく教えて下さい。

box

Re:初歩的な質問なんですが

#3

投稿記事 by box » 18年前

もしかして、こういうことですか?

#include <stdio.h>

int main(void)
{
	int i;
	
	for (i = 2; i <= 4; i++)
		printf("%d\n%d\n", i, i - 1);
	return 0;
}

K-I

Re:初歩的な質問なんですが

#4

投稿記事 by K-I » 18年前

前ここで数独の質問をしたものなんですが
#include <stdio.h>
int map1[9][9];
/* m:Mondai */
/**int p[9][9]={{0,0,9,0,5,0,0,0,3},
	         {0,0,3,7,0,0,2,0,5},
	   	     {8,0,0,0,3,0,0,6,0},
		     {3,0,0,0,6,0,0,0,1},
		     {5,0,0,0,7,0,0,0,9},
		     {9,0,0,4,2,0,0,0,8},
		     {0,5,0,0,9,0,0,0,7},
		     {2,0,7,0,0,3,1,0,0},
		     {6,0,0,0,4,0,9,0,0}};
			 */
			 int p[9][9]={{0,0,6,0,0,0,0,0,1},
	         {0,7,0,0,6,0,0,5,0},
	   	     {8,0,0,1,0,3,2,0,0},
		     {0,0,5,0,4,0,8,0,0},
		     {0,4,0,7,0,2,0,9,0},
		     {0,0,8,0,1,0,7,0,0},
		     {0,0,1,2,0,5,0,0,3},
		     {0,6,0,0,7,0,0,8,0},
		     {2,0,0,0,0,0,4,0,0}};
void disp()
{	int i,j;

//結果を表示//

	for (i=0;i<9;i++){
		for (j=0;j<9;j++){
			printf("%2d",p[j]);
		}
		printf("\n");
	}
}

void main(void)
{
	int i,j,k;
	int count_0,count_;
	int x,y;		
	int r,s,t=3;       
	int a,b,c;   

	
	//map1のマスを0にし//
	//正しい値の入る場所を作る//
	
	START:
	for (a=2;a<11;a++)
		for (b=1;b<10;b++){
	for (i=0;i<9;i++){
		for (j=0;j<9;j++) map1[j]=0;
	}
	
	for (i=0;i<9;i++){
		for (j=0;j<9;j++){
			if (p[j] !=0) map1[j]=a;
			if (p[j] ==b){	map1[j]=b;
				for(k=0;k<9;k++){
					if(map1[k][j] ==0) map1[k][j]=a;
					if(map1[k] ==0) map1[k]=a;
				}
			}
		}
	}
	//3*3のマスに0が一つと同じ数字が8つの場合0に正しい値を入れる//
	
   for(x=0; x<3; x++){
		for(y=0; y<3; y++){
			r=x*3;
			s=y*3;
				count_0=0;
				count_=0;
				for(i=r; i<r+t; i++){
					for(j=s; j<s+t; j++){
						if( map1[j] == 0)
							count_0 +=1;
						else if( map1[j] == a )
							count_ +=1;
					}
				}
				if( (count_0 == 1) && (count_ == 8)){	
					for(i=r; i<r+t; i++){
						for(j=s; j<s+t; j++){
							if( map1[i][j] == 0){
								p[i][j] = b;
								if(count_0 != 0) goto START;
							}
						}
					}
				}
}}}
	disp();

}


このプログラムでaに2bに1で一回りしてまた戻って次はaに3bに2と入れていきたいんですが このままだと
aに2bに1に2bに2がはいってしまうんです
説明下手ですみません いい方法はないでしょうか?

閉鎖

“C言語何でも質問掲示板” へ戻る