Nhờ xem lỗi bài tập tính tổng sqrt(x^2) / i

#include <iostream>
#include <math.h>

using namespace std;

void nhap(float x, int n){
	cout<<"Nhap so thuc x: ";
	cin>>x;
	do{
		cout<<"Nhap so nguyen duong n: ";
		cin>>n;
	}while(n<=0);
}

double tinhS(float x, int n){
	float S;
	if(n>=2 && x!=0){
        for(int i=1; i<n; i++){
            S += (sqrt(pow(x,2))/i);
        }
        cout<<"Gia tri bieu thuc la: "<<S;
	}
	else{
		S = n*n*x;
		cout<<"Gia tri bieu thuc la: "<<S;
	}
}

int main(){
	float x;
	int n;
	nhap(x,n);
	tinhS(x,n);
}

Haiz, sao ko viết là S += abs(x) / i :smiley: whoops

Bạn xem lại phần truyền tham số nhé.

2 Likes
S += (sqrt(pow(x,2))/i); (1)
(1) <=> S += (sqrt (x*x)) / I <=> S += x/i;

accc

Tại đề của em nó khoai quá

căn bậc 2 của x^2 =)))

Em xong rồi ạ !
Em cảm ơn !

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?