Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <stdio.h>
- #include <algorithm>
- using namespace std;
- double* a;
- int n;
- double find_min(double*a){
- double ans = -1;
- for(int i = 0; i < n; ++i){
- if(a[i]>0 && ans == -1){
- ans = a[i];
- }else if(a[i]>0 && ans != -1){
- ans = min(ans, a[i]);
- }
- }
- if(ans == -1){
- printf("нет элементов >0\n");
- return 0;
- }
- return ans;
- }
- double sredn(double*a){
- int j = 0;
- for(int i = 1; i < n; ++i) {
- if(a[i]>=a[j]) j = i;
- }
- double ans = 0;
- for(int i = 0; i < j; ++i) {
- ans += a[i];
- }
- if(!j){
- printf("%lf\n", 0);
- return 0;
- }
- return ans/j;
- }
- void create(double **pa, int* pn){
- printf("n = ");
- scanf("%d\n", &n);
- a = (double*)malloc(sizeof(double)*n);
- for(int i=0;i<n;++i){
- scanf("%lf", &a[i]);
- }
- *pa = a;
- *pn = n;
- }
- double sr(double* a){
- double ans =0;
- int col=0;
- for(int i=0;i<n;++i){
- if(a[i]>0){
- ans+=a[i];
- ++col;
- }
- }
- if(!col){
- return 0;
- }else{
- return ans/col;
- }
- }
- int main()
- {
- create(&a, &n);
- printf("Ответ на первое задание = %lf\n",find_min(a));
- printf("Ответ на второе задание = %lf\n",sredn(a));
- printf("ответ на доп задание = %lf\n", sr(a));
- free(a);
- return 0;
- }
- //6
- //5.5 3 -2 5.5 5 -1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement