Advertisement
derazanother

array 2.1

Dec 26th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.86 KB | None | 0 0
  1. /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*-  */
  2. /*
  3.  * main.c
  4.  * Copyright (C) 2017 sut <sut@sut-mde>
  5.  *
  6.  */
  7.  
  8. #include <stdio.h>
  9. int x=0;
  10. int main()
  11. {
  12.     void countNegtive(int [],int );
  13.     void sumPositive(int [], int);
  14.     int n[]={2,3,-1,0,-5,9,30,-45,-3};
  15.    
  16.         countNegtive(n,9);
  17.         sumPositive(n,9);
  18.     return (0);
  19. }
  20.  
  21. void countNegtive(int x[],int y){
  22.     int i,z,c=0;
  23.     printf("From function countNegtive\n");
  24.         printf("Output: ");
  25.     for(i=0;i<y;i++){
  26.     if(x[i]<0){
  27.             printf("%d ",x[i]);
  28.         c++;
  29.         }
  30.        
  31.         }
  32.        
  33.         printf("\nCount = %d ",c);
  34.         return;
  35.     }
  36. void sumPositive(int x[], int y){
  37. int i,z,sum=0;
  38.         printf("\n");
  39.         printf("\nFrom function sumPositive.\n");
  40.         printf("Output: ");
  41.     for(i=0;i<y;i++){
  42.     if(x[i]>0){
  43.             printf("%d ",x[i]);
  44.    
  45.         sum += x[i];
  46.         }
  47.        
  48.         }
  49.        
  50.         printf("\nSum = %d",sum);
  51.         return;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement