gashink_t

1 задание (ln(1+x)))

Feb 9th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #define N 50
  5. int* newmass(int n) {
  6.     int i;
  7.     int *A=(int*)malloc(n*sizeof(int));
  8.     for (i=0;i<n;i++)
  9.         A[i]=rand()%10-5;
  10.     return A;
  11. }
  12. int vivod(int A[N], int n) {
  13.     int i;
  14.     for (i=0; i<n; i++)
  15.         printf("%4d", A[i]);
  16.     printf("\n");
  17.     return 0;
  18. }
  19. int suma(int A[N], int i, int n) {
  20.     if (A[i]<0)
  21.         return A[i]+suma(A,i+2,n);
  22.     else return suma(A,i+2,n);
  23.     else return 0;
  24. }
  25. int main() {
  26.     int n;
  27.     printf("vvedite razmer massiva n: \n");
  28.     scanf("%d", &n);
  29.     int* a=newmass(n);
  30.     printf("vash massiv: \n");
  31.     vivod(a,n);
  32.     printf("suma = %d\n", suma(a,1,n));
  33.     return 0;
  34. }
Add Comment
Please, Sign In to add comment