thu huong Moderator
Tổng số bài gửi : 25 Registration date : 17/09/2007
| Tiêu đề: ĐỆ QUI TÍNH TỔNG 8/4/2008, 20:12 | |
| làm ra kết quả đúng rồi. Bạn xem lại bài của mình nghe //1/1+(1+2)/(1*2)+1+2+3)/1*2*3)....+(1+2+3+...+n)/1*2*3...*n) - Code:
-
#include <iostream> #include <conio.h> #include <fstream>
using namespace std;
int n; void nhap() { ifstream fi; fi.open("data.txt"); fi>>n; fi.close(); } int TONG(int n) { if(n==1) return 1; else return n+TONG(n-1); } int NHAN(int n) { if(n==1) return 1; else return n*NHAN(n-1); } float TINH(int n) { if(n==1) return 1; else return TINH(n-1)+(float)TONG(n)/NHAN(n); } void xuat() { ofstream fo; fo.open("out.txt"); fo<<TINH(n); } void main() { nhap(); xuat(); }
| |
|