Monday, August 22, 2011

Latihan Perulangan Baris


// Run with Microsoft Visual Studio C# 2010
// And Console Application
// Its function is to ask your number
// Then will printed rows as number as you ask
// Finally click 'y' to Exit


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

namespace perulangan_baris
{
    class Program
    {
        static void Main(string[] args)
        {
            int b = 1;
           
            Console.WriteLine(" ");
            Console.WriteLine(" ");
            Console.WriteLine(" ");
            Console.Write("Berapa baris yang anda inginkan? ");
            string i = Console.ReadLine();
            int jumlah = Int32.Parse(i);
            Console.WriteLine(" ");
            Console.WriteLine(" ");

            for (b = 1; b <= jumlah; b++)
            {
                Console.WriteLine("Ini adalah baris yang ke-" + b);
                if (b % 10 == 0)
                    Console.WriteLine(" ");
            }

            bool lagi = true;

            while (lagi)
            {
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("Klik y + Enter untuk exit");
                string jawab = Console.ReadLine();
               
                if (jawab == "y") lagi = false;
                else lagi = true;
            }
        }
    }
}


Back to Home

Related Articles

0 comment:

Post a Comment