2 Replies - 152 Views - Last Post: 17 February 2019 - 12:35 AM Rate Topic: -----

#1 narcos   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 17-February 19

array subscript is not an integer?

Posted 17 February 2019 - 12:10 AM

#include<stdio.h>
#include<conio.h>
#include<math.h>
#define F(x) (sin(x)-log(x)+exp(x))
void main()
{
    float a,b,h,n,x[100],y[100],s1=0,s2=0,s3=0,I=0;
    int i;
    printf("Simpson's 3/8th Method\n");
    printf("Enter two initial points a and b: ");
    scanf("%f%f",&a,&B)/>/>/>/>/>;
    printf("Enter the no. of intervals: ");
    scanf("%f",&n);
    h=(b-a)/n;
    printf("The height is %.4f\n",h);
    printf("I\tX\tY\n");
    for(i=0;i<=n;i++)
        {
            x[i]=a+h*i;
    y[i]=F(x[i]);
    printf("%d\t%.4f\t %.4f\n",i,x[i],y[i]);
    if(i!=0 && i!=n && i%3==0)
        s2=s2+y[i];
    if(i!=0 && i!=n && i%3!=0)
        s3=s3+y[i];
    }
    s1=y[0]+y[n];
    I=(2*s2+s1+3*s3)*(3*h/8);
    printf("The answer is %.4f.",I);

getch();
 }

This post has been edited by Skydiver: 17 February 2019 - 09:25 AM
Reason for edit:: Added "[CODE]" tags. Please do this yourself in future, as you're asked.


Is This A Good Question/Topic? 0
  • +

Replies To: array subscript is not an integer?

#2 dr3am1nc0d3   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 01-December 18

Re: array subscript is not an integer?

Posted 17 February 2019 - 12:28 AM

Hello, Please fix the format of your code on here to make it more readable using the code tags.

With that said, I noticed an issue with your input:

printf("Enter two initial points a and b: ");
scanf("%f%f",&a,&B)/>;



That &B should be &b.
Was This Post Helpful? 0
  • +
  • -

#3 ndc85430   User is offline

  • I think you'll find it's "Dr"
  • member icon

Reputation: 976
  • Posts: 3,842
  • Joined: 13-June 14

Re: array subscript is not an integer?

Posted 17 February 2019 - 12:35 AM

That's a bug in the forum.

narcos: why do you think it makes sense to use a float (n) as an array index?
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1