Solved

Problem with a program function in C

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Retrun object in plist format 5 55
Problem with MFCApp 78 349
How to get time_t value that is a week old 6 164
Arduino EDI - Programming language 3 80
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 opening and reading files 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.

863 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

16 Experts available now in Live!

Get 1:1 Help Now