给定数字N ,任务是找到X i的N个整数,使得X 1
例子:
Input: N = 5
Output:
X1 = 0 sin(X1) = 0.000000
X2 = 710 sin(X2) = 0.000060
X3 = 1420 sin(X3) = 0.000121
X4 = 2130 sin(X4) = 0.000181
X5 = 2840 sin(X5) = 0.000241
Input: N = 3
Output:
X1 = 0 sin(X1) = 0.000000
X2 = 710 sin(X2) = 0.000060
X3 = 1420 sin(X3) = 0.000121
方法:想法是使用PI(&PI)的分数;即, Pi = 355/113,因为它给出的PI精度的最佳合理值为0.000009%。
As,
PI = 355/113
=> 113*PI = 355
=> 2*(113*PI) = 710
As sin() function has a period of 2*PI,
Therefore sin(2*k*PI + Y) = sin(Y);
根据上面的等式,获得值X 1
下面是上述方法的实现:
C++
// C++ program for the above approach
#include
using namespace std;
// Function to print all such Xi s.t.
// all Xi and sin(Xi) are strictly
// increasing
void printSinX(int N)
{
int Xi = 0;
int num = 1;
// Till N becomes zero
while (N--) {
cout << "X" << num << " = " << Xi;
cout << " sin(X" << num << ") = "
<< fixed;
// Find the value of sin() using
// inbuilt function
cout << setprecision(6)
<< sin(Xi) << endl;
num += 1;
// increment by 710
Xi += 710;
}
}
// Driver Code
int main()
{
int N = 5;
// Function Call
printSinX(N);
return 0;
}
Java
// Java program for the above approach
import java.util.*;
class GFG{
// Function to print all such Xi s.t.
// all Xi and sin(Xi) are strictly
// increasing
static void printSinX(int N)
{
int Xi = 0;
int num = 1;
// Till N becomes zero
while (N-- > 0)
{
System.out.print("X" + num + " = " + Xi);
System.out.print(" sin(X" + num + ") = ");
// Find the value of sin() using
// inbuilt function
System.out.printf("%.6f", Math.sin(Xi));
System.out.println();
num += 1;
// Increment by 710
Xi += 710;
}
}
// Driver Code
public static void main(String[] args)
{
int N = 5;
// Function Call
printSinX(N);
}
}
// This code is contributed by Princi Singh
Python3
# Python3 program for the above approach
import math
# Function to print all such Xi s.t.
# all Xi and sin(Xi) are strictly
# increasing
def printSinX(N):
Xi = 0;
num = 1;
# Till N becomes zero
while (N > 0):
print("X", num, "=", Xi, end = " ");
print("sin(X", num, ") =", end = " ");
# Find the value of sin() using
# inbuilt function
print("{:.6f}".format(math.sin(Xi)), "\n");
num += 1;
# increment by 710
Xi += 710;
N = N - 1;
# Driver Code
N = 5;
# Function Call
printSinX(N)
# This code is contributed by Code_Mech
C#
// C# program for the above approach
using System;
class GFG{
// Function to print all such Xi s.t.
// all Xi and sin(Xi) are strictly
// increasing
static void printSinX(int N)
{
int Xi = 0;
int num = 1;
// Till N becomes zero
while (N-- > 0)
{
Console.Write("X" + num + " = " + Xi);
Console.Write(" sin(X" + num + ") = ");
// Find the value of sin() using
// inbuilt function
Console.Write("{0:F6}", Math.Sin(Xi));
Console.WriteLine();
num += 1;
// Increment by 710
Xi += 710;
}
}
// Driver Code
public static void Main(String[] args)
{
int N = 5;
// Function Call
printSinX(N);
}
}
// This code is contributed by SoumikMondal
输出:
X1 = 0 sin(X1) = 0.000000
X2 = 710 sin(X2) = 0.000060
X3 = 1420 sin(X3) = 0.000121
X4 = 2130 sin(X4) = 0.000181
X5 = 2840 sin(X5) = 0.000241