LoginSignup
0
0

C言語で指定された添字の整数を出力する方法

Posted at

注意!

・ネタバレあり。

学んだこと

・二重ループのiとjの使い方
・添字は0から始まる。

ACしたコード

#include <stdio.h>
int	main(void)
{
	int	r,c;

	scanf("%d%d",&r,&c);
	// printf("%d %d\n",r,c);
	int a[2][2];
	// iは縦に使う
	for (int i = 0; i < 2; i++)
	{
		// jは横に使う
		for (int j = 0; j < 2; j++)
		{
			scanf("%d",&a[i][j]);
			// 標準入力から受け取れているか確認
			//printf("%d ",a[i][j]);
		}
		//printf("\n");
	}
	// 添字は0から始まるので問題文のrとcをそのまま指定するとズレるから-1する必要がある。
	printf("%d\n", a[r - 1][c - 1]);
	return (0);
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0