You are on page 1of 8

BÀI TẬP PROGRAMMING

1. Students information
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StudentInformation
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("name");
string name = (Console.ReadLine());
Console.WriteLine("age");
int age = int.Parse(Console.ReadLine());
Console.WriteLine("grade");
double grade = double.Parse(Console.ReadLine());
Console.WriteLine();
}
}
}

2. Passed or Falied
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace baitap
{
internal class Program
{
static void Main(string[] args)
{
var grade = double.Parse(Console.ReadLine());
if (grade >= 3.00)
{
Console.WriteLine("Passed!");
}
else
{
Console.WriteLine("Failed");
}
Console.ReadLine();
}
}
}

3. Back in 30 minutes
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp3
{
internal class Backin30minutes
{
static void Main(string[] args)
{
Console.WriteLine("Program: Back in 30 minutes");
int hour = int.Parse(Console.ReadLine());
int minutes = int.Parse(Console.ReadLine()) + 30;
if (minutes > 59)
{
hour += 1;
if (hour > 23)
{
hour -= 24;
}
minutes -= 60;
}
if (minutes < 10)
{
Console.WriteLine(hour + ":" + "0" + minutes);
}
else if (minutes >= 10)
{
Console.WriteLine(hour + ":" + minutes);
}
Console.ReadLine();
}
}
}
4. Month Printer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Monthprinter
{
public class Program
{

static void Main()


{
int monno;
Console.WriteLine("\n\n");
Console.WriteLine("Read month number and display month name: \n");
Console.WriteLine("--------------------------------------------");
Console.WriteLine("\n\n");
Console.WriteLine("Input Month No: ");
monno = Convert.ToInt32(Console.ReadLine());
}
switch (monno)
{
case 1:
Console.WriteLine("January\n");
break;
case 2:
Console.WriteLine("February\n");
break;
case 3:
Console.WriteLine("March\n");
break;
case 4:
Console.WriteLine("April\n");
break;
case 5:
Console.WriteLine("May\n");
break;
case 6:
Console.WriteLine("June\n");
break;
case 7:
Console.WriteLine("July\n");
break;
case 8:
Console.WriteLine("August\n");
break;
case 9:
Console.WriteLine("September\n");
break;
case 10:
Console.WriteLine("October\n");
break;
case 11:
Console.WriteLine("November\n");
break;
case 12:
Console.WriteLine("December\n");
break;
default:
Console.WriteLine("invalid Month number. \nPlease try again ....\n");
break;
}
Console.WriteLine();
}
}
5. Foreign languages
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace foreignlanguages
{
internal class Program
{
private static string languge;

static void Main(string[] args)


{
Console.WriteLine("Foreign langueges");
string languges = Console.ReadLine();
Console.WriteLine("Languge of the conutry is: ");
switch (languge)
{
case "USA":
case "England":
Console.WriteLine("English");
break;
case "Spain":
case "Argentina":
case "Mexico":
Console.WriteLine("Spanish");
break;
default:
Console.WriteLine("Unknown");
break;
}
Console.WriteLine();
}
}
}
6. Theatre Promotions
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace theatrepromotion
{
internal class Program
{
static void Main(string[] args)
{
string day = Console.ReadLine().ToLower();
int age = int.Parse(Console.ReadLine());
int price = 0;
if (day == "weekday")
{
if ((age >= 0 && age <= 18) || (age > 64 && age <= 122))
{
price = 12;
}
else if (age > 18 && age <= 64)
{
price = 18;
}
}
if (day == "weekend")
{
if ((age >= 0 && age <= 18) || (age > 64 && age <= 122))
{
price = 15;
}
else if (age > 18 && age <= 64)
{
price = 20;
}
}
if (day == "holiday")
{
if (age >= 0 && age <= 18)
{
price = 5;
}
else if (age > 18 && age <= 64)
{
price = 12;
}
else if (age > 64 && age >= 122)
{
price = 10;
}
}
if (price > 0)
{
Console.WriteLine($"{price}&");
}
else
{
Console.WriteLine("Error!");
}
Console.ReadLine();
}
}
}
7. Divisible by 3
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp7
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Divided by 3: ");
for (int i = 1; i <= 100; i++)
{
if (i % 3 == 0)
{
Console.WriteLine(i);
}
}
Console.ReadLine();
}
}
}
8. Sum of odd numbers
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SumOfOddNumbers
{
internal class Program
{
static void Main(string[] args)
{
int i, n, sum = 0;
Console.Write("\n\n");
Console.Write("Display the sum of n odd natural number: \n");
Console.Write("-------------------------------------------");
Console.Write("\n\n");
Console.Write("Input number of terms: ");
n = Convert.ToInt32(Console.ReadLine());
Console.Write("The odd numbers are: \n");
for (i = 1; i <= n; i++)
{
Console.Write("{0}", 2 * i - 1);
sum += 2 * i - 1;
}
Console.Write("The Sum of odd Natural Number upto {0} terms: {1} \n", n, sum);
Console.ReadLine();
}
}
}
9. Multiplication table
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MultiplicationTable
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Multiplication Table of number: ");
var number = int.Parse(Console.ReadLine());
var times = 1;
while (times <= 10)
{
Console.WriteLine($"{number} X {times} = {number * times}");
times++;
}
Console.ReadLine();
}
}
}
10.Multiplication table 2.0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MultipcationTable2
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Input two integer: ");
int number = int.Parse(Console.ReadLine());
int times = int.Parse(Console.ReadLine());
do
{
Console.WriteLine($"{number} X {times} = {number * times}");
times++;
}
while (times <= 10);
Console.ReadLine();
}
}
}
11.Even number
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EvenNumber
{
internal class Program
{
static void Main(string[] args)
{
var n = 0;
while (true)
{
Console.WriteLine("Enter even number: ");
n = int.Parse(Console.ReadLine());
if (n % 2 == 0)
{
break;
}
Console.WriteLine("Please write an even number: ");
}
Console.WriteLine("Even number entered: {0}", n);
Console.ReadLine();
}
}
}

You might also like