Advertisement
lil_SV

7 лаба

Oct 8th, 2021
1,121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.38 KB | None | 0 0
  1. // main.c
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <malloc.h>
  5. #include "lib.h"
  6.  
  7. int main()
  8. {
  9.     int n=getSize();
  10.     double *a,*b,*c,*d,*e;
  11.     a=getArray(n);
  12.     b=getArray(n);
  13.     c=getArray(n);
  14.     d=initArray(a,b,n);
  15.     e=initArray(b,c,n);
  16.     printf("1 последовательность:\n");
  17.     for(double *i=d;i!=&d[n];i++)printf("%lf  ",*i);
  18.     printf("\n2 последовательность:\n");
  19.     for(double *i=e;i!=&e[n];i++)printf("%lf  ",*i);
  20.     return 0;
  21. }
  22.  
  23. // lib.h
  24. #ifndef LIB_H_INCLUDED
  25. #define LIB_H_INCLUDED
  26. double get(double a, double b);
  27. int getSize();
  28. double * getArray(int n);
  29. double * initArray(double * a,double * b,int n);
  30. double get(double a, double b);
  31.  
  32. int getSize(){
  33.     int n;
  34.     printf("Введите размер массива:\n");
  35.     scanf("%d",&n);
  36.     return n;
  37. }
  38.  
  39. double * getArray(int n){
  40.     printf("Введите %d чисел:\n",n);
  41.     double *a;
  42.     a=(double*)malloc(n * sizeof(double));
  43.     for(double * i=a;i!=&a[n];i++)scanf("%lf",i);
  44.     return a;
  45. }
  46.  
  47. double * initArray(double * a,double * b,int n){
  48.     double *c=(double*)malloc(n*sizeof(double));
  49.     for(double *i=a,*j=b,*k=c;i!=&a[n];i++,j++,k++){
  50.         *k=get(*i,*j);
  51.     }
  52.     return c;
  53. }
  54.  
  55. double get(double a, double b){
  56.     if(a>0 && b<0)return a;
  57.     if(a<0 && b>0)return b;
  58.     return 0;
  59. }
  60.  
  61. #endif // LIB_H_INCLUDED
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement