Solved

Problem with a program function in C

Posted on 1998-11-22
2
241 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
Suggested Courses

738 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