Dadas 3 coordenadas x, y y z, la tarea es determinar el octante del plano axial.
Ejemplos:
Entrada: 2, 3, 4
Salida: El punto se encuentra en el 1er octante
Entrada: -4, 2, -8
Salida: El punto se encuentra en el 6º octante
Entrada: -6, -2, 8
Salida: El punto se encuentra en el 3er octante
Aproximación: A continuación se presentan las condiciones que deben verificarse para determinar el octante del plano axial.
- Compruebe si x >= 0 y y >= 0 y z >= 0, entonces el punto se encuentra en el 1er octante.
- Compruebe x < 0 y y >= 0 y z >= 0, entonces el punto se encuentra en el segundo octante.
- Compruebe si x < 0 y y < 0 y z >= 0, entonces el punto se encuentra en el 3er octante.
- Compruebe si x >= 0 y y < 0 y z >= 0, entonces el punto se encuentra en el 4º octante.
- Compruebe si x >= 0 y y >= 0 y z < 0, entonces el punto se encuentra en el quinto octante.
- Compruebe si x < 0 y y >= 0 y z < 0, entonces el punto se encuentra en el sexto octante.
- Comprueba si x < 0, y < 0 y z < 0, entonces el punto se encuentra en el 7º octante.
- Compruebe si x >= 0 y y < 0 y z < 0, entonces el punto se encuentra en el octavo octante.
A continuación se muestra la implementación del enfoque anterior:
C++
// C++ program to print octant // of a given point. #include <bits/stdc++.h> #include<math.h> using namespace std; // Function to print octant void octant(float x, float y, float z) { if (x >= 0 && y >= 0 && z >= 0) cout << "Point lies in 1st octant\n"; else if (x < 0 && y >= 0 && z >= 0) cout << "Point lies in 2nd octant\n"; else if (x < 0 && y < 0 && z >= 0) cout << "Point lies in 3rd octant\n"; else if (x >= 0 && y < 0 && z >= 0) cout << "Point lies in 4th octant\n"; else if (x >= 0 && y >= 0 && z < 0) cout << "Point lies in 5th octant\n"; else if (x < 0 && y >= 0 && z < 0) cout << "Point lies in 6th octant\n"; else if (x < 0 && y < 0 && z < 0) cout << "Point lies in 7th octant\n"; else if (x >= 0 && y < 0 && z < 0) cout << "Point lies in 8th octant\n"; } // Driver Code int main() { float x = 2, y = 3, z = 4; octant(x, y, z) ; x = -4, y = 2, z = -8; octant(x, y, z); x = -6, y = -2, z = 8; octant(x, y, z); return 0; } // This code is contributed // by Amber_Saxena.
C
// C program to print octant // of a given point. #include <stdio.h> // Function to print octant void octant(float x, float y, float z) { if (x >= 0 && y >= 0 && z >= 0) printf("Point lies in 1st octant\n"); else if (x < 0 && y >= 0 && z >= 0) printf("Point lies in 2nd octant\n"); else if (x < 0 && y < 0 && z >= 0) printf("Point lies in 3rd octant\n"); else if (x >= 0 && y < 0 && z >= 0) printf("Point lies in 4th octant\n"); else if (x >= 0 && y >= 0 && z < 0) printf("Point lies in 5th octant\n"); else if (x < 0 && y >= 0 && z < 0) printf("Point lies in 6th octant\n"); else if (x < 0 && y < 0 && z < 0) printf("Point lies in 7th octant\n"); else if (x >= 0 && y < 0 && z < 0) printf("Point lies in 8th octant\n"); } // Driver Code int main() { float x = 2, y = 3, z = 4; octant(x, y, z) ; x = -4, y = 2, z = -8; octant(x, y, z); x = -6, y = -2, z = 8; octant(x, y, z); } // This code is contributed // by Amber_Saxena.
Java
// Java program to print octant // of a given point. import java.util.*; class solution { // Function to print octant static void octant(float x, float y, float z) { if (x >= 0 && y >= 0 && z >= 0) System.out.println("Point lies in 1st octant"); else if (x < 0 && y >= 0 && z >= 0) System.out.println("Point lies in 2nd octant"); else if (x < 0 && y < 0 && z >= 0) System.out.println("Point lies in 3rd octant"); else if (x >= 0 && y < 0 && z >= 0) System.out.println("Point lies in 4th octant"); else if (x >= 0 && y >= 0 && z < 0) System.out.println("Point lies in 5th octant"); else if (x < 0 && y >= 0 && z < 0) System.out.println("Point lies in 6th octant"); else if (x < 0 && y < 0 && z < 0) System.out.println("Point lies in 7th octant"); else if (x >= 0 && y < 0 && z < 0) System.out.println("Point lies in 8th octant"); } // Driver Code public static void main(String args[]) { float x = 2, y = 3, z = 4; octant(x, y, z) ; x = -4; y = 2; z = -8; octant(x, y, z); x = -6; y = -2; z = 8; octant(x, y, z); } } //This code is contributed by Surendra_Gangwar
Python
# Python program to print octant of a # given point. # Function to print octant def octant(x, y, z): if x >= 0 and y >= 0 and z >= 0: print "Point lies in 1st octant" elif x < 0 and y >= 0 and z >= 0: print "Point lies in 2nd octant" elif x < 0 and y < 0 and z >= 0: print "Point lies in 3rd octant" elif x >= 0 and y < 0 and z >= 0: print "Point lies in 4th octant" elif x >= 0 and y >= 0 and z < 0: print "Point lies in 5th octant" elif x < 0 and y >= 0 and z < 0: print "Point lies in 6th octant" elif x < 0 and y < 0 and z < 0: print "Point lies in 7th octant" elif x >= 0 and y < 0 and z < 0: print "Point lies in 8th octant" # Driver Code x, y, z = 2, 3, 4 octant(x, y, z) x, y, z = -4, 2, -8 octant(x, y, z) x, y, z = -6, -2, 8 octant(x, y, z)
C#
// C# program to print octant // of a given point. using System; class GFG { // Function to print octant static void octant(float x, float y, float z) { if (x >= 0 && y >= 0 && z >= 0) Console.WriteLine("Point lies in 1st octant"); else if (x < 0 && y >= 0 && z >= 0) Console.WriteLine("Point lies in 2nd octant"); else if (x < 0 && y < 0 && z >= 0) Console.WriteLine("Point lies in 3rd octant"); else if (x >= 0 && y < 0 && z >= 0) Console.WriteLine("Point lies in 4th octant"); else if (x >= 0 && y >= 0 && z < 0) Console.WriteLine("Point lies in 5th octant"); else if (x < 0 && y >= 0 && z < 0) Console.WriteLine("Point lies in 6th octant"); else if (x < 0 && y < 0 && z < 0) Console.WriteLine("Point lies in 7th octant"); else if (x >= 0 && y < 0 && z < 0) Console.WriteLine("Point lies in 8th octant"); } // Driver Code static public void Main () { float x = 2, y = 3, z = 4; octant(x, y, z) ; x = -4; y = 2; z = -8; octant(x, y, z); x = -6; y = -2; z = 8; octant(x, y, z); } } // This code is contributed by ajit
PHP
<?php // PHP program to print octant // of a given point. // Function to print octant function octant($x, $y, $z) { if ($x >= 0 && $y >= 0 && $z >= 0) echo "Point lies in 1st octant\n"; else if ($x < 0 && $y >= 0 && $z >= 0) echo "Point lies in 2nd octant\n"; else if ($x < 0 && $y < 0 && $z >= 0) echo "Point lies in 3rd octant\n"; else if ($x >= 0 && $y < 0 && $z >= 0) echo "Point lies in 4th octant\n"; else if ($x >= 0 && $y >= 0 && $z < 0) echo "Point lies in 5th octant\n"; else if ($x < 0 && $y >= 0 && $z < 0) echo "Point lies in 6th octant\n"; else if ($x < 0 && $y < 0 && $z < 0) echo "Point lies in 7th octant\n"; else if ($x >= 0 && $y < 0 && $z < 0) echo "Point lies in 8th octant\n"; } // Driver Code $x = 2; $y = 3; $z = 4; octant($x, $y, $z) ; $x = -4; $y = 2; $z = -8; octant($x, $y, $z); $x = -6; $y = -2; $z = 8; octant($x, $y, $z); // This code is contributed // by Amber_Saxena. ?>
Javascript
<script> // Javascript program to print octant // of a given point. // Function to print octant function octant( x, y, z) { if (x >= 0 && y >= 0 && z >= 0) document.write("Point lies in 1st octant"+"</br>"); else if (x < 0 && y >= 0 && z >= 0) document.write( "Point lies in 2nd octant"+"</br>"); else if (x < 0 && y < 0 && z >= 0) document.write("Point lies in 3rd octant"+"</br>"); else if (x >= 0 && y < 0 && z >= 0) document.write("Point lies in 4th octant"+"</br>"); else if (x >= 0 && y >= 0 && z < 0) document.write("Point lies in 5th octant"+"</br>"); else if (x < 0 && y >= 0 && z < 0) document.write("Point lies in 6th octant"+"</br>"); else if (x < 0 && y < 0 && z < 0) document.write("Point lies in 7th octant"+"</br>"); else if (x >= 0 && y < 0 && z < 0) document.write("Point lies in 8th octant"+"</br>"); } // driver code let x = 2, y = 3, z = 4; octant(x, y, z) ; x = -4, y = 2, z = -8; octant(x, y, z); x = -6, y = -2, z = 8; octant(x, y, z); // This code is contributed by jana_sayantan. </script>
Producción:
Point lies in 1st octant Point lies in 6th octant Point lies in 3rd octant
Publicación traducida automáticamente
Artículo escrito por anamika9988 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA