Find N values of X1, X2, … Xn such that X1 < X2 < … < XN and sin(X1) < sin(X2) < … < sin(XN)

Given a number N, the task is to find the N integer values of Xi such that X1 < X2 < … < XN and sin(X1) < sin(X2) < … < sin(XN).

Examples:

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

Approach: The idea is to use the fractional value of PI(&PI); i.e., Pi = 355/113 as it given best rational value of PI of accuracy being 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);

As per the above equation to get the value X1 < X2 < … < XN and sin(X1) < sin(X2) < … < sin(XN) we must find the value of sin(X) with an increment of 710.

Below is the implementation of the above approach:

C++

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program for the above approach
#include <bits/stdc++.h>
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;
}

chevron_right


Java

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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

chevron_right


Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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

chevron_right


C#

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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

chevron_right


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

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.