Solved

Problem with a program function in C

Posted on 1998-11-22
2
236 Views
Last Modified: 2010-04-15
hi there. the progrma consists in using the simpson 3/8 rule to
>calculate the integral of the following function: e^sinx from 1 to 3
>the rule for sypmpson is the following:
>
>I=(3/8)*(f1+3f2+3f3+2f4+3f5+3f6+2f7.....+3f20+3f21+f22)
>
> HERE I INCLUDE THE PROGRAM I MADE . IT RUNS BUT DOESNT GIVE THE
>RESULT TO THE INTEGRAL. IT SAYS IT IS zERO WHICH IS NOT.
>rules of the game:
>n=21, lower=1, upper=3, h= upper-lower/n, and I has to be a function.
>
>i will appreciate any help you can give me. this is for this monday.
>thanx,
>pedro
>
>
>#include<stdio.h>
>#include<math.h>
>void main (void)
>{
> float n,upper,lower,counter,counter2;
> float x1,acc,suma,f1,f2,f3,f4,Symp;
> float I(float,float);
> float h;
>
> acc=0;
> x1=1;
> counter=0;
> counter2=0;
> n=21.0000000000;
> lower=1.0000000000;
> upper=3.00000000;
> h=(upper-lower)/n;
>
> while(counter2<7)
> {
>  f1=exp(sin(x1+(counter*h)));
>  counter++;
>  f2=exp(sin(x1+(counter*h)));
>  counter++;
>  f3=exp(sin(x1+(counter*h)));
>  counter++;
>  f4=exp(sin(x1+(counter*h)));
>  suma=(f1+(3*f2)+(3*f3)+f4);
>  acc+=suma;
>  counter2=counter2+1;
> }
>
>Symp=I(h,acc);
>printf("sympson=%f",Symp);
>}
>
> float I(float w, float z)
>{
> float resultado;
> resultado=(3/8)*w*z;
> return (resultado);
>}
>
0
Comment
Question by:milalic
2 Comments
 

Accepted Solution

by:
visualc earned 200 total points
ID: 1254560
Hi!
When resultado is calculating, 3/8 is casting to integer, becouse 3 and 8 are implicite integers.
So you can force a cast to float:

float I(float w, float z)
{
 float resultado;
 resultado=((float)3/8)*w*z;
 return (resultado);
}
It,s works...


0
 

Author Comment

by:milalic
ID: 1254561
thanx for your help, wherecan i get a good source of c knowledge?
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now