473,396 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

TO print sum of series of numbers

I want to write a c program to print sum of series of numbers. Can anyone please send me the program code.
Sep 27 '09 #1
2 3594
newb16
687 512MB
If I send you the code, how would you be able to write it on your own when you already have it?
Sep 27 '09 #2
whodgson
542 512MB
One way to do this is to use a while loop and load an int or double type vector with the numbers you want to sum. Then use a for loop to to get each number from the vector and make a running sum.
e.g. this snippet explains.
Expand|Select|Wrap|Line Numbers
  1. vector<int>v;   //declare vector
  2. while(cin>>n)             //press any key which is not an int to cease input (say ~)
  3.    v.push_back(n);      //load vector elements
  4. for(int i=0;i<v.size();++i)
  5.    sum+=v[i];             //develop sum
  6. cout<<"sum of numbers"<<sum<<endl;
Sep 30 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Christopher M. Pieper | last post by:
I want to generate a resultset that is just a series of numbers in ascending order or perhaps a series of dates.. What I mean is, is there a way to generate a temporary table of dates given an...
4
by: YS Sze | last post by:
If you know the exact longitude and latitude for a specific location, would anyone think it'd make any sense to find out if this set of location numbers is really part of the Fibonacci series or...
47
by: shan | last post by:
Hi to every body, I am a begginer in C.can anybody give the complete code for fibinocci series (0 1 1 2 3 5 8 ...)an input is get from user to calculate how many numbers to be printed.I am using...
2
by: EManning | last post by:
Using A2K. I have a series of unbound textboxes on a report. I made a duplicate of these textboxes (Edit...Duplicate) to make a new series, then put this new series on another report. But I...
4
by: geoffp | last post by:
I need to generate reproducible random number series. I've done the obvious - use mt_srand with the same seed. This supposedly will create the same series every time. Is this true? Its not...
1
by: kelsloris | last post by:
I'm printing a combination of text and graphics to the printer. When I print to my HP Laserjet, everything comes out ok. If I print to my Canon Inkjet photo printer (i475D series), all I get is...
0
by: developer200701 | last post by:
The following code (which is distilled down from a larger application) worked for several years previously. Now, the instant you click on the print icon within the print preview window the...
8
by: python101 | last post by:
I would like to calculate the value of this series (for limited number of n) s=2(1/1 - 1/3 + 1/5 -1/7 + 1/9 - 1/11+...) I tried for-lop but it did not work well since the sign alternative (+, - ,...
8
by: andrew.smith.cpp | last post by:
Hello how Can i get this kind of output? 1,2,3,5,8,13,21 i try it with loop but could print it. Thanks
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.