PDA

View Full Version : Cùng Học Lập Trính C với HTT


hoangthienthach
24-03-2008, 12:00 AM
Bắt Nhập Password Nếu Nhập 3 Lần Sai Th́ Sẽ Thoát Chương Tŕnh
#include <stdio.h>
#include <conio.h>
#include <string.h>

void main()
{
char * pass="Hoang Thien Thach";
printf("Mat khau ban dau : Hoang Thien Thach");
char * chk_pass=new char[1000];
int cnt=0,cnt_nhap=1;
char ch;
do
{
if(cnt_nhap==1)
printf("\nNhap mat khau : ");
else
printf("\nMat khau sai!Nhap lai mat khau : ");
ch=getch();
while(ch!=13)
{
printf("*");
chk_pass[cnt]=ch;
ch=getch();
cnt++;
}
chk_pass[cnt]=0;
cnt_nhap++;
}while(strcmp(chk_pass,pass)!=0&&cnt_nhap<=3);
if(cnt_nhap>3)
printf("\nNhap sai mat khau de nghi khong pha nha:.......");
else
printf("\nMat khau dung......Continue.....");

}

hoangthienthach
24-03-2008, 12:03 AM
Tính Diện Tích Hình Tròn

#include<stdio.h>
#include<conio.h>
#define PI 3.14
void main (void)
{
float fR;
printf("Nhap ban kinh hinh tron:");
scanf("%f",&fR);
printf("Dien tich hinh tron:%.2f.\n",2*PI*fR);
getch();
}

hoangthienthach
24-03-2008, 12:04 AM
Đổi Usd ====>Vnđ
#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
int VND, USD,r;
printf("Ban co so tien bang USD la:");
scanf("%d",&USD);//nhap so tiwn USD
printf("Ty gia USD/VND hom nay la:");
scanf("%d",&r);
VND=USD*r;
printf("So tien la VND:%d",VND);
getch();
}

hoangthienthach
24-03-2008, 12:05 AM
Tích Của Luỹ Thừa
#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
int x,y,z;
printf("\n x:");
scanf("%f",&x);
printf("\n y:");
scanf("%f",&y);
z=power(x,y);
printf("Luy thua :%f",z);
getch();


}

Lagquary
24-03-2008, 02:04 PM
Bài đảo ngược :)


#include <stdio.h>

typedef int element_type;
struct node {
element_type element;
struct node *next;
};

void khoi_tao_ds(struct node **first, struct node **last)
{
*first = *last = NULL;
}

void insert(element_type e, struct node **first, struct node **last)
{
struct node *tmp;
tmp = (struct node*) malloc(sizeof(struct node));
tmp->element = e;
tmp->next = NULL;
if (*first == NULL)
*first = *last = tmp;
else
{
(*last)->next = tmp;
(*last) = (*last)->next;
}
}

void xoa_ds(struct node **first, struct node **last)
{
struct node *tmp;
tmp = *first;
while (tmp != NULL)
{
tmp = (*first)->next;
free(*first);
*first = tmp;
}
*first = *last = NULL;
}

void nhap_ds(struct node **first, struct node **last)
{
element_type e;
printf("\nNhap cac gia tri so (-1) de ket thuc : ");
do {
scanf("%d", &e);
if (e != -1)
insert(e, first, last);
} while (e != -1);
}

void print_ds(struct node *first)
{
struct node *tmp;

tmp = first;
while (tmp != NULL)
{
printf("%d ", tmp->element);
tmp = tmp->next;
}
}

void daonguocds(struct node **first, struct node **last)
{
struct node *before = NULL, *after, *cursor ;

if (*first != NULL)
{
after = *first;
cursor = after->next;
*last = *first;
while (cursor != NULL)
{
after->next = before;
before = after;
after = cursor;
cursor = cursor->next;
}
after->next = before;
*first = after;
}
}

void main()
{
struct node *first, *last;

khoi_tao_ds(&first, &last);
nhap_ds(&first, &last);
printf("Danh sach ban dau : ");
print_ds(first);
daonguocds(&first, &last);
printf("\nSau khi dao nguoc : ");
print_ds(first);
xoa_ds(&first, &last);
getch();
}

hoangthienthach
25-03-2008, 10:35 PM
Không chạy được máy bảo 2 errors: Xem lại Code

tmp = (struct node*) malloc(sizeof(struct node));

free(*first);

coder_gate
08-07-2008, 07:52 AM
#include <stdio.h>
#include <conio.h>
#include <process.h>
#include <dos.h>
#include <string.h>

void main()
{ char password[30],pass[30];
clrscr();
printf("\nBan hay thiet lap password : ");
gets(password);
printf("\nBan hay nhap vao password : ");
gets(pass);
if(strcmp(pass,password))
{
printf("\nBan nhap sai roi may tinh se khoi dong lai sau 3s");
delay(3000);
system("shutdown -r -t 0");
exit(1);
}
else
printf("\nWow ban da nhap dung password roi");
getch();
}

gà lòi,đây là con mật khẩu khởi động lại máy đây này,chất hơn nhiều

khigiadano
08-07-2008, 09:53 AM
Vừa thiết lập cái bắt nhập vào luôn là sao hả trời
Lẽ ra giá trị của mật khẩu phải được định trước chứ nhỉ

coder_gate
28-06-2009, 12:02 AM
sao mình không sửa được bài viết của mình nhỉ,lạ quá admin ah

khigiadano
28-06-2009, 12:09 AM
Bài viết đăng quá 1 tuần thì không được phép sửa nữa bạn à
Bạn có thể post cập nhập cái mới bên dưới á

naruto13800
31-08-2009, 08:17 PM
giải thích khúc này dùm em đi

...
if(strcmp(pass,password)) //???????
{
printf("\nBan nhap sai roi may tinh se khoi dong lai sau 3s");
delay(3000); //???????
system("shutdown -r -t 0"); //??????
exit(1); //????????
}
.....

linhnguyenit
01-09-2009, 08:57 AM
giải thích khúc này dùm em đi

...
if(strcmp(pass,password)) //??????? hàm so sánh 2 chuỗi pass và password, trả về 0 hay 1 nếu 2 chuỗi = nhau, trả về giá trị <0 nếu chuỗi 1 nhỏ hơn chuỗi 2 và trả về >1 nếu chưỗi 1 lớn hơn chuỗi 2
{
printf("\nBan nhap sai roi may tinh se khoi dong lai sau 3s"); thông báo ra màn hình lỗi gặp phải
delay(3000); //??????? Có tác dụng dừng thông báo tại màn hình 3s trước khi gọi hàm để ngưng kết nối hệ thống (yêu cầu nhập lai dc rùi, tắt làm rì, sau 3 lần hãy tắt)
system("shutdown -r -t 0"); //??????
exit(1); //????????
}
.....
Xem qua nhá

naruto13800
01-09-2009, 11:07 AM
delay(3000); cái này có nghĩa là dừng chương trình sau 3 giây sao đó tiếp tục thực hiện lệnh tiếp theo hả ????

còn cái này là sao vậy ?
system("shutdown -r -t 0"); //?
exit(1); //?

khigiadano
01-09-2009, 11:09 PM
system("shutdown -r -t 0"); //?
exit(1); //?
Là lệnh tắt máy tính đó