Guest User

Untitled

a guest
Aug 16th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. /*
  2. * File: main.cpp
  3. * Author: undefiened
  4. *
  5. * Created on 24 Май 2012 г., 21:48
  6. */
  7.  
  8. #include <cstdlib>
  9. #include <iostream>
  10. #include "time.h"
  11.  
  12. using namespace std;
  13.  
  14. /*
  15. *
  16. */
  17.  
  18. void initiliase_array(int n, float *arr){
  19. for(int i = 0; i<n; i++){
  20. *(arr+i) = rand()%10000;
  21. *(arr+i) /= 100;
  22. cout<<*(arr+i)<<" ";
  23. }
  24. }
  25.  
  26. int elems_less_then_k(float *arr, float k, int n){
  27. int counter = 0;
  28. for(int i = 0; i<n; i++){
  29. if(*(arr+i)<k){
  30. counter++;
  31. }
  32. }
  33. return counter;
  34. }
  35.  
  36. int main(int argc, char** argv) {
  37. srand(time(NULL));
  38. float A[10];
  39. float B[30];
  40. float min;
  41. int count = 0;
  42.  
  43. cout<<"Заполним массив А"<<endl;
  44.  
  45. initiliase_array(10,A);
  46.  
  47. cout<<endl<<"Заполним массив В"<<endl;
  48. initiliase_array(30, B);
  49.  
  50. cout<<endl<<"Минимум массива А = ";
  51. min = A[0];
  52. for(int i = 0; i<10; i++){
  53. if(A[i]<min){
  54. min = A[i];
  55. }
  56. }
  57. cout<<min<<endl;
  58. count = elems_less_then_k(B,min,30);
  59. if(count==0){
  60. cout<<"Нет таких элементов"<<endl;
  61. } else {
  62. cout<<"Есть "<<count<<" элементов, меньших "<<min<<endl;
  63. }
  64.  
  65.  
  66. }
Add Comment
Please, Sign In to add comment