GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 21-May-2007, 13:24
logieen logieen is offline
New Member
 
Join Date: May 2007
Posts: 4
logieen is on a distinguished road

I have a problem to solve summation in c++


Hi , Every one I have a problem to solve this summation in c++ ;
1/3 + 3/5 +5/7 .......

this the program I wrote
CPP / C++ / C Code:
#include <stdio.h>
#include <iostream.h>
#include <conio.h>
#include <math.h>

main()
{
  int i=3.0,j=1.0,d,N;
  cout<<"Enter Number ";
  cin>>N;
  float sum;
     while(j<=N && i<=N){
  for (d=1; d <= N; d++){
    sum += j/i;
    printf("%d:  %2.2f\n", d, sum);
    i+=2;
    j+=2;
  }}
  getch();
}

and this is the run
Code:
1: 0.00 2: 0.00 3: 0.00 4: 0.00
is there a problem in my program >


thanks
Last edited by admin II : 21-May-2007 at 14:50. Reason: Please surround your CPP code with [CPP] ... [/CPP]
  #2  
Old 21-May-2007, 13:47
dlp dlp is offline
Member
 
Join Date: May 2006
Posts: 157
dlp has a spectacular aura about

Re: I have a problem to solve summation in c++


What should sum equal in the beginning?
  #3  
Old 22-May-2007, 04:59
Peter_APIIT Peter_APIIT is offline
Regular Member
 
Join Date: May 2007
Location: Malaysia
Posts: 545
Peter_APIIT can only hope to improve
Thumbs up

Re: I have a problem to solve summation in c++


The computer cannot view the 1/3 as something because the computer will divide and sum it.

I don't know whether i correct or not.
  #4  
Old 22-May-2007, 05:02
Peter_APIIT Peter_APIIT is offline
Regular Member
 
Join Date: May 2007
Location: Malaysia
Posts: 545
Peter_APIIT can only hope to improve
Thumbs up

Re: I have a problem to solve summation in c++


You also never initialized the sum to zero.


No responsibility to be taken for any advices.
  #5  
Old 22-May-2007, 08:25
logieen logieen is offline
New Member
 
Join Date: May 2007
Posts: 4
logieen is on a distinguished road

Re: I have a problem to solve summation in c++


Thanks it finally work.
 
 

Recent GIDBlogAccepted for Ph.D. program by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with using classes as Parameters and Return Types wmbest2 C++ Forum 3 13-Mar-2007 21:08
Hitting a logic problem I can't solve Elsydeon C++ Forum 3 09-Oct-2005 22:29
Graphic problem in Unreal Tournament 2004 zerox Computer Software Forum - Games 10 09-Oct-2005 13:31
a significant problem after installing Xp mohammad Computer Software Forum - Windows 10 09-Aug-2005 08:03
Please help to solve me a problem with multiline texrbox and checkbox mithila MS Visual C++ / MFC Forum 0 08-Sep-2004 23:08

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 20:03.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.