15,918,343 members

See more:

Hii,

Here i have facing such kind of in my following code.

**What I have tried:**

Error : subscripted value is neither array nor pointer nor vector.

in bold area.

Here i have facing such kind of in my following code.

<pre> #include <stdio.h> #include <stdbool.h> #include <math.h> #include<stdio.h> int main() { bool True = 1; //for sqr wave conversion bool False = 0 ; int n[10],m[10] ; // n is an array of 1000 integers int i1, i2,x,y ; int r,xx[10],xy[10],yy[10],nr=0,dr_1=0,dr_2=0,dr_3=0,dr=0; int sum_y=0,sum_yy=0,sum_xy=0,sum_x=0,sum_xx=0; int i, h=10; /* initialize elements1 of array n to 0 */ for (i1=0;i1<10;i1++) { n[i1] = i1+1; // set an element at location i to 1000 } /* initialize elements2 of array n to 0 */ for (i2=0; i2<10; i2++) { m[i2] = i2+5; } //output of each array element for (x=0 ;x<10; x++) { if (x%2 == 0) //sqr wave coversion { True = 1 ; } else { False = 0 ; } printf("element1 [%d] = %d\n" , x, n[x]); } for (y=0 ; y<10; y++) { if (y%2 == 0) //sqr wave { False = 0; } else { True = 1; } printf("element2 [%d] = %d\n" , y, m[y]); } for(i=0; i<h; i++) {xx[i]= x[i]*x[i]; // coorelation logic yy[i]= y[i]*y[i];} for(i=0;i<h;i++) {sum_x+=x[i]; sum_y+=y[i]; sum_xx+= xx[i]; sum_yy+=yy[i]; sum_xy+= x[i]*y[i];} hr=(h*sum_xy)-(sum_x*sum_y); int sum_x2=sum_x*sum_x; int sum_y2=sum_y*sum_y; dr_1=(h*sum_xx)-sum_x2; dr_2=(h*sum_yy)-sum_y2; dr_3=dr_1*dr_2; dr=sqrt(dr_3); r=(hr/dr); printf("Total Numbers:%d\nCorrelation Coefficient:%.2f",h,r); return 0; }

Error : subscripted value is neither array nor pointer nor vector.

in bold area.

Look at your code:

You can't declare an integer and treat it as an array - equally, you can't declare an array and treat it as an integer!

I suspect that your

Do yourself a couple of favours: pick an indentation style, and stick to it. Then indent your code uniformly, so it's obvious what is what - at the moment that's all over the place, and it's much harder to read as a result. And stop using single character variable names: it means that nobody - not even you, obviously - is sure what variable does what. And that makes your code really difficult to work out. Use meaningful names and your code starts to self document, and that means it's much easier to read and a lot harder to use the wrong variables as you have. That's why your code is "student grade"! :laugh:

`int i1, i2,x,y ;`

for (x=0 ;x<10; x++) { ... } for (y=0 ; y<10; y++) { ... }

for(i=0; i<h; i++) { xx[i]= x[i]*x[i]; // coorelation logic yy[i]= y[i]*y[i]; } for(i=0;i<h;i++) { sum_x+=x[i]; sum_y+=y[i]; sum_xx+= xx[i]; sum_yy+=yy[i]; sum_xy+= x[i]*y[i]; }

You can't declare an integer and treat it as an array - equally, you can't declare an array and treat it as an integer!

I suspect that your

`x`

and `y`

should be `m`

and `n`

, but your code is too "student grade" for me to work it out, and I have no idea what you are actually trying to get it to do.Do yourself a couple of favours: pick an indentation style, and stick to it. Then indent your code uniformly, so it's obvious what is what - at the moment that's all over the place, and it's much harder to read as a result. And stop using single character variable names: it means that nobody - not even you, obviously - is sure what variable does what. And that makes your code really difficult to work out. Use meaningful names and your code starts to self document, and that means it's much easier to read and a lot harder to use the wrong variables as you have. That's why your code is "student grade"! :laugh:

Permalink

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject,
20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8
+1 (416) 849-8900