| | Mot so bai tham khao!! | |
| | Tác giả | Thông điệp |
---|
Admin Admin
Tổng số bài gửi : 166 Age : 40 Registration date : 01/06/2007
| Tiêu đề: Mot so bai tham khao!! Mon Jul 23, 2007 11:31 pm | |
| Co mot so de thi tham khao,minh lay tu trang www.diendantinhoc.com (da chinh sua de chay duoc rui), moi nguoi tham khao nhe!!1. Xây dựng câu trúc Sinhvien o Hoten – có 30 ký tự o Tuoi - kiểu int 2. Định nghĩa kiểu dữ liệu mới Svien dựa trên cấu trúc sinh viên (sử dụng từ khoá typedef) 3. Xây dựng chương trình o Tạo menu gồm: 1. Nhập dữ liệu 2. In thông tin 3. Sắp xếp theo tên 4. Đảo vị trí 5. Kết thúc 4. Khi chọn vào mục 1 -> Nhập dữ liệu cho 5 sinh viên, viết hàm nhập riêng và sử dụng con trỏ làm tham số cho việc truyền cấu trúc. 5. Chọn mục 2 -> in danh sách sinh viên đã nhập: viết hàm riêng, dùng tham số là con trỏ 6. Chọn mục 3: Sắp xếp theo tên: sắp xếp các sinh viên theo thứ tự tăng dần A-> Z o Viết hàm riêng, dùng con trỏ o Có thể viết thêm 1 hàm để đảo vị trí 2 sinh viên 7. Chọn mục 4: Đảo vị trí các sinh viên từ sau ra trước o 1-> n o 2-> n-1 o … 8. Chọn mục 5: Kết thúc chương trình | |
| | | Admin Admin
Tổng số bài gửi : 166 Age : 40 Registration date : 01/06/2007
| Tiêu đề: Re: Mot so bai tham khao!! Mon Jul 23, 2007 11:33 pm | |
| Con day code chay: #include<stdio.h> #include<conio.h> #include<string.h> #include<stdlib.h>
typedef struct sinhvien { char hoten[30]; int tuoi; float diem; }sv;
//==============================
int menu() { int phim;
printf("\nTAO MENU:"); printf("\n\t 1.Nhap du lieu."); printf("\n\t 2.In thong tin."); printf("\n\t 3.Sap xep theo ten."); printf("\n\t 4.Dao vi tri."); printf("\n\t 5.In ra file."); printf("\n\t 6.Thoat."); printf("\nCHON 1 CHUC NANG TREN:--->>"); scanf("%d",&phim); printf("\n--------------------------"); return phim; }
//=================================
//NHAP THONG TIN VE SINH VIEN void nhap(sv *sv1,int n) { int i=0; float tam; for(i=0;i<n;i++) { printf("\nNhap thong tin sinh vien:"); printf("\n\tHo ten:"); fflush(stdin); gets(sv1[i].hoten);
printf("\n\tTuoi:"); scanf("%d",&(sv1+i)->tuoi);
printf("\n\tDiem:"); scanf("%f",&tam); sv1[i].diem= tam; } }
//=================================
//IN THONG TIN SV RA MAN` HINH` void in(sv *sv1,int n) { int i=0; for (i=0;i<n;i++) { printf("\nIn ra thong tin ve sinh vien:"); printf("\n\t Ho ten :%s",(sv1 +i)->hoten); printf("\n\t Tuoi :%d",(sv1 +i)->tuoi); printf("\n\t Diem :%.2f",(sv1 +i)->diem); } }
//=================================
void sapxep(sv *sv1,int n) { int i,j,c; sv tg; for(i=0;i<n;i++) for(j=i+1;j<n;j++) { c=strcmp((sv1+i)->hoten,(sv1+j)->hoten); //DUng` con tro
// Co the dung` mang? nhu sau : c=strcmp(nv1[i].hoten,nv1[j].hoten); if(c>0) { tg=sv1[i]; sv1[i]=sv1[j]; sv1[j]=tg; } } }
//================================= void daovitri(sv *sv1,int n) { int i,j; sv tam; for(i=0,j=n-1;i<=n/2;i++,j--) { tam=sv1[i]; sv1[i]=sv1[j]; sv1[j]=tam; } }
//================================= //LUU THONG TIN VE SV RA FILE void savefile(char *tenfile,sv *sv1,int n) { FILE *fp; int i; fp = fopen(tenfile , "w"); if (fp==NULL) { printf("\nKhong mo duoc Flie"); } else { for(i=0;i<n;i++) { fprintf(fp, "\n Sinh vien thu' %d:", i+1); fprintf(fp, "\n\tHo ten: %s \n\tTuoi: %d \n\tDiem: %.2f", (sv1+i)->hoten, (sv1+i)->tuoi, (sv1+i)->diem); }
fclose(fp); }
}
//==========================================================================
//HAM` CHINH' CUA CHUONG TRINH` void main() { sv sv1[3];
do {
int phim; phim= menu();
switch(phim) { case 1: nhap(sv1,3); break; case 2: in(sv1,3); break; case 3: sapxep(sv1,3); printf("\nBan da sap xep ten theo thu tu bang chu cai."); break;
case 4: daovitri(sv1,3); printf("\nMang da dao"); break;
case 5: savefile("DATA.TXT", sv1, 3); printf("\nBan da in ra file thanh cong:"); break;
case 6:exit(1); break;
default: printf("\nChon sai-Chon lai."); break; } getch(); } while(1); } | |
| | | Admin Admin
Tổng số bài gửi : 166 Age : 40 Registration date : 01/06/2007
| Tiêu đề: Re: Mot so bai tham khao!! Mon Jul 23, 2007 11:36 pm | |
| Con day la mot so de thi ly thuyet(chay tho):
45. main() { int x=5; for(;x!=0;x--) { printf("x=%d\n", x--); } }
A. 5, 3, 1
B. 4, 3, 2, 1, 0
C. 5, 4, 3, 2,1
D. none of the above<Vong` lap se chay vo han> ________________________________________
46. main() { int x=5; clrscr(); for(;x<= 0;x--) { printf("x=%d ", x--); } }
A. 5, 3, 1, -1, 3
B. 5, 2, 1
C. 5, 3, 1
D. None of the above. ________________________________________
47. main() { { unsigned int bit=256; printf("%d", bit); } { unsigned int bit=512; printf("%d", bit); } }
A. 256, 512
B. 512, 512
C. 256, 256
________________________________________
48.main() { int i; clrscr(); for(i=0;i<5;i++) { printf("%d\n", 1L << i); } }
A. 1, 2, 4, 8, 16
B. 0, 1, 2, 4, 8
C. 0, 1, 2, 3, 4
D. 5, 4, 3, 2, 1 ________________________________________
49. main() { signed int bit=512, i=5; for(;i;i--) { printf("%d\n", bit = (bit >> (i - (i -1)))); } }
A. 128, 64, 32, 16, 8
B. 256, 128, 64, 32, 16
C. 512, 256, 128, 64, 32
D. 64, 32, 16, 8, 4 ________________________________________ 50. main() { signed int bit=512, i=5; for(;i;i--) { printf("%d\n", bit >> (i - (i -1))); } }
A. 512, 512, 512, 512, 512
B. 256, 256, 0, 0, 0
C. 512, 256, 0, 0, 0
D. 256, 256, 256, 256, 256 ________________________________________ 51 . main() { if (!(1&&0)) { printf("OK I am done."); } else { printf("OK I am gone."); } }
A. none of the above
B. compile error
C. OK I am gone
D. OK I am done ________________________________________
52 . main() { if ((1||0) && (0||1)) { printf("OK I am done."); } else { printf("OK I am gone."); } }
A. none of the above
B. compile error
C. OK I am gone
D. OK I am done ________________________________________
53. main() { signed int bit=512, mBit; { mBit = ~bit; bit = bit & ~bit ; printf("%d %d", bit, mBit); } }
A. 0, -513 B. 512, 0
C. 0, 513
D. 0, 0 ________________________________________
54 . What would be the output of the following program? main() { int i=4; switch(i) { default: printf("\n A mouse is an elephant built by the Japanese"); case 1: printf(" Breeding rabbits is a hair raising experience"); break; case 2: printf("\n Friction is a drag"); break; case 3: printf("\n If practice make perfect, then nobody's perfect"); } }
A. A mouse is an elephant built by the Japanese
B. Breeding rabbits is a hare raising experience
C. A mouse is an elephant built by the Japanese Breeding rabbits is a hare raising experience
D. None of the above ________________________________________
55 . What is the output of the following program? #define SQR(x) (x*x) main() { int a,b=3; a= SQR(b+2); printf("%d",a); }
A. 25
B. 11
C. Error
D. Garbage Value ________________________________________
56 . In which line of the following, an error would be reported? 1. #define CIRCUM® (3.14*R*R); 2. main() 3. { 4. float r=1.0,c; 5. c= CIRCUM®; 6. printf("\n%f",c); 7. if(CIRCUM®)==6.28) 8. printf("\nGobbledygook"); 9. }
A. Line 1
B. Line 5
C. Line 6
D. Line 7 ________________________________________
57 . We should not read after a write to a file without an intervening call to fflush(), fseek() or rewind()
A. True
B. False ________________________________________
14 . If the program (myprog) is run from the command line as myprog 1 2 3 , What would be the output? main(int argc, char *argv[]) { int i; for(i=0;i<argc;i++) printf("%s",argv[i]); }
A. 1 2 3
B. C:\MYPROG.EXE123//Moi may’ cho mot ket qua khac nhau.
C. MYP
D. None of the above ________________________________________
58 . If the following program (myprog) is run from the command line as myprog 1 2 3, What would be the output? main(int argc, char *argv[]) { int i,j=0; for(i=0;i<argc;i++) j=j+ atoi(argv[i]); printf("%d",j); }
A. 1 2 3
B. 6
C. error
D. "123" ________________________________________
59 . If the following program (myprog) is run from the command line as myprog monday tuesday wednesday thursday What would be the output? main(int argc, char *argv[]) { while(--argc >0) printf("%s",*++argv); }
A. myprog monday tuesday wednesday thursday
B. monday tuesday wednesday thursday
C. mondaytuesdaywednesdaythursday
D. myprog tuesday thursday ________________________________________
60 . What would be the output of the following program? main() { int y=128; const int x=y; printf("%d",x); }
A. 128
B. Garbage value
C. Error
D. 0 ________________________________________
61 . Following declarations are same: const char *s; char const *s;
A. True
B. False ________________________________________
62 . What would be the output of the following program? main() { char near * near *ptr1; char near * far *ptr2; char near * huge *ptr3; printf("%d %d %d",sizeof(ptr1),sizeof(ptr2),sizeof(ptr3)); }
A. 1 1 1
B. 1 2 4
C. 2 4 4
D. 4 4 4
E. Error ________________________________________
63 . Following declarations are different from one another const char *const s; char const *const s;
A. True
B. False ________________________________________
64 . If the following program (myprog) is run from the command line as myprog friday tuesday sunday, What would be the output? main(int argc, char*argv[]) { printf("%c",**++argv); }
A. m
B. f
C. myprog
D. Friday E.Runtime error ________________________________________
65 . If the following program (myprog) is run from the command line as myprog friday tuesday sunday, What would be the output?
main(int argc, char *argv[]) { printf("%c",*++argv[1]); }
A. r
B. f
C. m
D. y E.< Runtime error> ________________________________________ 66 . Would the following program compile? main() { int a=10,*j; void *k; j=k=&a; j++; k++; printf("\n%u%u",j,k); }
A. True
B. False ________________________________________
67 . According to ANSI specifications which is the correct way of declaring main() when it receives command line arguments?
A. main(int argc, char *argv[])
B. main(argc,argv) int argc; char *argv[];
C. main() {int argc; char *argv[]; }
D. None of the above ________________________________________
68 . What would be the output of the following program? main() { const int x=5; int *ptrx; ptrx=&x; *ptrx=10; printf("%d",x); }
A. 5
B. 10 C. Error
D. Garbage Value <Gia’ tri vo nghia~>
69. main() { int i; clrscr(); printf("%d", &i)+1; scanf("%d", i)-1; }
A. Runtime error. Access violation
B. Compile error. Illegal syntax
C. None of the above
D. Runtime error ________________________________________
70 . main(int argc, char *argv[]) { (main && argc) ? main(argc-1, NULL) : return 0; }
A. Gets into Infinite loop
B. Compile error. Illegal syntax C. None of the above
D. Runtime error. ________________________________________
71. main() { int i; float *pf; pf = (float *)&i; *pf = 100.00; printf("\n %d", i); }
A. Some Integer not 100
B. 100
C. Runtime error.
D. None of the above ________________________________________ 72. main() { int i = 0xff ; printf("\n%d", i<<2); }
A. 1020
B. 512
C. 4
D. 1024 ________________________________________
73. #define SQR(x) x * x main() { printf("%d", 225/SQR(15)); }
A. 15
B. 225
C. 1
D. none of the above ________________________________________
74. union u { struct st { int i : 4; int j : 4; int k : 4; int l; }st; int i; }u; main() { u.i = 100; printf("%d, %d, %d",u.i, u.st.i, u.st.l); }
A. 40, 4, 0
B. 100, 4, 0
C. 0, 0, 0
D. 4, 4, 0 ________________________________________
75 . union u { union u { int i; int j; }a[10]; int b[10]; }u; main() { printf("\n%d", sizeof(u)); printf(" %d", sizeof(u.a)); // printf("%d", sizeof(u.a[4].i)); }
A. 1, 100, 1
B. 40, 4, 4
C. 4, 4, 4
D. None of the Above ________________________________________
76 . main() { int i, j, *p; i = 25; j = 100; p = &i; // Address of i is assigned to pointer p printf("%f", i/(*p) ); // i is divided by pointer p }
A. Compile error
B. 1.00000
C. Runtime error.
D. Runtime error. ________________________________________
77 . main() { int i, j; scanf("%d %d"+scanf("%d %d", &i, &j)); printf("%d %d", i, j); }
A. Compile error
B. 0, 0
C. Runtime error.
D. the first two values entered by the user<nhap vao 2 gia tri> ________________________________________
78 . main() { char *p = "hello world"; p[0] = 'H'; printf("%s", p); }
A. Compile error
B. "Hello world"
C. Runtime error.
D. "hello world" ________________________________________
79 . main() { char * strA; char * strB = I am OK; memcpy( strA, strB, 6); }
A. Compile error
B. I am OK
C. Runtime error.
D. I am O ________________________________________ 80 . How will you print % character? | |
| | | tenluumanh
Tổng số bài gửi : 8 Age : 38 Registration date : 23/07/2007
| Tiêu đề: Re: Mot so bai tham khao!! Tue Jul 24, 2007 5:47 am | |
| | |
| | | tu033
Tổng số bài gửi : 14 Age : 41 Registration date : 08/06/2007
| Tiêu đề: Re: Mot so bai tham khao!! Tue Jul 24, 2007 11:59 am | |
| Hau oi ong post not cai bai 3 nhap day so nguyen len di. | |
| | | Sponsored content
| Tiêu đề: Re: Mot so bai tham khao!! | |
| |
| | | | Mot so bai tham khao!! | |
|
Trang 1 trong tổng số 1 trang | |
| Permissions in this forum: | Bạn không có quyền trả lời bài viết
| |
| |
| |