04.01.2007, 14:25
общий
это ответ
Здравствуйте, POSTAL!
Вот еще как вариант.
Удачи
Приложение:
#include <stdio.h>#include <conio.h>#include <stdlib.h>int main(){ char ans; int i; int *array=NULL; /*array pointer to be (we deal with dynamic array)*/ int count=0; /*array size*/ int negcount=0; /*total number of negative values*/ int negsum=0; /*total sum of negative values*/ puts("wanna enter values by hand? (y/n)"); scanf("%c",&ans), fflush(stdin); if(ans==‘y‘||ans==‘Y‘) { do { ++count; array = (int*)realloc(array,count*sizeof(int)); printf("enter %d element: ",count); scanf("%d",array+count-1), fflush(stdin); printf("more? (y/n)"); scanf("%c",&ans); } while(ans==‘y‘||ans==‘Y‘); } else { puts("what size?"); scanf("%d",&count), fflush(stdin); array = (int*)malloc(count); randomize(); for(i=0; i<count; ++i) array[i]=random(500)-250; } puts("initial array:"); for(i=0; i<count; ++i) { printf("%3d ",array[i]); if(array[i]<0) { ++negcount; negsum+=array[i]; } } printf("\nnegative values count = %d\n",negcount); printf("sum of negative values = %d\n",negsum); if(array) free(array); getch(); return 0;}