C#/수업 내용
for문 연습(구구단 만들기)
Game Client Lee Hwanguk
2023. 1. 3. 10:56
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace study01
{
class Program
{
static void Main(string[] args)
{
//2X1=2
//2X2=4
//2X3=6
//2X4=9
//2X5=10
for(int i=0; i<5; i++)
{
int b = i + 1;
int a = b * 2;
Console.WriteLine("2x{0}={1}", b,a);
}
}
}
}
//i는 몇번 곱하는지
//i는 0부터 시작함으로 b=i+1;
//1씩 증가한 i를 b에 넣고 곱한 값을 a에 넣어준다.
2*1=2
2*2=4
2*3=6
2*4=8
2*5=10
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace study01
{
class Program
{
static void Main(string[] args)
{
//원하는 구구단 단수를 입력하세요.
Console.Write("원하는 단수를 입력하세요");
string input = Console.ReadLine(); //int로 변환 필요
int dan = Convert.ToInt32(input);
Console.WriteLine("{0}단", input);
//9번 반복
for(int i=0; i<9; i++)
{
int num = i + 1;
int result = dan * num;
//단수 *num=단수*num 3*1=3 3*2=6 ....
Console.WriteLine(" {0}x{1}={2}", input, num, result); ;
}
}
}
}