Skip to content

Instantly share code, notes, and snippets.

@Evshved
Last active August 29, 2015 14:08
Show Gist options
  • Select an option

  • Save Evshved/301f14e89d0bda98d805 to your computer and use it in GitHub Desktop.

Select an option

Save Evshved/301f14e89d0bda98d805 to your computer and use it in GitHub Desktop.
#include <vcl.h> // Visual Component Library
#include <stdio.h> // standard input/output header
#include <conio.h> //console input-output
#include <math.h> //mathematics
#include <stdlib.h> //standard library
#pragma hdrstop
#pragma argsused
//---------------------------------------------------------------------------
int main(int argc, char* argv[])
{
int *a,n,i,k,sum,count,sign;
randomize();
do {
clrscr();
printf("Quest : ''Sum numbers after first negative number''\n");
do {
printf("Please type '1' for random, other digits -your's array\n");
fflush(stdin);
}while(scanf("%d",&sign) !=1);
do {
printf("Enter the number of array elements\n");
fflush(stdin);
}while(scanf("%d",&n) !=1);
a=new int[n];
if (sign==1){
puts("New array A...");
for (i=0;i<n;i++){
a[i]=random(21)-10;
printf("%d ",a[i]);
}
}
else {
i=0;
do {
do {
printf("Please enter a[%d] ",i);
fflush(stdin);
}while(scanf("%d",&a[i]) !=1);
i++;
} while(i!=n);
printf("Your's array...\n");
for (k=0;k<i;k++){
printf("[%d] ",a[k]);
}
}
count=-3;
for (i=0;i<n;i++){
if ((a[i]<0) && (count<0)){
count=i+1;
break;
}
}
if (count<0) {
puts ("\nNo negative number.");
continue;
}
if (count==n){
printf ("\nFirst negative number - a[%d]\n",count-1);
continue;
}
if ((count>=0) && (count!=n))
{
sum=0;
for (i=count;i<n;i++) sum+=a[i];
printf("\nSUM=%d\n",sum);
}
delete []a;
puts("Exit - 1, Restart - any key");
} while ( getch() != '1');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment