Bài tập tổng hợp
Post date: Dec 19, 2011 7:45:30 AM
#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<stdlib.h>
#include<string.h>
main()
{
int a[20],choice,n,i=0,j,tam;
FILE *fp;
char st[20];
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. Dua phu am len file *");
printf("\n* 3. Thoat *");
printf("\n***************************************");
printf("\nMoi ban nhap vao mot so:");
scanf("%d",&choice);
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]);
}
}
else if(choice==2)
{
if((fp=fopen("e:\\test.txt","w"))==NULL)
{
printf("Cannot file");
exit(1);
}
else
{
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')))
fputc(st[i],fp);
}
}
}
else
{
exit(1);
}
getch();
}