Code C#: Nhập vào số nguyên N có 3 chữ số. Tính tổng 3 chữ số đó

Người đăng: chisenhungsuutam on Thứ Tư, 13 tháng 3, 2013


//Viết chương trình Console Application, nhập vào số nguyên n có 3 chữ số. Hãy tính tổng 3 chữ số đó.
namespaceBaiThucHanh1{
    class Program{
        static void Main(){
            int n;
            Console.Write("Nhap vao so nguyen n: ");
            n = int.Parse(Console.ReadLine());
            ints = 0;
            intdu;
            while(n != 0) {
                du = n % 10;
                s = s + du;
                n = n / 10;
            }
            Console.WriteLine("Tong cac chu so la: {0}",s.ToString());
            Console.ReadLine();
        }
    }
}

More about

Code C#: Ví dụ vòng lặp FOR

Người đăng: chisenhungsuutam on Thứ Hai, 11 tháng 3, 2013


//Ví dụ 1: Viết chương trình C# sử dụng cấu trúc FOR in ra màn hình kết quả như sau:
*******
******
*****
****
***
**
*
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FOR_LOOP_1{
class Program{
static void Main(string[] args){
     int i,j;
     for(i=0;i<=6;i++){
           for(j=1;j<=7-i;j++) Console.Write("*");
           Console.Write("\n"); 
     }
Console.ReadLine(); 
   }
 }
}

//Ví dụ 2: VCT C# sử dụng cấu trúc FOR in ra màn hình kết quả như sau:
1******
12*****
123****
1234***
12345**
123456*
1234567

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

namespace FOR_LOOP_2{
class Program{
static void Main(string[] args){
int i,j,k;

   for (i = 1; i <= 7; i++) {
       for (j = 1; j <= i; ++j)
             Console.Write(j);
       for (k = 7 - i; k >= 1; k--)
             Console.Write("*");
   Console.Write("\n");
}
Console.ReadLine();
  }
 }
}
More about

Code C#: Ví dụ cấu trúc IF...ELSE

Người đăng: chisenhungsuutam


//Viết chương trình cho phép nhập 3 số nguyên từ bàn phím. In ra số lớn nhất.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Max_3_so{
class Program{
static void Main(string[] args){

int a, b, c;

Console.Write("Nhap gia tri a:");
a = int.Parse(Console.ReadLine());
Console.Write("Nhap gia tri b:");
b = int.Parse(Console.ReadLine());
Console.Write("Nhap gia tri c:");
c= int.Parse(Console.ReadLine());

if (a > b)
   if (a > c) Console.Write("Gia tri lon nhat la:{0}.",a);
   else Console.Write("Gia tri lon nhat la:{0}.", z);
else if (b > c) Console.Write("Gia tri lon nhat la:{0}.",b);
   else Console.Write("Gia tri lon nhat la:{0}.",c);

Console.ReadLine(); 
    }
  }
}


More about

Code C#: Ví dụ về LỚP và ĐỐI TƯỢNG

Người đăng: chisenhungsuutam on Thứ Tư, 6 tháng 3, 2013


