nguyenducdh10th
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.
Latest topics
» Transparency On Prices Required From All Health Care Sectors, Not Only Physicians, Letter States
Đồ Án Lập Trình C Của Nguyên Đức, Minh Tâm, Nhựt Trung Và Vũ Bằng EmptyWed Aug 03, 2011 4:48 pm by Khách viếng thăm

» Refog Kelogger wont work on machine with Net Protector Antivirus?
Đồ Án Lập Trình C Của Nguyên Đức, Minh Tâm, Nhựt Trung Và Vũ Bằng EmptyWed Aug 03, 2011 5:28 am by Khách viếng thăm

» play popular vegas slots
Đồ Án Lập Trình C Của Nguyên Đức, Minh Tâm, Nhựt Trung Và Vũ Bằng EmptyWed Aug 03, 2011 2:59 am by Khách viếng thăm

» fish oil heart health
Đồ Án Lập Trình C Của Nguyên Đức, Minh Tâm, Nhựt Trung Và Vũ Bằng EmptyTue Aug 02, 2011 11:48 pm by Khách viếng thăm

» hi i am using micromax 3g modem. i am clueless how to use it in Linux environment?
Đồ Án Lập Trình C Của Nguyên Đức, Minh Tâm, Nhựt Trung Và Vũ Bằng EmptyTue Aug 02, 2011 8:14 am by Khách viếng thăm

» гинекологические больницы отзывы
Đồ Án Lập Trình C Của Nguyên Đức, Minh Tâm, Nhựt Trung Và Vũ Bằng EmptyMon Aug 01, 2011 12:13 pm by Khách viếng thăm

» how i can made a backup of bootable USB.?
Đồ Án Lập Trình C Của Nguyên Đức, Minh Tâm, Nhựt Trung Và Vũ Bằng EmptyMon Aug 01, 2011 2:48 am by Khách viếng thăm

» To which directory or path do we need to install the modules in drupal through filezilla?
Đồ Án Lập Trình C Của Nguyên Đức, Minh Tâm, Nhựt Trung Và Vũ Bằng EmptySat Jul 30, 2011 9:29 pm by Khách viếng thăm

» Should I upgrade my hardware for my computer?
Đồ Án Lập Trình C Của Nguyên Đức, Minh Tâm, Nhựt Trung Và Vũ Bằng EmptySat Jul 30, 2011 1:27 pm by Khách viếng thăm

Thống Kê
Hiện có 1 người đang truy cập Diễn Đàn, gồm: 0 Thành viên, 0 Thành viên ẩn danh và 1 Khách viếng thăm

Không

[ View the whole list ]


Số người truy cập cùng lúc nhiều nhất là 15 người, vào ngày Tue Apr 30, 2024 3:29 pm

Đồ Án Lập Trình C Của Nguyên Đức, Minh Tâm, Nhựt Trung Và Vũ Bằng

Go down

Đồ Án Lập Trình C Của Nguyên Đức, Minh Tâm, Nhựt Trung Và Vũ Bằng Empty Đồ Án Lập Trình C Của Nguyên Đức, Minh Tâm, Nhựt Trung Và Vũ Bằng

Bài gửi  Admin Fri Nov 26, 2010 4:47 pm

Các Bạn nên chạy trước đi rồi hả đọc code nghe. Zậy dễ hiểu hơn.



#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<stdlib.h>
#include<alloc.h>
#include<string.h>
#include <math.h>
void modau2();
void modau1();
void modau3();
void bangmenu();
void thuasonguyento();
int luachon(),thoat;
void solonnhat();
/// CAC KHAI BAO SU DUNG O MENU THU 3
int **doi,**tongdiem,n,ketwa,tong;
/// KET THUC KHAI BAO MENU 3
/// CAC KHAI BAO SU DUNG CHO MENU THU 4
int**mta,**mtb,**mtkq;
void nhanmatran();
/// KET THUC CAC KHAI BAO DE SU DUNG CHO MENU 4
///CAC KHAI BAO CHO MENU THU 5
int nt(int);
int ht(int);
int bcnn(int,int);
int ucln(int,int);
void cacsohoanthien(int);
void cacsonguyento(int);
int a,b;
int bcnn_dayso();
int luachon5(),tiep5;
///KET THUC KHAI BAO DUNG CHO MENU THU 5
///CAC KHAI BAO SU DUNG CHO MENU THU 6
int menu6();
void hinhtamgiac();
void hinhtron();
void hinhvuong();
void hinhchunhat();
int chon6;
///KET THUC VIEC KHAI BAO CHO MENU 6
///CAC KHAI BAO SU DUNG CHO MENU THU 7 QUAN LY SINH VIEN
typedef struct {
char masv[9];
char hoten[50];
float diem;
}sv;
sv dssv[100];
int sosv,i,luachon7(),suluachon,tieptuc;
void nhapsv(int);
void xuatsv();
void timsv();
void xoasv();
///KET THUC VIEC KHAI BAO MENU THU 7 QUAN LY SINH VIEN
///CAC KHAI BAO SU DUNG CHO MENU THU 8
void thaotactrentiep();
///KET THUC VIEC KHAI BAO SU DUNG O MENU THU 8
/// CAC KHAI BAO SU DUNG CHO MENU THU 9
unsigned long giaithua(int);
unsigned long to_hop_chap(int,int);
void tohop();
void tengoicuanam();
void chuongtrinhtonghopmenu9();
int hscx2;
int hscx;
int hstd;
float x1,x2,x;
char chon,tiep;
float delta;
float ptbh(float x1,float x2,float x);
void tongcacsocua1so();
int chucnang;
void tambiet(); /*ham su dung khi thoat*/
void main()
{
modau2();
clrscr();
modau1();
clrscr();
modau3();
do
{bangmenu();
switch(luachon())
{case 1: {clrscr();
thuasonguyento();
break;
}
case 2: {textbackground(6);
solonnhat();
break;
}
case 3: {clrscr();
textbackground(13);
printf("==============================================================================");
gotoxy(11,2);
textcolor(7);
printf("CHUONG TRINH NHAP VAO KET QUA DIEM THI DAU CUA CAC DOI BONG");
gotoxy(36,3);
printf("VA");
gotoxy(14,4);
printf("IN RA TEN CAC DOI BONG CO THU TU TONG DIEM GIAM DAN\n");
printf("==============================================================================\n");
printf(" Nhap vao so doi bong cua giai: ");
scanf("%d",&n);
printf("==============================================================================\n");

/*cap phat bo nho dong de ghi ket qua cac tran dau*/
doi=(int **)calloc(n,sizeof(int*));
for(int i=0;i<n;i++)
doi[i]=(int*)calloc(n,sizeof(int));

/* nhap ket qua cho danh sach*/
printf("==============================================================================\n");
printf(" Moi ban nhap ket qua cho tung tran dau: \n Neu doi A thang doi B thi ghi Ket qua doi A vs doi B la: 3, Hoa 1, Thua 0\n");
printf("==============================================================================\n\n");
for(int hang=0;hang<n;hang++)
for(int cot=hang+1;cot<n;cot++)
do
{printf(" Ket qua doi %d vs doi %d la: ",hang+1,cot+1);
scanf("%d",&ketwa);
doi[hang][cot]=ketwa;
if(ketwa==3) doi[cot][hang]=0;
if(ketwa==0) doi[cot][hang]=3;
if(ketwa==1) doi[cot][hang]=1;
}
while(ketwa!=0&&ketwa!=1&&ketwa!=3);
/*in bang diem de kiem tra*/
printf("==============================================================================\n");
printf(" BANG DIEM CAC DOI\n\n");
printf(" ");
for(int sdoi=0;sdoi<n;sdoi++)
printf("DOI %d\t",sdoi+1);
printf("\n\n");

for(int hg=0;hg<n;hg++)
{printf("DOI %d ",hg+1);
{for(int co=0;co<n;co++)
if(hg==co) printf("X\t"); else printf("%d\t",doi[hg][co]);
printf("\n\n");
}
}
printf("==============================================================================\n\n");
/* TINH DIEM CHO CAC DOI LUU VAO MANG*/

/*cap phat bo nho cho mang chua tong diem n doi*/
tongdiem=(int**)malloc(n*sizeof(int*));
for(int sodoi=0;sodoi<n;sodoi++)
tongdiem[sodoi]=(int*)malloc(2*sizeof(int));

/* tinh tong diem cho tung doi*/
for(int h=0;h<n;h++)
{tong=0;
for(int c=0;c<n;c++)
{int kq;
if(h==c) kq=0; else kq=doi[h][c];
tong=tong+kq;
}
tongdiem[h][0]=h+1;
tongdiem[h][1]=tong;
}


/*sap xep cac doi co tong diem tu cao xuong thap*/
for(int vitri1=0;vitri1<n-1;vitri1++)
for(int vitri2=0;vitri2<n-1;vitri2++)
{int bientam1,bientam2;
if(tongdiem[vitri2][1]<=tongdiem[vitri2+1][1])
{
bientam1=tongdiem[vitri2][1];
tongdiem[vitri2][1]=tongdiem[vitri2+1][1];
tongdiem[vitri2+1][1]=bientam1;

bientam2=tongdiem[vitri2][0];
tongdiem[vitri2][0]=tongdiem[vitri2+1][0];
tongdiem[vitri2+1][0]=bientam2;
}
}
/*in doi bong co tong diem giam dan*/
textcolor(14);
printf("\n==============================================================================\n");
printf(" DANH SACH XEP HANG CAC DOI THEO TONG DIEM\n\n");
for(int k=0;k<n;k++)
printf("%d/ doi %d voi so diem la %d\n",k+1,tongdiem[k][0],tongdiem[k][1]);
printf("==============================================================================\n\n");
delay(10000);
break;
}
case 4: {clrscr();
textbackground(12);
nhanmatran();
break;
}
case 5: {clrscr();
textbackground(4);
do{switch(luachon5())
{case 1:{clrscr();
printf("================================================================================");
gotoxy(33,2);
printf("5.1 XAC DINH SO NGUYEN TO");
gotoxy(1,3);
printf("================================================================================");
printf("\n\n @CHU Y: Gia tri tra ve 1 la DUNG\n Gia tri tra ve 0 la SAI\n");
printf("\n Nhap so N vao de kiem tra no la so nguyen to khong:\t");
scanf("%d",&a);
printf("\n\n Gia tri tra ve la %d",nt(a));
delay(10000);
break;
}
case 2:{clrscr();
printf("================================================================================");
gotoxy(33,2);
printf("5.2 XAC DINH SO HOAN THIEN");
gotoxy(1,3);
printf("================================================================================");
printf("\n\n @CHU Y: Gia tri tra ve 1 la DUNG\n Gia tri tra ve 0 la SAI\n");

printf("Nhap so N vao de kiem tra phai so hoan thien hay khong:\t");
scanf("%d",&a);
printf("\n\n Gia tri tra ve la %d",ht(a));
delay(10000);
break;

}
case 3:{clrscr();
printf("================================================================================");
gotoxy(33,2);
printf("5.3 IN CAC SO NGUYEN TO NHO HON N");
gotoxy(1,3);
printf("================================================================================");
printf("\n\n Nhap N Vao: ");
scanf("%d",&a);
cacsonguyento(a);
delay(10000);
break;
}
case 4:{clrscr();
textcolor(5);
printf("================================================================================");
gotoxy(33,2);
printf("5.4 IN CAC SO HOAN THIEN NHO HON N");
gotoxy(1,3);
printf("================================================================================");
printf("\n\n Nhap vao so n de tui liet ke cac so hoan thien nho hon n:\t");
scanf("%d",&a);
cacsohoanthien(a);
delay(10000);
break;
}
case 5:{clrscr();
textcolor(10);
printf("================================================================================");
gotoxy(33,2);
printf("5.5 BCNN CUA 2 SO");
gotoxy(1,3);
printf("================================================================================");
printf("\n\n Nhap 2 so de tim BCNN\n A= ");
scanf("%d",&a);
printf("\n B= ");
scanf("%d",&b);
printf("BCNN cua %d & %d la: %d",a,b,bcnn(a,b));
delay(10000);
break;
}
case 6:{clrscr();
printf("================================================================================");
gotoxy(33,2);
printf("5.6 UCLN CUA 2 SO");
gotoxy(1,3);
printf("================================================================================");
printf("\n\n Nhap vao 2 so de tim UCLN\n A= ");
scanf("%d",&a);
printf("\n B= ");
scanf("%d",&b);
printf(" UCLN cua %d & %d la: %d",a,b,ucln(a,b));
delay(10000);
break;
}
case 7:{clrscr();
printf("================================================================================");
gotoxy(33,2);
printf("5.7 BCNN CUA N SO NGUYEN");
gotoxy(1,3);
printf("================================================================================");
printf("BCNN cua cac so vua nhap: %d",bcnn_dayso());
delay(10000);
break;
}
}
}
while(tiep5==8);
break;
}
case 6: {clrscr();
textbackground(7);
do{chon6 = menu6();
switch(chon6)
{case 1 :{ hinhtamgiac(); break;}
case 2 :{ hinhtron(); break;}
case 3 :{ hinhvuong(); break;}
case 4 :{ hinhchunhat(); break;}
}
}
while (chon6 != 0);
break;
}
case 7: {clrscr();
textbackground(2);
do {printf("================================================================================");
gotoxy(33,2);
printf("QUAN LY SINH VIEN");
gotoxy(1,3);
printf("================================================================================");
printf(" Moi ban nhap vao so sinh vien(1-100):\t");
scanf("%d",&sosv);
}
while(sosv<1||sosv>100);
nhapsv(sosv);
do{switch(luachon7())
{case 1: {xuatsv();break;}
case 2: {timsv(); break;}
case 3: {xoasv(); break;}
}
delay(10000);
clrscr();
printf("================================================================================");
gotoxy(33,2);
printf("QUAN LY SINH VIEN");
gotoxy(1,3);
printf("================================================================================");
printf(" Ban co muon tiep tuc thao tac tren danh sach sinh vien nay?\n\n\t\t\t1. Co\t\t2.Khong\n\n\t\t\tBan chon so: ");
scanf("%d",&tieptuc);
}
while(tieptuc==1);break;
}
case 8: {clrscr();
textbackground(5);
thaotactrentiep();
break;
}
case 9: {clrscr();
textbackground(10);
chuongtrinhtonghopmenu9();
break;
}
case 10:{clrscr();
textbackground(9);
gotoxy(4,13);
printf(" Ban da chon thoat!!! Mong duoc lam viec voi ban lan sau he.....");
delay(4000);
tambiet();
break;
}
}
}
while(thoat!=10);

}

