Bài Giải
/*
Name: DOi cho 2 so nguyen a va b
Copyright: None
Author: Tran Anh
Description: http://www.code.tavn.net
*/
#include<conio.h>
#include <stdio.h>
int hoanvi(int &u, int &v)
{
int tam;
tam=u;
u=v;
v=tam;
}
void change(int *u, int *v)
{
int tam;
tam=*u;
*u=*v;
*v=tam;
}
main()
{
//Trang tri chuong trinh
int l;
printf("\t");
for (l=1;l<30;l++) printf("* ");
printf("\n\t\t DOI CHO HAI SO NGUYEN\n\n");
//Het doan chuong trinh trang tri
int a,b;
printf("\t- Nhap vao so A= "); scanf("%d",&a);
printf("\t- Nhap vao so B= "); scanf("%d",&b);
change(&a,&b);
printf("\n\t- Gia tri A= %d\n",a);
printf("\t- Gia tri B= %d",b);
hoanvi(a,b);
printf("\n\n\t- Gia tri A= %d\n",a);
printf("\t- Gia tri B= %d",b);
getch();
return 0;
}
getch();
return 0;
}
Name: DOi cho 2 so nguyen a va b
Copyright: None
Author: Tran Anh
Description: http://www.code.tavn.net
*/
#include<conio.h>
#include <stdio.h>
int hoanvi(int &u, int &v)
{
int tam;
tam=u;
u=v;
v=tam;
}
void change(int *u, int *v)
{
int tam;
tam=*u;
*u=*v;
*v=tam;
}
main()
{
//Trang tri chuong trinh
int l;
printf("\t");
for (l=1;l<30;l++) printf("* ");
printf("\n\t\t DOI CHO HAI SO NGUYEN\n\n");
//Het doan chuong trinh trang tri
int a,b;
printf("\t- Nhap vao so A= "); scanf("%d",&a);
printf("\t- Nhap vao so B= "); scanf("%d",&b);
change(&a,&b);
printf("\n\t- Gia tri A= %d\n",a);
printf("\t- Gia tri B= %d",b);
hoanvi(a,b);
printf("\n\n\t- Gia tri A= %d\n",a);
printf("\t- Gia tri B= %d",b);
getch();
return 0;
}
getch();
return 0;
}
Không có nhận xét nào:
Đăng nhận xét