Bài 40: Tính S(x,n) =
có n dấu căn
//========================================//Cách 1
#include <stdio.h>
#include <conio.h>
#include <math.h>
void main()
{
float x;
scanf("%f", &x);
int n;
scanf("%d", &n);
float S = 0;
long T = 1;
int i = 1;
while (i <= n)
{
T = T * x;
S = pow(T+S, (float)1/2);
i = i + 1;
}
printf("%f", S);
}
//========================================
//Cách 2
/*
#include <stdio.h>
#include <conio.h>
#include <math.h>
float Can(float,int);
void main()
{
float x;
scanf("%f", &x);
int n;
scanf("%d", &n);
float kq = Can(x,n);
printf("%f", kq);
}
float Can(float y, int k)
{
float S = 0;
long T = 1;
for (int i=1; i<=k; i++)
{
T = T * y;
S = pow(T+S, (float)1/2);
}
return S;
}
*/
No comments:
Post a Comment