void modau2()
{textcolor(10);
for(int i=60;i>=5;i--)
{
clrscr();
printf("\n--------------------------------------------------------------------------------");
gotoxy(i,3);
printf("NHOM FOUR STUPID");
printf("\n--------------------------------------------------------------------------------");
delay(50);
}
}


void modau3()
{
for(int k=3;k<=10;k++)
{ textcolor(k);
clrscr();
gotoxy(1,2);
printf("--------------------------------------------------------------------------------");
gotoxy(1,4);
printf("--------------------- ------------------------\n");
gotoxy(22,k);
printf("[<--------NHOM FOUR STUPID-------->]");
delay(200);
}
gotoxy(34,12);
printf("LE NGUYEN DUC");
delay(100);
gotoxy(35,13);
printf("LE MINH TAM");
delay(150);
gotoxy(35,14);
printf("CAO VU BANG");
delay(200);
gotoxy(33,15);
printf("DOAN NHUT TRUNG");
gotoxy(22,17);
printf("[<-------------------------------->]");
for(int demgiay=10;demgiay>0;demgiay--)
{gotoxy(26,19);
printf("Vui long cho %d giay ...",demgiay);
delay(1000);
}
}


void modau1()
{textcolor(10+128);
for(int j=5;j<=33;j++)
{
clrscr();
printf("\n--------------------------------------------------------------------------------");
gotoxy(j,3);
printf("NHOM FOUR STUPID");
printf("\n--------------------------------------------------------------------------------");
delay(100);
}
}


