Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // main.c
- #include <stdio.h>
- #include <stdlib.h>
- #include <malloc.h>
- #include "lib.h"
- int main()
- {
- int n=getSize();
- double *a,*b,*c,*d,*e;
- a=getArray(n);
- b=getArray(n);
- c=getArray(n);
- d=initArray(a,b,n);
- e=initArray(b,c,n);
- printf("1 последовательность:\n");
- for(double *i=d;i!=&d[n];i++)printf("%lf ",*i);
- printf("\n2 последовательность:\n");
- for(double *i=e;i!=&e[n];i++)printf("%lf ",*i);
- return 0;
- }
- // lib.h
- #ifndef LIB_H_INCLUDED
- #define LIB_H_INCLUDED
- double get(double a, double b);
- int getSize();
- double * getArray(int n);
- double * initArray(double * a,double * b,int n);
- double get(double a, double b);
- int getSize(){
- int n;
- printf("Введите размер массива:\n");
- scanf("%d",&n);
- return n;
- }
- double * getArray(int n){
- printf("Введите %d чисел:\n",n);
- double *a;
- a=(double*)malloc(n * sizeof(double));
- for(double * i=a;i!=&a[n];i++)scanf("%lf",i);
- return a;
- }
- double * initArray(double * a,double * b,int n){
- double *c=(double*)malloc(n*sizeof(double));
- for(double *i=a,*j=b,*k=c;i!=&a[n];i++,j++,k++){
- *k=get(*i,*j);
- }
- return c;
- }
- double get(double a, double b){
- if(a>0 && b<0)return a;
- if(a<0 && b>0)return b;
- return 0;
- }
- #endif // LIB_H_INCLUDED
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement