Last active
February 8, 2023 11:01
-
-
Save p182/0419a7198d3e9555989ff34b1cce279c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> //Бібліотека з функціями rand і srand | |
#include <time.h> //Для генерації "солі", функції rand(srand) | |
int main () { | |
int arr[1024]; //ініціалізація масиву в пам'яті | |
int i,n=10,c=0; | |
srand(time(NULL)); //ініціалізація "солі" | |
//заповнення масиву | |
for ( i = 0; i < n; i++ ) { | |
arr[i] = rand() % 150-50; //випадковими числами від -50 до 100 | |
} | |
printf("Всі елементи масиву: \n"); | |
/*вивід всіх елементів масиву*/ | |
for (i = 0; i < n; i++ ) { | |
printf("[%d] = %d\n", i, arr[i] ); | |
} | |
printf("\nЕлементи масиву, більші за правого сусіда: "); | |
/*вивід номерів елементів масиву, більших за правого сусіда*/ | |
for (i = 0; i < n-1; i++ ) { | |
if (arr[i]>arr[i+1]){ | |
printf("%d;", i); | |
c++; | |
} | |
} | |
printf("\nКількість елементів, більших за правого сусіда: %d", c); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment