Array1. Дано целое число N > 0. Сформировать и вывести целочисленный массив размера N, содержащий N первых положительных нечетных чисел: 1, 3, 5, … .
>Решение Pascal
1 2 3 4 5 6 7 8 9 10 11 12 | program Array1; var a:array[1..10] of integer; N,i:Integer; begin Write('N:'); Readln(N); for i:=1 to N do a[i]:=i*2-1; for i:=1 to N do writeln(i,' : ',a[i]); end. |
>
Решение C
1 2 3 4 5 6 7 8 9 10 11 12 | #include <stdio.h> int main(void) { int a[10]; int n, i=1,i2=1; printf("N: "); scanf("%i",&n); for (i=0; i<n; ++i, i2+=2) a[i]=i2; for (i=0; i<n; ++i) printf("%i : %i\n",i,a[i]); return 0; } |
Решение C++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #include <iostream> using namespace std; int main() { int a[100]; int n; cout << "N: "; cin >> n; for (int i=0; i<n; i++) a[i] = 1 + i*2; for (int i=0; i<n; ++i) cout << "a[" << i << "]=" << a[i] << endl; return 0; } |
Решение C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | using System; namespace ConsoleApp { class Program { static void Main(string[] args) { Console.Write("N:"); int n = Convert.ToInt32(Console.ReadLine()); int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = 1 + i * 2; for (int i = 0; i < n; ++i) Console.WriteLine("a[" + i + "]=" + a[i]); Console.ReadKey(); } } } |
>
Решение Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | package abramyan; import java.util.Scanner; public class Abramyan { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("N:"); int n = in.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = 1 + i * 2; for (int i = 0; i < n; ++i) System.out.println("a[" + i + "]=" + a[i]); in.close(); } } |
Помогите пожалуйста написать программу на языке программирование Java.
Бег. Пользователь указывает количество км за каждый день в течение некоторого периода времени. Программа находит общий пробег, среднее значение в день, наименьшее и наибольшее значения.
#include
#include
using namespace std;
int main(){
const int l = 5;
int array[l] = {5,8,2,3,9};
for (int st = 0; st < l — 1; ++st)
{
int sm = st;
for (int c = st + 1; c < l; ++c)
if (array[c] < array[sm])
sm = c;
swap(array[st], array[sm]);
}
for (int i = 0; i < l; ++i)
cout << array[i] << ' ';
return 0;
}
#include
using namespace std;
int main() {
setlocale(LC_ALL,»ru»);
int n;
cout <> n;
const int SIZE=n;
int arr[SIZE];
for (int i=1; i <= SIZE; i+=2){
cout << i<< " ";
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int[] array = new int[a];
for (int i = 0; i<array.length; i++){
array[i]=i;
if (array[i]%2!=0){
System.out.print(array[i]+" ");
}
}
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int[] array = new int[a];
for (int i = 0; i<array.length; i++){
array[i]=i;
if (array[i]%2!=0){
System.out.print(array[i]+" ");
}
}
}
}
//pascal
##
var n := readinteger;
var a: array of integer;
SetLength (a, n);
a[0] := 1;
for var i := 1 to n-1 do a[i] := a[i-1]+2;
a.println