Help with array

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
  #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;
} 

> deduce the initial indexes of all (positive and negative) number sequences
don't understand, provide some examples


your code's indentation is confusing, here's with proper indentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#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) //<-- the conditional is useless
			if(!nn)
				; //<--- no operation
		i_pradinis = i; //this always execute
		nn = 1;
	}
	for(nn = i = 0; i < 100; i++) {
		if(MASYVAS[i] > 0) //<--- same as before
			if(nn)
				;
		for(j = i_pradinis; j - 1; j++) //missing statement, also ¿does it end?
	}

	/* 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
[] (empty array)
[0], [1], [-1]
[1, 2], [-1, 1], [0, 0]
[1, -1, 1, -1, 1, -1]
[1, 2, -3, -4, -5, 6, 7]

¿what should be the output of your program for those inputs?
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)
Now i have example , but it's just for positive sequences indexes , how to get both positive and negative numbers sequences indexes?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// 7 darbas
// 5 variantas
// pvz 

#include <stdio.h>
#include <stdlib.h>
int MASYVAS[100];

int main (void) {
	int i,j;
	int indeksas;
	int nn;
	int i_pradinis;
	
	rand(); /* rand inicializacija */
 /* masyvo užpildymas atsitiktiniais skaiciais */
 for (i=0; i<100; MASYVAS[i++]=rand()%100-50 );
 /* pirminio masyvo išvedimas */
 printf("Pirminis masyvas:\n");
 for (i=0; i<100; printf("%3d ",MASYVAS[i++])); 
 // naujo masyvo paieska
 putchar('\n');
 putchar('\n'); 
 j=0;
 int k;
 
 i_pradinis=0;
 printf("Teigiamu masyvu, ilgesniu nei 5 skaiciai, pirminiai indeksai\n");
 for (nn=i=0; i<100; i++) {
	 if (MASYVAS[i]>=0)  {
		 
		 nn++;
		 i_pradinis=i-1;

		 if(nn==2){
			 
			 printf("%3d ",i_pradinis);
			 j++;
			 
		 }
	 }
			 
		
	
	 		 
	 else if (MASYVAS[i]<0){
		 nn=0;
 }		 
	 }
		 
		

	
 printf("\n"); 
 char ch;
 while ((ch=getchar()) != 'T')
putchar (ch);
return 0; 
}
		  
			 
		 
		 
		 
Last edited on
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)


now, ¿can you explain how that last program work?
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
Topic archived. No new replies allowed.