IT05
Bạn có muốn phản ứng với tin nhắn này? Vui lòng đăng ký diễn đàn trong một vài cú nhấp chuột hoặc đăng nhập để tiếp tục.

IT05

Lớp CNTT05A - ĐH Đồng Tháp
 
Trang ChínhPortalGalleryLatest imagesTìm kiếmĐăng kýĐăng Nhập

 

 Tính giai thừa , tổ hợp, ...

Go down 
Tác giảThông điệp
nebulafire

nebulafire


Tổng số bài gửi : 25
Join date : 06/02/2010
Age : 37

Tính giai thừa , tổ hợp, ... Empty
Bài gửiTiêu đề: Tính giai thừa , tổ hợp, ...   Tính giai thừa , tổ hợp, ... I_icon_minitimeSun Feb 21, 2010 7:54 pm

Code:
#include<iostream.h>
#include<conio.h>
#include<STDLIB.H>
#define true 1
#define false 0
//////////////////////////////////////////
typedef int Datatype;
//////////////////////////////////////////
typedef struct TagNode
{
    Datatype data;
    struct TagNode *pNext;
}StackNode;
//////////////////////////////////////////
typedef StackNode *StackPtr;
//////////////////////////////////////////
void initStack(StackPtr &sp)
{
    sp=NULL;
}
//////////////////////////////////////////
int isEmpty(StackPtr &sp)
{
    if (sp==NULL)
   return true;
    else return false;
}
//////////////////////////////////////////
void push(StackPtr &sp,Datatype data)
{
    StackPtr p= new StackNode;
    if(p==NULL)
    {
        cout<<"Stack is Full !!"<<endl;
        getch();
        exit(1);
    }
    p->data=data;
    p->pNext=NULL;
    if(sp==NULL)
        sp=p;
    else
    {
        p->pNext=sp;
        sp=p;
    }
}
//////////////////////////////////////////
Datatype pop(StackPtr &sp)
{
    Datatype data;
    if(isEmpty(sp))
    {
        cout<<"Stack is Empty"<<endl;
        getch();
        exit(1);
    }
    StackPtr p;
    p=sp;
    data=sp->data;
    sp=p->pNext;
    delete p;
    return data;
}
///////////////////////////////////////////
void convert(int n,int b)
{
    Datatype temp;
    StackPtr sp;
    initStack(sp);
    while(n)
    {
        push(sp,n%b);
        n/=b;
    }
    while(!isEmpty(sp))
    {
        temp=pop(sp);
        if(temp==10) cout<<"A";
            else if(temp==11) cout<<"B";
                else if(temp==12) cout<<"C";
                    else if(temp==13) cout<<"D";
                        else if(temp==14) cout<<"E";
                            else if(temp==15) cout<<"F";
        else cout<<temp;
    }
    cout<<endl;
}
///////////////////////////////////////////
int giaiThua(int n)
{
    int  gt=1;
    int temp=1;
    StackPtr sp;
    initStack(sp);
    while(n)
    {
   push(sp,n);
   n=n-1;
    }
    while(isEmpty(sp)==false) // Neu Stack khong rong
    {
   gt=gt*pop(sp);
    }
    return gt;
}

int toHop(int n, int k){
   int ketqua=giaiThua(n)/(giaiThua(k)*giaiThua(n-k));
   return ketqua;
}
//////////////////////////////////////////
int main()
{
//    cout<<"doi tu he 10 sang he 2."<<endl;
//    cout<<"nhap so can doi n:=";
    int n;
//    cin>>n;
//    cout<<"ket Qua      :";
//    convert(n,2);
//    cout<<"doi tu he 10 sang 16"<<endl;
//    cout<<"nhap so can doi n:=";
//    cin>>n;
//    cout<<"ket Qua    ";
//    convert(n,16);
    cout<<"Tinh giai thua"<<endl;
    cout<<"nhap n:=";
    cin>>n;
    cout<<"ket qua: = "<<giaiThua(n)<<endl;
    getch();
    return 0;

}
Về Đầu Trang Go down
 
Tính giai thừa , tổ hợp, ...
Về Đầu Trang 
Trang 1 trong tổng số 1 trang
 Similar topics
-
» Tính trị biểu thức hậu tố
» Fabonacci Đệ quy - Không đệ quy - Đánh giá giải thuật
» NHẠC TRỮ TÌNH
» thơ truyện và đố vui
» Thần Bài 2 - God Of Gamblers 2 - Châu Tinh Trì

Permissions in this forum:Bạn không có quyền trả lời bài viết
IT05 :: SOURCE - CODE CHƯƠNG TRÌNH :: C/C++-
Chuyển đến