void bangmenu()
{clrscr();
textcolor(12);
for(int dong=1;dong<=5;dong++)
{clrscr();
gotoxy(1,dong);
printf("=============================< Menu >=============================\n\n");
gotoxy(35,dong+2);
printf(" 1/ THUA SO NGUYEN TO.");
gotoxy(33,dong+3);
printf(" 2/ TIM SO LON NHAT.");
gotoxy(31,dong+4);
printf(" 3/ SEAGAME 26 NE!.");
gotoxy(28,dong+5);
printf(" 4/ NHAN 2 MA TRAN.");
gotoxy(25,dong+6);
printf(" 5/ SO NGUYEN TO, HOAN THIEN, BCNN,UCLN...");
gotoxy(28,dong+7);
printf(" 6/ DIEN TICH CAC HINH.");
gotoxy(31,dong+8);
printf(" 7/ QUAN LY SINH VIEN.");
gotoxy(33,dong+9);
printf(" 8/ THAO TAC TREN FILE.");
gotoxy(35,dong+10);
printf(" 9/ TU CHON TONG HOP.");
gotoxy(63,dong+11);
printf(" 10/ THOAT");
gotoxy(25,dong+13);
printf("[<***************************>]");

}
}


int luachon()
{textcolor(10);
int phimchon;
do{printf("\n");
gotoxy(10,34);
printf(" Vui long chon so tuong ung voi chuc nang chuong trinh (1-10): ");
scanf("%d",&phimchon);
if(1<=phimchon&&phimchon<=10)
{clrscr();
gotoxy(15,12);
printf("Ok. Ban da chon dung! Chuong trinh se duoc thuc hien...");
delay(2000);
}
}
while(phimchon<1||phimchon>10);
thoat=phimchon;
return phimchon;
}


void thuasonguyento()
{textcolor(8);
int mu=0,dem=0,i,j;
int so;
clrscr();
printf("================================================================================");
gotoxy(25,2);
printf(" PHAN TICH 1 SO THANH THUA SO NGUYEN TO\n");
printf("================================================================================\n\n");
printf(" Nhap so vao de phan tich di ban: ");
scanf("%d",&so);
printf("\n %d = ",so);
for(i=2;i<=so;i++)
{for(j=2;j<i;j++)
if(i%j==0) dem++; else dem=dem;
if(dem=1&&so%i==0)
{mu=0;
while(so>=i&&so%i==0)
{so=so/i;
mu++;
}
printf("(%d^%d)",i,mu);
}
}
delay(10000);
}

void solonnhat()
{textcolor(7);
float n,max=0;
clrscr();
printf("================================================================================");
gotoxy(24,2);
printf("CHUONG TRINH NHAP SO THUC DEN KHI GAP 0");
gotoxy(21,3);
printf("THI DUA RA SO LON NHAT TRONG CAC SO VUA NHAP");
gotoxy(1,4);
printf("================================================================================\n\n");
for (int i=1;i<1000;i++)
{printf("N%d=",i);
scanf("%f",&n);
if (n==0) break; else
if (max>=n) max=max; else max=n;
}
gotoxy(28,15);
printf("%8.1f la so lon nhat",max);
delay(10000);
}
void tambiet()
{clrscr();
textcolor(12);
{for(int mau=0;mau<=15;mau++)
{clrscr();
textcolor(mau);
gotoxy(34,10);
printf(" LE NGUYEN DUC ");
gotoxy(35,11);
printf(" LE MINH TAM ");
gotoxy(35,12);
printf(" CAO VU BANG ");
gotoxy(33,13);
printf(" DOAN NHUT TRUNG ");
delay(200);
}
for(int hangtambiet=25;hangtambiet>=1;hangtambiet--)
{clrscr();
textcolor(10+128);
gotoxy(16,hangtambiet);
printf("CAM ON CAC BAN DA DEN VOI CHUONG TRINH CUA CHUNG TOI");
gotoxy(16,hangtambiet+1);
printf(" CHUC SUC KHOE NGHE!");
delay(200);
}
clrscr();
textcolor(10);
gotoxy(16,11);
printf("<<<<<<<<<<<<<<<<<<<< FOUR STUPID >>>>>>>>>>>>>>>>>>>>");
gotoxy(16,13);
printf(" CAM ON CAC BAN DA DEN VOI CHUONG TRINH CUA CHUNG TOI");
gotoxy(16,15);
printf(" CHUC SUC KHOE!");
gotoxy(16,17);
printf("<<<<<<<<<<<<<<<<<<<< FOUR STUPID >>>>>>>>>>>>>>>>>>>>");
delay(10000);
}
}
/// CAC HAM SU DUNG CHO MENU THU 7 QUAN LY SINH VIEN
void nhapsv(int sosv)
{clrscr();
textcolor(10);
printf("================================================================================");
gotoxy(33,2);
printf("QUAN LY SINH VIEN");
gotoxy(1,3);
printf("================================================================================");
for(i=0;i<sosv;i++)
{printf("--------------------------------------------------------------------------------\n");
printf("\n Nhap thong tin hoc sinh thu %d\n\n Ma SV:\t",i+1);
char masv_t[9];
fflush(stdin);
gets(masv_t);
strcpy(dssv[i].masv,masv_t);
printf("\n Ten SV:\t");
char hoten_t[30];
fflush(stdin);
gets(hoten_t);
strcpy(dssv[i].hoten,hoten_t);
printf("\n Diem:\t");
float diem;
scanf("%f",&diem);
dssv[i].diem=diem;
}
clrscr();
printf("================================================================================");
gotoxy(33,2);
printf("QUAN LY SINH VIEN");
gotoxy(1,3);
printf("================================================================================");
gotoxy(28,10);
textcolor(6);
printf("Viec nhap thong tin hoan tat!");
delay(5000);
}

void xuatsv()
{textcolor(10);
printf("\n\n Danh Sach Thong Tin Sinh Vien");
for(int i=0;i<sosv;i++)
{printf("\n--------------------------------------------------------------------------------\n");
printf("\n Ma sinh vien:\t%s\n Ho ten:\t%s\n Diem:\t%2.1f\n",dssv[i].masv,dssv[i].hoten,dssv[i].diem);
}
}

