Hello i'm new here and i'm beginner in programming. I hope that someone will help me. I need to deduce the initial indexes of all (positive and negative) number sequences. Maybe someone can say my mistakes and say where are problems in the code.
#include <stdio.h>
#include <stdlib.h>
int MASYVAS[100]; /* apdorojamas masyvas */
int main(void) {
int i,j; /* masyvo indeksai */
int ch;
int nn;
int i_pradinis;
rand(); /* rand inicializacija */
/* masyvo uzpildymas atsitiktiniais skaiciais */
for (i=0; i<100; MASYVAS[i++]=rand()%100-50 );
/* pirminio masyvo isvedimas */
printf("Pirminis masyvas:\n");
for (i=0; i<100; printf("%3d ",MASYVAS[i++]));
putchar('\n');
putchar('\n');
for (nn=i=0;i<100; i++) {
if (MASYVAS[i]<0)
if (!nn);
i_pradinis=i; nn=1 ;
}
for (nn=i=0;i<100; i++) {
if (MASYVAS[i]>0)
if (nn);
for (j=i_pradinis; j-1; j++)
}
/* rezultatu isvedimas */
printf("Rezultatas:\n");
putchar('\n');
for (j=0; j<100; printf("%3d ",MASYVAS[j++]));
putchar('\n');
printf("Jeigu norite baigti?");
printf("\n");
printf("Parasykite raide T ir paspauskite Enter klavisa> ");
while ((ch=getchar()) != 'T') /* skirta isejimui is programos */
putchar (ch);
return 0;
}
I don't have example that's why i need help. How i understand that these red numbers are indexes https://imgur.com/a/KX8tFx5
And i need to deduce those indexes wheres is negative or positive number sequences
Sorry i didn't understand you...
Program creates random array and i need to output indexes for number sequences. Number sequence is minimum 2numbers . And where starts sequence i need to get indexes .
where is yellow there is sequence and i need that program will output indexes (red numbers where is the sequence)
I wanted example input/output not an example program.
say that the MASYVAS array is
[1, 0, 1, 0, 1, -1, 0, -1, 0, -1, 1, 0, 1, -1, -2]
¿what would be the output? (also for the other arrays that I've gived you)
https://imgur.com/ClNZ1qF
This is how program works. I'm getting positive sequences initial indexes(yellow numbers) i need to get the same with negative sequences