//Ví dụ 1: Tạo lớp SINHVIEN gồm
- Các thuộc tính: maSV, tenSV, lop, diemtoan, diemly, diemhoa, diemtb;
Yêu cầu:
1. Xây dựng các phương thức khởi dựng  của lớp SINHVIEN với các tham số khác nhau
2. Xây dựng các phương thức của lớp SINHVIEN: nhapDL(), TinhdiemTB(), inDL();
3. Khởi tạo 3 đối tượng thuộc lớp SINHVIEN theo các cách khác nhau. Nhập dữ liệu và in kết quả ra màn hình
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Class_basic
{
    public class SINHVIEN {
        string maSV;
        string tenSV;
        string lop;
        float dt, dl, dh,dtb;
        //Khai bao cac phuong thuc khoi dung cua lop SINHVIEN
        public SINHVIEN() {
            maSV = "";
            tenSV = "";
            lop = "";
            dt = dl = dh = 0;
        }
        public SINHVIEN(stringmasv, string tensv, stringlop, float dt, floatdl, float dh) {
            this.maSV = masv;
            this.tenSV = tensv;
            this.lop = lop;
            this.dt = dt;
            this.dl = dl;
            this.dh = dh;
        }
        public SINHVIEN(SINHVIEN_sv) {
            this.maSV = _sv.maSV;
            this.tenSV = _sv.tenSV;
            this.lop = _sv.lop;
            this.dt = _sv.dt;
            this.dl = _sv.dl;
            this.dh = _sv.dh;
        }
        //Khai bao cac property cho cac bien thanh vien cua lop SINHVIEN
        public string MASV {
            get { return maSV; }
            set { maSV = value; }
        }
        public string TENSV
        {
            get { return tenSV ; }
            set { tenSV = value; }
        }
        public float DIEMTOAN
        {
            get { return dt; }
            set { dt = value; }
        }
        public float DIEMLY
        {
            get { return dl; }
            set { dl = value; }
        }
        public float DIEMHOA
        {
            get { return dh; }
            set { dh = value; }
        }
        //Khai bao cac phuong thuc cua lop SINHVIEN
        public void nhapDL() {
            Console.Write("Nhap ma sinh vien: ");    maSV = Console.ReadLine();
            Console.Write("Nhap ten sinh vien: ");   tenSV = Console.ReadLine();
            Console.Write("Nhap lop hoc: ");         lop = Console.ReadLine();
            Console.Write("Nhap diem Toan: ");      dt = float.Parse(Console.ReadLine());
            Console.Write("Nhap diem Ly: ");        dl = float.Parse(Console.ReadLine());
            Console.Write("Nhap diem Hoa: ");       dh = float.Parse(Console.ReadLine());
        }
        public floatTinhdiemTB() {
            float kq;
            kq = (dt + dl + dh) / 3;
            return kq;
        }
        public void inDL() {           
            Console.WriteLine("Ma sinh vien: {0}",maSV);
            Console.WriteLine("Ten sinh vien: {0}", tenSV);
            Console.WriteLine("Lop hoc: {0}", lop);
            Console.WriteLine("Diem toan: {0}", dt);
            Console.WriteLine("Diem ly: {0}", dl);
            Console.WriteLine("Diem hoa: {0}", dh);
            Console.WriteLine("Diem trung binh: {0}", TinhdiemTB().ToString());
            Console.WriteLine("----------------------------------------------");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            //Tao doi tuong sv1 voi ham khoi dung co tham so;
            SINHVIEN sv1 = newSINHVIEN("SV01","Nguyen Minh Ngoc ","CDN LTMT K1",6,7,6);
            sv1.inDL();
            //Tao doi tuong sv2 voi ham khoi dung khong co tham so;
            SINHVIEN sv2 = newSINHVIEN();
            sv2.nhapDL();
            sv2.inDL();
            //Tao doi tuong sv3 voi ham khoi dung sao chep
            SINHVIEN sv3 = newSINHVIEN(sv1);
            sv3.MASV = "SV03";
            sv3.TENSV = "Nguyen Giang Linh";
            sv3.inDL();
            Console.ReadLine();
        }
    }
}
More about

Code C-C++: Viết chương trình nhập vào 3 số. In ra màn hình số lớn nhất, nhỏ nhất.

Người đăng: chisenhungsuutam


//Đề bài: Viết chương trình nhập vào 3 số. In ra màn hình số lớn nhất, nhỏ nhất.
#include<iostream.h>
#include<conio.h>
void main(){ 
      float a,b,c; // Khai báo 3 biến a, b,c
      cout<<"\n Nhap gia tri a:"; cin>>a; 
      cout<<"\n Nhap gia tri b:"; cin>>b; 
      cout<<"\n Nhap gia tri c:"; cin>>c; 

      float max=a;  //Gán giá trị lớn nhất bằng a
      if(max<b) max=b; 
      if(max<c) max=c; 

      float min=a;  //Gán giá trị nhỏ nhất bằng a
      if(min>b) min=b; 
      if(min>c) min=c;
      cout<<"\n So lon nhat la: "<<max<<"\n So nho nhat la: "<<min; 
      getch();
}
More about

Code Pascal: Nhập một xâu, kiểm tra xâu có đối xứng không

Người đăng: chisenhungsuutam


Yêu cầu: Nhập một xâu, kiểm tra xâu có đối xứng không 
procedure test_xaudoixung;
var  s: String;
i,j,count:integer;
begin
     write('Nhap vao xau s=');
     readln(s);
     i:=1; j:=length(s);
     count:=0;
     while( j >= i) do
     begin
          if s[i] <> s[j] then
          begin
             count:=1;
             break;
          end
          else
          begin
               inc(i);
               dec(j)
          end;
     end;
     if count=0 then writeln('Xau doi xung')
     else
         writeln('Xau ko doi xung');
end;



More about

Code Pascal: Nhập vào một số, kiểm tra số có đối xứng hay không

Người đăng: chisenhungsuutam


procedure bai1;
var
n,n1,temp:integer;
BEGIN
    repeat
          clrscr;
          write('Nhap vao so n=');
          readln(n);
          if((n>-32000) and (n<32000) )then break;
    until (1=1);
    n1:=0;
    temp:=n;
    while temp>0 do
    begin
         n1:=n1*10 + temp mod 10;
         temp:= temp div 10;
    end;
    if n1=n then writeln('Doi xung')
    else
        writeln('Khong doi xung');
END;

More about