|
|
| input 4 integers and output values of them by 8 ways | |
| | Fri 09 Oct 2009, 10:15 pm | | vanquaninformatics BINH NHI | -Sinh nhật : 06/07/1989
-Đến từ : binh thuan province -Sở thích : nothings special -Điểm tích cực : 18 -Cảm ơn : 1
|
| | Tiêu đề: input 4 integers and output values of them by 8 ways | |
| | | | | | Nguồn : http://sptinbt.forum-viet.net/t30-topic Tiêu Đề : input 4 integers and output values of them by 8 ways
Nếu thấy bài viết này hay thì xin click vào nút [Cảm ơn] bên dưới để thay cho lời cảm ơn nhé --------------------------------------------------
các bạn cho ý kiến đóng góp cho bài hay thêm nha,có gì không hiểu cứ để lại reply mình sẽ có response cho các bạn: way one : //CACH1 - LAM BANG CLASS: #include using namespace std; class input_output { private: int a[4]; public: void input() { cout<<"input 4 integers you want:"< for(int i=0 ; i<4 ; i++) { cout<<"input a["< cin>>a[i]; } } void output() { cout<<"4 integers you have inputted : "< for(int i=0 ; i<4 ; i++) { cout<<"a["< } } }; void main() { input_output a; a.input(); a.output(); }
way two:
//CACH 2- LAM BANG DO...WHILE
#include #include using namespace std; void main() { int i=0,a[4]; cout<<"input value:"< do { cout<<"a["< cin>>a[i]; i++; }while(i<4); cout<<"4 integers you have inputted : "< for(int j=0 ; j<4 ; j++) { cout<< } system("pause"); }
way three:
//CACH 3 - LAM BANG WHILE
#include #include using namespace std; void main() { int i=0,j=0,a[4]; cout<<"input 4 integers you want:"< while(i<4) { cout<<"a["< cin>>a[i]; i++; } cout<<"4 values of integer you have inputted :"< while(j<4) { cout<< j++; } }
way four:
//CACH4 - CACH LAM BANG FOR #include #include using namespace std; void main() { int a[4]; cout<<"input 4 integers you want :"< for(int i=0 ; i<4 ; i++) { cout<<"a["< cin>>a[i]; } cout<<"4 integers you have inputted :"; for(int j=0; j<4 ; j++) { cout<< } }
way five:
//CACH 5 - CAU TRUC:
#include #include using namespace std;
struct input_output { int a[4]; }; //definition <<: ostream& operator <<(ostream &os ,input_output &n) { for(int i=0 ; i<4 ;i++) { os<< } return os; } //definition >>: istream& operator >>(istream &is ,input_output &n) { for(int i=0 ; i<4 ; i++) { cout<<"a["< is>>n.a[i]; } return is; } //main function: void main() { input_output n; cout<<"input 4 integers you want:"< cin>>n; cout<<"4 values of integer you have inputted :"< cout<}
way six:
//BAI6 - HAM; #include #include using namespace std; void input(int a[],int size) { for(int i=0 ; i { cout<<"a["< cin>>a[i]; } cout<} void output(int a[],int size) { for(int i=0 ; i cout<<} void main() { int a[4],size = 4; cout<<"input 4 integers you want:"< input(a,size); cout<<"4 values of integer you have inputted:"< output(a,size); }
way seven:
#include #include using namespace std; void nput(int *f) { for(int i=0 ; i<4 ; i++) { cout<<"a["< cin>>*(f+i); } } void utput(int *g) { for(int i=0 ; i<4 ; i++) cout<<<*(g+i); } void main() { int a[4]; cout<<"input 4 integers you want:"< nput(&a[4]); cout<<"4 values of integer you have inputted:"< utput(&a[4]); }
way eight:
#include using namespace std; void input(char *f,int a[],int size1) { int i; FILE *fp; fp = fopen(f,"r"); for(i= 0 ; i fscanf(fp,"%d",&a[i]); fclose(fp); } void output(char *f,int b[],int size2) { int i; FILE *fp; fp = fopen(f,"w"); for(i=0 ; i fprintf(fp,"%d",b[i]); fclose(fp); } void main() { const int n=4; int a[n];//THAY KIỂU CỦA A[N] THÀNH CHAR ÄỂ THẤY ÄƯỢC VẤN ÄỀ MỚI: char f[9]="inpu.txt"; char g[10]="outpu.txt"; input(f,a,n); output(g,a,n); } --------------------------------------------------
| | | | |
Copy đường link gửi cho bạn bè ! |
|
|
Sat 10 Oct 2009, 12:58 pm | | Ngoc Toan Thống Sói | -Sinh nhật : 24/05/1985
-Đến từ : Bình Thuận -Sở thích : phá phách -Điểm tích cực : 1231 -Cảm ơn : 3
|
| | Tiêu đề: Re: input 4 integers and output values of them by 8 ways | |
| |
Copy đường link gửi cho bạn bè ! |
|
|
Sat 10 Oct 2009, 4:35 pm | | vanquaninformatics BINH NHI | -Sinh nhật : 06/07/1989
-Đến từ : binh thuan province -Sở thích : nothings special -Điểm tích cực : 18 -Cảm ơn : 1
|
| | Tiêu đề: Re: input 4 integers and output values of them by 8 ways | |
| |
Copy đường link gửi cho bạn bè ! |
|
|
| | Sponsored content
| |
| | |
Trang 1 trong tổng số 1 trang | | * Viết tiếng Việt có dấu, là tôn trọng người đọc. * Chia sẻ bài sưu tầm có ghi rõ nguồn, là tôn trọng người viết. * Thực hiện những điều trên, là tôn trọng chính mình.-Nếu chèn smilies có vấn đề thì bấm A/a trên phải khung viết bài
| Permissions in this forum: | Bạn không có quyền trả lời bài viết
| |
| |
|
|