Solved

Problem with a program function in C

Posted on 1998-11-22
2
240 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
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 recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

830 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