using System;

class Reverse
{
 static void Main()
 {
  Console.WriteLine("원하는 숫자나 문자를 입력해주세요!");
  String strLine = Console.ReadLine();
  Char[] ch = strLine.ToCharArray(); //String 변수는 char[] 배열로 만듬;

  for (int index = ch.Length - 1; index >= 0; index--) //
  {
   Console.Write(ch[index]);
  }

  Console.ReadLine();
 }
}

using System;

public class ArrayMethods 
{
 public static void Main() 
 {
  int[ ] arr = new int[10];
 
  Console.WriteLine("10개의 숫자를 입력해주세요");
  for(int i =0;i<10;i++)
  {
   Console.WriteLine("{0}번째 숫자 입력해주세요",i+1);
   arr[i]=int.Parse(Console.ReadLine());
  }

  Console.WriteLine( "Before sorting:" );
  foreach (int i in arr) Console.Write(i+"\t ");
  Console.WriteLine();

  Array.Sort( arr );    // 올림차순 정렬
  Console.WriteLine( "After sorting:" );
  foreach (int i in arr) Console.Write(i+"\t ");
  Console.WriteLine();

  Array.Reverse( arr ); // 내림차순 정렬
  Console.WriteLine( "After Reverse Sorting:" );
  foreach (int i in arr) Console.Write(i+"\t ");
  Console.WriteLine();
 
 
  int index55 = Array.IndexOf(arr,55); // 55가 처음 나오는 위치
  Console.WriteLine("Index of 55:");
  Console.WriteLine(index55);

  int lastIndex55 = Array.LastIndexOf(arr,55);

  // 마지막에서부터 55가 처음 나오는 위치
  Console.WriteLine("LastIndex of 55:");
  Console.WriteLine(lastIndex55);

  Array.Clear(arr, 0, 5); // 0번째부터 5번째까지 0으로 초기화
  Console.WriteLine("Cleared 0 to 5:");
  foreach (int i in arr) Console.Write(i+"\t ");
  Console.ReadLine();

 } //main
} //class

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[,] A = new int[2, 2];
            int[,] B = new int[2, 2];
            int[,] Result = new int[2, 2];

            //미리 입력 해 놓고 계산 하실거면 이걸 쓰세요.
            //그리고 입력 부분 for문은 삭제 하시구요.
            //int[,] A =
            //    {
            //        {3, 2},
            //        {1, 4}
            //    };
            //int[,] B =
            //    {
            //        {9, 2},
            //        {1, 7}
            //    };

            //입력 부분입니다.
            //행렬을 A, B로 정하셔서 배열을 두개 생성 했습니다.
            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    Console.Write("{0},{1}부분 입력: ", i, j);
                    A[i, j] = Int32.Parse(Console.ReadLine());
                }//end of for2
            }//end of for1
            Console.WriteLine();
            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    Console.Write("{0},{1}부분 입력: ", i, j);
                    B[i, j] = Int32.Parse(Console.ReadLine());
                }//end of for2
            }//end of for1

            Console.WriteLine();

            //계산 하는 부분입니다.(A*B)
            for (int i = 0; i < 2; i++)
            {
                Result[i, 0] = A[i, 0] * B[0, 0] + A[i, 1] * B[i, 0];
                Result[i, 1] = A[i, 0] * B[0, 1] + A[i, 1] * B[1, 1];
            }//end of for1

            //결과값 출력 부분입니다.
            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    Console.Write("{0} ", Result[i, j]);
                    if (j == 1) Console.WriteLine();
                }//end of for2
            }//end of for1
        }//end of Main
    }//end of Program_Class
}//end of namespeace

//3개의 정수를 콘솔로부터 입력 받아 내림차순으로 정렬하여 출력하는 프로그램

using System;
using System.Collections;
using System.Text;

namespace ConsoleApplication1
{
 class Program
 {
  static void Main(string[] args)
  {
   int[] bubblesort = new int[3];//입력 후 최종 sort결과
   int temp = 0;

   Console.WriteLine("출력-----------------------------");
   Console.WriteLine();

   //숫자 입력 부분
   for (int i = 0; i < 3; i++)
   {
    Console.WriteLine("{0}번째", i + 1);
    bubblesort[i] = Int32.Parse(Console.ReadLine());
   }
   

   //숫자 정렬 부분
   for (int i = 0; i < 2; i++)
   {
    for (int j = 0; j < 2 - i; j++)
    {
     //두 숫자 비교해서 뒷쪽이 크면 교환(정렬은 bubble sort 알고리즘)
     if (bubblesort[j] > bubblesort[j + 1])
     {
      temp = bubblesort[j];
      bubblesort[j] = bubblesort[j + 1];
      bubblesort[j + 1] = temp;
     }
    }//end of for2
   }//end of for1

   Console.WriteLine();

   //정렬된 숫자 출력 부분
   for (int i = 0; i < 3; i++)
   {
    Console.WriteLine(bubblesort[i]);
   }//end of for

   Console.WriteLine("---------------------------------");
   Console.ReadLine();
  }//end of Main
 }//end of Program_Class
}//end of namespeace


/// 배열을 이용한 구구단
using System;

 class GUGU
 {
  ///
  /// 해당 응용 프로그램의 주 진입점입니다.
  ///
  [STAThread]
  static void Main(string[] args)
  {

   int[] value1 = new int[9] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
   int[,] value2 = new int[9,9];

   for (int i = 1; i < 9; i++)
   {
    Console.WriteLine();
    Console.WriteLine(" {0}단 구구단", value1[i]);
   
    for (int j = 0; j < 9; j++)
    {
     value2[i,j] =  value1[i] * value1[j];

     Console.WriteLine("{0}x{1}={2}", value1[i], value1[j], value2[i,j]);
    }

/// 그냥 구구단
using System;

 class GUGU
 {
  ///
  /// 해당 응용 프로그램의 주 진입점입니다.
  ///
  [STAThread]
  static void Main(string[] args)
  {

   for (int i = 2; i <= 9; i++)
   {
   
    Console.WriteLine(" {0}단입니다.", i);
   
    for (int j = 1; j <= 9; j++)
    {
     Console.WriteLine("{0}x{1}={2}", i, j, i*j);
    }
   
   }
   
   Console.ReadLine();
   
  }
 }

   
   }
   Console.ReadLine();
  }
 }


 

C#을 이용한 테트리스 프로그래밍

+ Recent posts