原文:
给定一个整数数组,打印当前索引元素和数组的后续下一个索引元素之间的中间值。 示例:
input : arr[] = { 4, 2, 7, 5};
output :
intermediate elements between 4 and 2
2 3 4
intermediate elements between 2 and 7
2 3 4 5 6 7
intermediate elements between 7 and 5
5 6 7
c
// c program to print the
// intermediate value
#include
using namespace std;
void inter(int arr[], int n)
{
for (int l = 0; l < n - 1; l )
{
// points to first index element
int i = arr[l];
// points to preceding index element
int j = arr[l 1];
// find big element
// between the above elements
int big = i > j ? i : j;
// find small element
// between the above elements
int sml = i < j ? i : j;
cout<<"intermediate elements between "<<
i <<" and "<
java 语言(一种计算机语言,尤用于创建网站)
// java program to print the
// intermediate values
public class gfg
{
static void inter(int[] arr)
{
for (int l = 0; l < arr.length - 1; l )
{
// points to first index element
int i = arr[l];
// points to preceding index element
int j = arr[l 1];
// find big element
// between the above elements
int big = i > j ? i : j;
// find small element
// between the above elements
int sml = i < j ? i : j;
system.out.println("intermediate elements between "
i " and " j);
for (int k = sml; k <= big; k )
system.out.print(k " ");
system.out.println();
}
}
// driver code
public static void main(string[] args)
{
int[] arr = { 4, 2, 7, 5 };
inter(arr);
}
}
python 3
# python 3 program to print the
# intermediate value
def inter(arr, n) :
for l in range( 0, n - 1) :
# points to first index element
i = arr[l]
# points to preceding index element
j = arr[l 1]
# find big element
# between the above elements
if(i>j) :
big = i
else :
big = j
# find small element
# between the above elements
if(i
c
// c# program to print the
// intermediate values
using system;
public class gfg
{
static void inter(int[] arr)
{
for (int l = 0; l < arr.length - 1; l )
{
// points to first index element
int i = arr[l];
// points to preceding index element
int j = arr[l 1];
// find big element
// between the above elements
int big = i > j ? i : j;
// find small element
// between the above elements
int sml = i < j ? i : j;
console.writeline("intermediate elements between "
i " and " j);
for (int k = sml; k <= big; k )
console.write(k " ");
console.writeline();
}
}
// driver code
public static void main()
{
int[] arr = { 4, 2, 7, 5 };
inter(arr);
}
}
// this code is contributed by vt_m.
服务器端编程语言(professional hypertext preprocessor 的缩写)
$j ? $i : $j;
// find small element
// between the above elements
$sml = $i < $j ? $i : $j;
echo "interermediate elements between ",
$i ," and ",$j,"\n";
for ($k = $sml; $k <= $big; $k )
echo $k," ";
echo "\n";
}
}
// driver code
$arr = array(4, 2, 7, 5);
$n=count($arr);
inter($arr,$n);
// this code is contributed by anuj_67.
?>
java 描述语言
输出:
intermediate elements between 4 and 2
2 3 4
intermediate elements between 2 and 7
2 3 4 5 6 7
intermediate elements between 7 and 5
5 6 7
麻将胡了pg电子网站的版权属于:月萌api www.moonapi.com,转载请注明出处