Практикум по программированию. Основы. Массивы. Поиск сотрудников
From AsIsWiki
(Difference between revisions)
Line 9: | Line 9: | ||
<pre> | <pre> | ||
− | |||
− | |||
− | |||
public class Task21 { | public class Task21 { | ||
Line 17: | Line 14: | ||
public static void main(String[] args) { | public static void main(String[] args) { | ||
− | |||
− | |||
System.out.println(); | System.out.println(); | ||
Line 49: | Line 44: | ||
<pre> | <pre> | ||
+ | // g++ 4.2 | ||
+ | |||
+ | #include <iostream> | ||
+ | |||
+ | using namespace std; | ||
+ | |||
+ | int main() { | ||
+ | |||
+ | cout << "\n Поиск сотрудников обладающих зарплатой от 1000$ до 3000$\n"; | ||
+ | cout << "----------------------------------------------------------\n"; | ||
+ | |||
+ | srand((int)time(0)); | ||
+ | |||
+ | const int n = 5; | ||
+ | |||
+ | int a[n]; | ||
+ | |||
+ | for (int i = 0; i < n; i++) { | ||
+ | a[i] = 500 + (rand() % 5000); | ||
+ | printf(" Сотрудник %d Зарплата: %4d$\n", i + 1, a[i]); | ||
+ | } | ||
+ | |||
+ | cout << "----------------------------------------------------------\n"; | ||
+ | cout << " Зарплатой 1000$ - 3000$ обладают сотрудники:"; | ||
+ | |||
+ | for (int i = 0; i < n; i++) { | ||
+ | if ((a[i] >= 1000) && (a[i] <= 3000)) { | ||
+ | cout << " " << (i + 1); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | cout << "\n\n"; | ||
+ | |||
+ | return 0; | ||
+ | } | ||
</pre> | </pre> | ||
Latest revision as of 08:05, 21 April 2015
Contents |
[edit] Java
public class Task21 { private static final int n = 5; public static void main(String[] args) { System.out.println(); System.out.println(" Поиск сотрудников обладающих зарплатой от 1000$ до 3000$ "); System.out.println("----------------------------------------------------------"); int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = (int) (500 + 5000 * Math.random()); System.out.printf(" Сотрудник %d Зарплата: %4d$\n", i + 1, a[i]); } System.out.println("----------------------------------------------------------"); System.out.print(" Зарплатой 1000$ - 3000$ обладают сотрудники:"); for (int i = 0; i < n; i++) { if ((a[i] >= 1000) && (a[i] <= 3000)) { System.out.print(" " + (i + 1)); } } System.out.println(); } }
[edit] C++
// g++ 4.2 #include <iostream> using namespace std; int main() { cout << "\n Поиск сотрудников обладающих зарплатой от 1000$ до 3000$\n"; cout << "----------------------------------------------------------\n"; srand((int)time(0)); const int n = 5; int a[n]; for (int i = 0; i < n; i++) { a[i] = 500 + (rand() % 5000); printf(" Сотрудник %d Зарплата: %4d$\n", i + 1, a[i]); } cout << "----------------------------------------------------------\n"; cout << " Зарплатой 1000$ - 3000$ обладают сотрудники:"; for (int i = 0; i < n; i++) { if ((a[i] >= 1000) && (a[i] <= 3000)) { cout << " " << (i + 1); } } cout << "\n\n"; return 0; }
[edit] Pascal