1. Sửa lỗi viết hoa
#include<stdio.h>
#include<conio.h>
#include<string.h>
void sualoi(char s[])
{
int i;
int l = strlen(s);
for(i=l;i>0;i--)
{
if(s[i] != ' ') s[i+1] = s[i];
else s[i-1] = toupper(s[i]);
}
}
int main()
{
char s[100];
int i;
int l = strlen(s);
printf("nhap vao mot chuoi: ");
gets(s);
printf("chuoi chua sua la: %s\n",s);
printf("chuoi da sua la: ");
sualoi(s);
for(i=l;i>0;i--)
printf("%s",s[i]);
getch();
return 1;
}
#include<stdio.h>3. Thuật toán
#include<conio.h>
int main()
{
int a[100],b[100];
int gia;
int i,n,hieu;
printf("nhap vao so luong khach hang:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("nhap vao khach hang thu %d\n",i+1);
printf("tien dien thang 9: ");
scanf("%d",&a[i]);
printf("tien dien thanh 10:");
scanf("%d",&b[i]);
while(a[i] > b[i])
{
printf("ban da nhap so lieu sai, moi nhap lai: \n");
printf("tien dien thang 9: ");
scanf("%d",&a[i]);
printf("tien dien thanh 10:");
scanf("%d",&b[i]);
}
printf("\n");
}
printf("---------------//-----------------\n");
for(i=0;i<n;i++)
{
hieu = b[i]-a[i];
gia = hieu>350?(hieu-350)*1500+305000:hieu>250?(hieu-250)*1200+185000:hieu>150?
(hieu-150)*1000+85000:hieu>50?(hieu-50)*800+5000:hieu*500;
printf("so tien dien nguoi %d phai tra la: %d\tnghin dong\n",i+1,gia);
}
getch();
return 1;
}
#include<stdio.h>4. Xếp loại điểm
#include<conio.h>
int main()
{
int a,b,r,q,x,y;
int x0 = 1;
int x1 = 0;
int y0 = 0;
int y1 = 1;
printf("nhap vao so a: ");
scanf("%d",&a);
printf("nhap vao so b: ");
scanf("%d",&b);
if(b==0)
printf("UCLN la: %d",a);
{
while(b>0)
{
r = a/b;
q = a%b;
x = x0-x1*q;
y = y0-y1*q;
if(r==0) break;
a=b;
b=r;
x0=x1;
x1=x;
y0=y1;
y1=y;
} return b;
printf("UCLN la: %d",b);
}
getch();
return 1;
}
#include<stdio.h>
#include<conio.h>
int main()
{
int i,n;
float a[100];
printf("nhap vao so luong thi sinh: ");
scanf("%d",&n);
printf("moi nhap vao diem thi sinh \n");
for(i=0;i<n;i++)
{
printf("%d :",i+1);
scanf("%f",&a[i]);
}
for(i=0;i<n;i++)
{
//xeploai = a[i]>9?gioi:a[i]>7?kha:a[i]>5?trungbinh:yeu;
if(a[i]>=9) printf("%0.2f\t\t\t\tgioi\n",a[i]);
else if(a[i]>=7) printf("%0.2f\t\t\t\tkha\n",a[i]);
else if(a[i]>=5) printf("%0.2f\t\t\t\ttrungbinh\n",a[i]);
else printf("%0.2f\t\t\t\tyeu\n",a[i]);
}
getch();
}
0 comments:
Post a Comment