Array18. Дан массив A ненулевых целых чисел размера 10. Вывести значение первого из тех его элементов AK, которые удовлетворяют неравенству AK < A10. Если таких элементов нет, то вывести 0.
>Решение Pascal
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | program Array18; var a:array[1..10] of integer; k:Integer; begin for k:=1 to 10 do begin write(k,' :'); readln(a[k]); end; k:=1; While (A[k]>=A[10]) and(k<10) do inc(k); if k=10 then writeln ('0') else Writeln (a[k]); end. |
>
Решение C
1 2 3 4 5 6 7 8 9 10 11 12 13 | #include int main(void) { int a[11]; int k; for (k=0; k<10; ++k){ printf("a[%i] : ",k+1); scanf("%i",&a[k]); } for (k=0; a[k]>=a[9]; ++k); if (k==10) printf("0\n: "); else printf("%i\n ",a[k]); return 0; } |
Можно эту задачу на языке С++…???
а также на с# !?!?!?!?
с++
int main()
{
int a[11];
int i;
for (i = 0; i > a[i];
}
for (i = 0; a[i] >= a[9]; ++i);
{
if (i == 10)
{
cout << "0";
}
if (i != 10)
{
cout << a[i];
}
}
}
он не работает
JAVA
import java.util.Scanner;
public class arr18 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print(«Enter N juft son: «);
int n = sc.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
}
int i;
for ( i = 0; i < a.length; i++) {
if (a[i] < a[a.length — 1]) {
System.out.println(a[i]);
break;
}
}
if (i==a.length) System.out.println(0 );
}
static void printArray(int[] number) {
for (int i = 0; i < number.length; i++) {
System.out.print(number[i] + " ");
}
System.out.println();
}
}
int n;
cout <> n;
int array[n];
bool find = false;
srand(time(NULL));
for (int i = 0; i < n; i++)
{
array[i] = rand() % 100 + 1;
cout << array[i] << " ";
}
cout << endl;
for (int i = 0; i array[n — 1])
{
find = true;
}
else if (array[i] < array[n — 1])
{
cout << array[i];
find = false;
break;
}
}
if (find)
{
cout << "\n0" << endl;
}
Для C++
#include
#include
#include
using namespace std;
int main(){
srand(time(NULL));
int K=-1,L=-1,N=-1,sumKL=0,sumarr=0;
while(N<=0){
cout<0)»<<endl<>N;
}
int arr[N];
for (int i=0;iK||K>N){
cout<<"(0 <= K <= N)"<<endl<>K;
}
while(K>L||L>=N){
cout<<"(K <= L < N)"<<endl<>L;
}
for(int i=0;i<N;i++){
cout<<i<<"th element: "<<arr[i]<<endl;
sumarr+=arr[i];
if(i==N-1){
cout<<"Sum of values of all array elements: "<<sumarr<<endl;
}
}
if (K!=L){
for(int i=K;i<=L;i++){
sumKL+=arr[i];
}
}else{
sumKL=arr[K];
}
cout<<"Sum of values of array elements from "<<K<<"th to "<<L<<"th : "<<sumKL;
}
с++
Они не работает