void timsv()
{textcolor(12);
int timduoc=0;
printf("\n Nhap ma sinh vien can tim:\t");
char masv_t[9];
fflush(stdin);
gets(masv_t);
for(i=0;i<sosv;i++)
{if(strcmp(dssv[i].masv,masv_t)==0)
{timduoc=1;
printf("--------------------------------------------------------------------------------\n");
printf(" Thong tin sinh vien:\n");
printf(" Ma sinh vien:\t%s\n Ho ten:\t%s\n Diem:\t%2.1f",dssv[i].masv,dssv[i].hoten,dssv[i].diem);

}
}
if(timduoc==0)
printf(" Khong tim thay!");
}

void xoasv()
{
printf("\n Nhap ma sinh vien can xoa:\t");
char masv_t[9];
fflush(stdin);
gets(masv_t);
int chiso,timduoc=0;
for(i=0;i<sosv;i++)
if(strcmp(dssv[i].masv,masv_t)==0)
{timduoc=1;
chiso=i;
}
if(timduoc==1)
{for(i=chiso;i<sosv-1;i++)
{dssv[i]=dssv[i+1];
n--;
printf("\n Danh sach sinh vien sau khi xoa ma sinh vien %s",dssv[chiso].masv);
for(i=0;i<sosv;i++)
printf("\n Ma sinh vien:\t%s\n Ho ten:\t%s\n Diem:\t%2.1f",dssv[i].masv,dssv[i].hoten,dssv[i].diem);
}
}
else
printf(" Khong tim thay ma sinh vien can xoa");
}

int luachon7()
{textcolor(13);
int chon;
do{clrscr();
printf("================================================================================");
gotoxy(33,2);
printf("QUAN LY SINH VIEN");
gotoxy(1,3);
printf("================================================================================");
gotoxy(8,5);
printf("<<<Moi ban chon phim tuong ung de thuc hien thao tac quan ly>>>");
gotoxy(27,7);
printf("1/ In Danh Sach sinh vien");
gotoxy(27,8);
printf("2/ Tim sinh vien");
gotoxy(27,9);
printf("3/ Xoa Sinh Vien");
gotoxy(27,12);
printf("Ban chon chuc nang so: ");
scanf("%d",&chon);
}
while(chon<1||chon>3);
return chon;
}

/// CAC HAM SU DUNG CHO MENU THU 4
void nhanmatran()
{
int donga,cotadongb,cotb,donga1,cotadb,cotb1,so,tong;
clrscr();
printf("================================================================================");
gotoxy(33,2);
printf("NHAN 2 MA TRAN");
gotoxy(1,3);
printf("================================================================================");
printf("\n\n\t\tNeu ban muon NHAN hai MA TRAN ??????");
printf("\n\t\tHay su dung chuong trinh duoi day!!!!!!!");
printf("\n--------------------------------------------------------------------------------");
printf("\n\t\tNhap thong tin cua hai ma tran ma ban muon tinh.");
printf("\n\n # So dong cua ma tran thu nhat la : ");
scanf("%d",&donga);
printf("\n # So cot cua ma tran thu nhat (cung la so dong ma tran thu hai) la : ");
scanf("%d",&cotadongb);
printf("\n # So cot cua ma tran thu hai la : ");
scanf("%d",&cotb);
//-------------------------------------------------------------------------
//Cap phat bo nho cho ma tran A
mta=(int**)malloc(donga*sizeof(int*));
for(int i=0;i<cotadongb;i++)
mta[i]=(int*)malloc(cotadongb*sizeof(int));
//--------------------------------------------------------------------------
//Cap phat bo nho cho ma tran B
mtb=(int**)malloc(cotadongb*sizeof(int*));
for(int dongmt=0;dongmt<cotb;dongmt++)
mtb[dongmt]=(int*)malloc(cotb*sizeof(int));
//--------------------------------------------------------------------------
//Cap phat bo nho cho ma tran ket qua
mtkq=(int**)malloc(donga*sizeof(int*));
for(int cotmt=0;cotmt<cotb;cotmt++)
mtkq[cotmt]=(int*)malloc(cotb*sizeof(int));
//------------------------------------------------------------------------
//Nhap vao cac phan tu cua ma tran A
for(donga1=0;donga1<donga;donga1++)
{
for(cotadb=0;cotadb<cotadongb;cotadb++)
{
printf("\n Nhap vao phan tu thu A[%d][%d]=",donga1+1,cotadb+1);
scanf("%d",&mta[donga1][cotadb]);
}}
//--------------------------------------------------------------------------
//Nhap vao cac phan tu cua ma tran B
for(cotadb=0;cotadb<cotadongb;cotadb++)
{
for(cotb1=0;cotb1<cotb;cotb1++)
{
printf("\n Nhap vao phan tu thu B[%d][%d]=",cotadb+1,cotb1+1);
scanf("%d",&mtb[cotadb][cotb1]);
}}
//------------------------------------------------------------------------
//Su dung dong lap de nhan hai ma tran
for(donga1=0;donga1<donga;donga1++)
{
for(cotb1=0;cotb1<cotb;cotb1++)
{
tong=0;
for(cotadb=0;cotadb<cotadongb;cotadb++)
{
so=(mta[donga1][cotadb])*(mtb[cotadb][cotb1]);
tong=tong+so;
}
mtkq[donga1][cotb1]=tong;
}
}
//--------------------------------------------------------------------------
//In ma tran ket qua
printf("\n Ket qua nhan la:\n\n");
for(donga1=0;donga1<donga;donga1++)
{
for(cotb1=0;cotb1<cotb;cotb1++)
{
printf("\t%d",mtkq[donga1][cotb1]);
printf(" ");
}
printf("\n\n");
}
delay(10000);
}
/// KET THUC CAC HAM SU DUNG CHO MENU THU 4
///CAC HAM SU DUNG CHO MENU THU 5
/*1---HAM XAC DINH SO NGUYEN TO*/
int nt(int a)
{int dem=0;
for(int i=2;i<a;i++)
if(a%i==0) dem++; else dem=dem;
if(dem==0) return 1; else return 0;
}
/* 2---HAM XAC DINH SO HOAN THIEN*/
int ht(int b)
{int b1=b;
int tonguoc=0;
for(int i=2;i<b;i++)
if(b%i==0) tonguoc=tonguoc+i; else tonguoc=tonguoc;
if(tonguoc==b1) return 1; else return 0;
}
/* 3---HAM CAC SO HOAN THIEN*/
void cacsohoanthien(int a)
{textcolor(13);
printf(" CAC SO HOAN THIEN NHO HON %d LA:\n",a);
for(int i=2;i<a;i++)
if(ht(i)==1) printf("%d\t",i);
}
/* 4---HAM TIM BCNN*/
int bcnn(int a,int b)
{int giatritrave,a1=a,b1=b;
if(a==b) giatritrave=a;
while(a!=b)
{if(a<b) a=a+a1;
if(a==b) {giatritrave=a; break;}
if(a>b) b=b+b1;
if(a==b) {giatritrave=b; break;}
}
return giatritrave;
}
/* 5---HAM TIM UCLN*/
int ucln(int a,int b)
{int giatritrave;
if(a==b) giatritrave=a;
while(a!=b)
{if(a<b) b=b-a;
if(a==b) {giatritrave=a; break;}
if(a>b) a=a-b;
if(a==b) {giatritrave=b; break;}
}
return giatritrave;
}
/* 6---HAM IN CAC SO NGUYEN TO <N*/
void cacsonguyento(int n)
{textcolor(9);
printf(" Cac so nguyen to nho hon %d LA:\n",n);
for(int i=2;i<n;i++)
if(nt(i)==1) printf("%d\t",i);
}
/* 7--- HAM BCNN CUA DAY*/
int bcnn_dayso()
{/* cap phat do nho dong cho day so*/
int *dayso;
printf(" Ban can tim BCNN cua bao nhieu so: ");
scanf("%d",&a);
dayso=(int*)malloc(a*sizeof(int));
/* nhap gia tri cua day so*/
textcolor(2);
for(int u=0;u<a;u++)
{
printf(" A%d=",u+1);
scanf("%d",&dayso[u]);
}
int boitam=bcnn(dayso[1],dayso[2]);
for(int i=3;i<a;i++)
boitam=bcnn(boitam,dayso[i]);
return boitam;
}
int luachon5()
{clrscr();
textcolor(10);
int giatritrave;
printf("================================================================================");
gotoxy(25,2);
printf("SO NGUYEN TO, HOAN THIEN, BCNN, UCLN...");
gotoxy(1,3);
printf("================================================================================");
do{gotoxy(27,5);
printf("1/ Xac Dinh So Nguyen To.");
gotoxy(27,6);
printf("2/ Xac Dinh So Hoan Thien.");
gotoxy(27,7);
printf("3/ Tim Cac So Nguyen To Nho Hon N.");
gotoxy(27,8);
printf("4/ Xac Cac So Hoan Thien Nho Hon N.");
gotoxy(27,9);
printf("5/ BCNN Cua 2 So.");
gotoxy(27,10);
printf("6/ UCLN Cua 2 So.");
gotoxy(27,11);
printf("7/ BCNN Cua N so.");
gotoxy(12,13);
printf("Moi ban chon chua nang muon thuc hien(1-7): ");
scanf("%d",&giatritrave);
printf("\n\n Su dung cac chuc nang khac sau khi thuc hien chuc nang nay?\n (an phim 8 neu su dung khong thi an phim 9): ");
scanf("%d",&tiep5);
}
while(giatritrave<1||giatritrave>7);
return giatritrave;
}
///KET THUC CAC HAM SU DUNG CHO MENU THU 5
///CAC HAM SU DUNG CHO MENU THU 6
int menu6()
{
int c;
clrscr();
printf("================================================================================");
gotoxy(33,2);
printf("DIEN TICH CAC HINH");
printf("\n================================================================================");
gotoxy(23,5);
printf("1.Hinh tam giac");
gotoxy(23,6);
printf("2.Hinh tron");
gotoxy(23,7);
printf("3.Hinh vuong");
gotoxy(23,8);
printf("4.Hinh chu nhat");
gotoxy(23,9);
printf("0. Thoat");
gotoxy(23,11);
printf("----------------\n\n");
printf("Chon muc : ");
do {
c = getch();
}
while (c>'4' || c<'0');
putc(c, stdout);
return c -'0';
}

void hinhtamgiac()
{
int a, b, c;
float p;
printf("\n\nNhap vao ba canh tam giac : ");
scanf("%d%d%d", &a, &b, &c);
printf("\nChu vi tam giac = %d", a+b+c);
p = (float)(a + b + c)/2;
printf("\nDien tich tam giac = %lf", sqrt(p*(p-a)*(p-b)*(p-c)));
getch();
}

void hinhtron()
{
int r;
printf("\n\nNhap vao ban kinh hinh tron : ");
scanf("%d", &r);
printf("\nChu vi hinh tron = %f", 2 * M_PI * r);
printf("\nDien tich hinh tron = %f", M_PI * r * r);
getch();
}

void hinhvuong()
{
int a;
printf("\n\nNhap vao canh hinh vuong : ");
scanf("%d", &a);
printf("\nChu vi hinh tron = %d", 4 * a);
printf("\nDien tich hinh vuong = %d", a * a);
getch();
}

void hinhchunhat()
{
int a, b;
printf("\n\nNhap vao cac canh hinh chu nhat : ");
scanf("%d%d", &a, &b);
printf("\nChu vi hinh chu nhat = %d", 2 * (a+b));
printf("\nDien tich hinh chu nhat = %d", b * a);
getch();
}
///KET THUC CAC HAM SU DUNG CHO MENU THU 6
///HAM SU DUNG CHO MENU THU 8
void thaotactrentiep()
{FILE *taptin;
int * mangsonguyen;
int so,dem=0;
taptin= fopen("D:\\DAY SO NGUYEN.txt","w+r"); /* mo tap tin de ghi ghi cac so nguyen nhap tu ban phim*/
textcolor(10);
while(so!=0)
{clrscr();
printf("================================================================================");
gotoxy(17,2);
cprintf(" NHAP DAY SO DEN KHI GAP 0");
gotoxy(17,3);
printf(" DUNG CONG VIEC NHAP GHI GIA TRI VAO FILE");
gotoxy(17,4);
printf("DOC TU FILE CAC GIA TRI VUA NHAP ROI SAP XEP DAY TANG");
gotoxy(17,5);
printf(" GHI DAY DUOC SAP XEP VAO FILE");
gotoxy(1,6);
printf("================================================================================");
printf("\n\n Moi ban nhap so thu %d vao(viec nhap ket thuc khi ban nhap vao so 0): ",dem+1);
scanf("%d",&so);
if(so==0) break;
fprintf(taptin,"%d\n",so);
dem=dem+1;
}
gotoxy(24,10);
printf(" Viec nhap da xong!\n\n");

///----------------------------------------------------------------------------doc tu file cac so nguyen luu vao mangsonguyen
mangsonguyen=(int*)calloc(dem,sizeof(int)); /*cap phat bo nho cho mang n so vua nhap*/
///doc gia tri tu file vao mangsonguyen
fseek(taptin,0,0);/* dua con tro ve dau tap tin*/
int vitri=0;
while (feof(taptin)==0) /*kiem tra cuoi tap tin nguyen.txt hay chua?*/
{
fscanf(taptin,"%d",&mangsonguyen[vitri]);
vitri++;
}

fprintf(taptin,"DAY DUOC SAP XEP TANG DAN\n\n");
///----------------------------------------------------------------------------in cac so vua doc vao de kiem tra doc tu file dung khong
gotoxy(26,13);
printf(" Cac so vua nhap");
gotoxy(1,14);
printf("--------------------------------------------------------------------------------\n\n");
for(int q=0;q<dem;q++)
printf("%d\t",mangsonguyen[q]);
printf("\n--------------------------------------------------------------------------------");
///----------------------------------------------------------------------------sap xep cac so nguyen theo thu tu tang dan
for(int sothu1=0;sothu1<dem-1;sothu1++)
for(int sothu2=0;sothu2<dem-1;sothu2++)
{int bientam;
if(mangsonguyen[sothu2]>mangsonguyen[sothu2+1])
{bientam=mangsonguyen[sothu2];
mangsonguyen[sothu2]=mangsonguyen[sothu2+1];
mangsonguyen[sothu2+1]=bientam;
}
}
///----------------------------------------------------------------------------ghi day so vua sap xep tang dan vao cuoi tiep
fseek(taptin,2,2);/*dua ve cuoi tap tin*/
for(int i=0;i<dem;i++) /* ghi cac so da duoc sap xep vao cuoi tap tin*/
fprintf(taptin,"%d, ",mangsonguyen[i]);
fclose(taptin); /*dong tap tin*/
printf("\n\n\n Moi ban mo file D:\\Day so nguyen.txt de xem ket qua");
delay(10000);
}
///KET THUC HAM SU DUNG O MENU THU 8
/// CAC HAM SU DUNG CHO MENU THU 9
/* ham su dung tinh to hop*/
unsigned long giaithua(int n)
{unsigned long ketqua = 1;
int i;
for (i=2; i<=n; i++)
ketqua *= i;
return ketqua;
}

unsigned long to_hop_chap(int k, int n)
{return giaithua(n) / (giaithua(k) * giaithua(n-k));
}
void tohop()
{char chon;
int n, k;
do{clrscr();
do{clrscr();
printf("===============================================================================");
gotoxy(23,2);
printf("CHUONG TRINH TINH TO HOP CHAP K CUA N");
printf("\n===============================================================================");
printf("\n\nNhap vao gia tri N:\t");
scanf("%d", &n);
printf("\nNhap vao gia tri K:\t");
scanf("%d",&k);
}
while (n<k);
printf("\n\nTo hop chap %d cua %d = %lu", k, n, to_hop_chap(k, n));
printf("\n\n\nBan co muon tinh to hop tiep khong?(Y/N):\t");scanf("%s",&chon);
}
while(chon=='y'||chon=='Y');
}
/*ket thuc ham tinh to hop*/
/* Ham xac dinh ten goi cua nam*/
void tengoicuanam()
{int nam,dung;
char can[][10]={"Giap", "At", "Binh", "Dinh", "Mau", "Ky","Canh", "Tan", "Nham", "Quy"};
char chi[][12]={"Ty", "Suu", "Dan", "Meo", "Thin", "Ty","Ngo", "Mao", "Than", "Dau", "Tuat", "Hoi"};
do{ clrscr();
printf("================================================================================");
gotoxy(34,2);
printf("XAC DINH TEN NAM");
printf("\n================================================================================\n");

printf(" \n\n\nMoi ban nhap nam vao: ");
scanf("%d",&nam);
printf(" \n\nNam %d la nam %s %s.",nam,can[(nam+6)%10],chi[(nam+8)%12]);
printf("\n\nBan co muon su dung tiep khong?\n\n An 1 neu CO 0 neu KHONG ");
scanf("%d",&dung);
}
while(dung==1);
clrscr();
for(int demgiay=5;demgiay<=1;demgiay--)
{gotoxy(25,10);
printf("Chuong trinh se thoat sau %d giay...",demgiay);
delay(1000);
}
}
/* Ket thuc ham xac dinh ten goi cua nam*/

/* Ham giai phuong trinh bac 2*/
float ptbh(float x1, float x2, float x)
{do
{clrscr();
printf("================================================================================");
gotoxy(23,2);
printf("CHUONG TRINH GIAI PHUONG TRINH BAC HAI");
printf("\n================================================================================");
printf("\n\nNhap vao he so chua x binh phuong:\t");
scanf("%d",&hscx2);
printf("\nNhap vao he so chua x:\t"); scanf("%d",&hscx);
printf("\nNhap vao he so tu do:\t"); scanf("%d",&hstd);
if(hscx>0&&hstd>0)
{printf("\n\nCo phai ban muon giai phuong trinh %dX*X+%dX+%d=0 phai khong?(Y/N):",hscx2,hscx,hstd);
scanf("%s",&chon);
}
if(hscx<0&&hstd<0)
{printf("\n\nCo phai ban muon giai phuong trinh %dX*X%dX%d=0 phai khong?(Y/N):",hscx2,hscx,hstd);
scanf("%s",&chon);
}
if(hscx>0&&hstd<0)
{printf("\n\nCo phai ban muon giai phuong trinh %dX*X+%dX%d=0 phai khong?(Y/N):",hscx2,hscx,hstd);
scanf("%s",&chon);
}
if(hscx<0&&hstd>0)
{printf("\n\nCo phai ban muon giai phuong trinh %dX*X%dX+%d=0 phai khong?(Y/N):",hscx2,hscx,hstd);
scanf("%s",&chon);
}
}
while(chon=='N'||chon=='n');
delta=(hscx*hscx)-(4*hscx2*hstd);
if(delta==0)
{x=((-hscx)/(2*hscx2));
printf("\nPhuong trinh co nghiem kep %2.3f",x);
}
if(delta<0)
printf("\nPhuong trinh vo nghiem");
else
{x1=(((-hscx)-sqrt(delta))/(2*hscx2));
x2=(((-hscx)+sqrt(delta))/(2*hscx2));
printf("\nPhuong trinh co 2 nghiem la:\t%2.3f va %2.3f",x1,x2);
}
return x1,x2,x;
}
/* Ket thuc ham giai phuong trinh bac 2*/

/* Ham tinh tong cac so cua 1 so*/
void tongcacsocua1so()
{long int somoidoi1;
float sotinhtong,somoidoi2,sotam2,tong=0;
clrscr();
printf(" Nhap vao so can tinh tong : " );
scanf("%f",&sotinhtong);
//su dung dong lap do{...}while de tinh tong
do{// tinh somoidoi1 o dang so nguyen
somoidoi1=sotinhtong/10;
// tinh somoidoi2 o dang phan so
somoidoi2=sotinhtong/10;
// trich ra so cuoi cung cua so vua nhap
sotam2=somoidoi2-somoidoi1;
tong=tong+(sotam2*10);
// gan sotinhtong=somoidoi de tinh tiep tuc cho den khi cong duoc het cac chu so
sotinhtong=somoidoi1;
}
while(sotinhtong!=0);
printf("\n Tong cac chu so la: %5.0f",tong);
getch();
}

/*ham thuc hien cac chuong trinh o menu thu 9*/
void chuongtrinhtonghopmenu9()
{
do{clrscr();
do{clrscr();
gotoxy(1,4);
printf("-------------------------------------------------------------------------------");
gotoxy(28,5);
printf("1/ Tinh To Hop.");
gotoxy(28,6);
printf("2/ Xac Dinh Ten Cua Nam.");
gotoxy(28,7);
printf("3/ Tong Cac Chu So Cua 1 So.");
gotoxy(28,8);
printf("4/ Giai Phuong Trinh Bac 2.");
gotoxy(28,9);
printf("5/ Thoat.");
gotoxy(1,10);
printf("-------------------------------------------------------------------------------");
gotoxy(15,12);
printf("Moi ban nhap so tuong ung voi chuc nang cua chuong trinh: ");
scanf("%d",&chucnang);
}
while(chucnang<1||chucnang>5);
switch(chucnang)
{case 1:{clrscr();
tohop();
break;
}
case 2:{clrscr();
tengoicuanam();
break;
}
case 3:{clrscr();
tongcacsocua1so();
break;
}
case 4:{clrscr();
textcolor(14);
do {clrscr();
ptbh(x1,x2,x);
printf("\n\n\nBan co muon giai phuong trinh tiep khong?(Y/N):\t");
scanf("%s",&tiep);
}
while(tiep=='Y'||tiep=='y');
break;
}
}
}
while(chucnang!=5);
}
/*ket thuc ham thuc hien cac chuong trinh o menu thu 9*/
/// KET THUC CAC HAM O MENU THU 9
Admin
Admin
Admin

Tổng số bài gửi : 38
Join date : 20/11/2010

https://nguyenducdh10th.forumvi.com

Về Đầu Trang Go down

Về Đầu Trang


 
Permissions in this forum:
Bạn không có quyền trả lời bài viết