Bài 2:
Post date: Dec 5, 2011 6:52:20 AM
Yêu cầu: Viết chương trình hiển thị menu có dạng như sau:
****************************************************************************
Họ tên: MSSV:
Ngày sinh: Lớp:
1 - Đổi số thập phân sang thập lục phân.
2 - Nhập vào 1 chuỗi và in phụ âm ra màn hình.
3 - Thoát khỏi chương trình.
****************************************************************************
Hướng dẫn:
#include<stdio.h>
#include<string.h>
main()
{
int a[20],choice,n,i=0,j,tam;
char st[20];
//Hiển thị menu
printf("\n******************************************");
printf("\n* Ho ten: *");
printf("\n* Ngay sinh: *");
printf("\n* Ma so: *");
printf("\n* 1. Doi so thap luc phan *");
printf("\n* 2. In phu am ra man hinh *");
printf("\n* 3. Thoat *");
printf("\n******************************************");
printf("\nMoi ban nhap vao mot so:");
scanf("%d",&choice);
//Doi so thap luc phan
if(choice==1)
{
printf("Nhap so thap phan:");
scanf("%d",&n);
while(n!=0)
{
a[i]=n%16;
n=n/16;
i++;
}
printf("He 16 la:");
for(j=i-1;j>=0;j--)
{
if(a[j]==10)
printf("A");
else if(a[j]==11)
printf("B");
else if(a[j]==12)
printf("C");
else if(a[j]==13)
printf("D");
else if(a[j]==14)
printf("E");
else if(a[j]==15)
printf("F");
else
printf("%d",a[j]);
}
}
//in phu am ra man hinh
else if(choice==2)
{
{
printf("Nhap vao mot chuoi:");
scanf("%s",st);
strcat(st,"\n");
for(i=0;i<strlen(st);i++)
{
if((st[i]=='a')|| (st[i]=='e')||(st[i]=='i')||(st[i]=='o')||(st[i]=='u')||
(st[i]=='A')||(st[i]=='E')||(st[i]=='I')|| (st[i]=='O')||(st[i]=='U'))
continue;
else
if(((st[i] >= 'a') && (st[i] <= 'z'))||((st[i]>='A') && (st[i]<='Z')))
printf("%c",st[i]);
}
}
}
else
{
exit(1);
}
getch();
}