Advertisement
KvArt

Razvrstavanje na pozotivne i negativne elemente niza

Aug 14th, 2022
960
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.57 KB | None | 0 0
  1. #include <stdio.h>
  2. #define N 100
  3.  
  4. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  5.  
  6. void main()
  7. {
  8.     while(1)
  9.         {
  10.             int i;
  11.             printf("\nn? "); int na; scanf("%d", &na);
  12.             if(na<=0 || na>N) break;
  13.            
  14.             printf("A? "); int a[N]; for (i=0;i<na; scanf("%d", &a[i++]));
  15.             int b[N], c[N], nb=0, nc=0;
  16.             for (i=0; i<na;a[ i]<0 ? (b[nb++]=a[i++]) : (c[nc++]=a[i++]));
  17.            
  18.             printf("B= "); for (i=0; i<nb; printf("%d ", b[i++])); printf("\n");
  19.             printf("C= "); for (i=0; i<nc; printf("%d ", c[i++])); printf("\n");
  20.         }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement