473,398 Members | 2,525 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,398 software developers and data experts.

How to get sum of every 3rd number

143 100+
How do I structure a while loop that will add the sum of every 3rd digit in an input file.

I'm stuck!!
Oct 9 '06 #1
1 2624
D_C
293 100+
Expand|Select|Wrap|Line Numbers
  1. int dig = 0;
  2. int sum = 0;
  3. char ch;
  4. while(not EOF)
  5. {
  6.   ch = next character
  7.   if(ch is digit)
  8.     dig++;
  9.   if(dig == 3)
  10.   {
  11.     dig = 0;
  12.     sum += (ch - '0');
  13.   }
  14. }
Oct 10 '06 #2

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

Similar topics

35
by: Mokkapati | last post by:
Hi all, I have data that has to be written successively, that is, this data is updated at every step in the loop and I need to print this in a file. So, I need something like, for every step,...
18
by: Jen | last post by:
Is it possible (how) to display a new record every week (or day) from a recordset?
2
by: David | last post by:
Hi, Could PHP be used to take a txt file (or set of txt files) and add a string of characters every X number of words or characters? Say a txt file with 50,000 characters/5,000 words how would...
1
by: vijay.db | last post by:
Hi Team, Very serious problem with my DB2 V8.1 Fixpack 6 running in AIX 5.1 machine. Every one hour my DB2 instance processes are killed and it's going down. Several trap files are generated in...
1
by: bill.dourado | last post by:
Using DB2:- Product identifier SQL08027 Level identifier 03080106 Level DB2 v8.1.14.292 Build level s061108 PTF ...
4
by: jonceramic | last post by:
Hi guys, I have a user who wants to have a report that shows only the 10th value recorded by his equipment. (i.e. His equipment records temperature every 30 seconds, but he only wants to view...
0
by: summiyashaheen | last post by:
i have multiple groups on a report and i want to have record number for every group. the record number must restart from 1 for every group. additionally, there is column of marks. i want to rate the...
0
by: JuAn2226 | last post by:
hi this my code Private Sub Form_Load() car_count = 0 Cumulative_Speed = 0 End Sub Private Sub Timer1_Timer() Dim tmpNumber As Integer
2
by: babe20042004 | last post by:
How would I go about finding every nth number in an array set? For example if i had a set containing the numbers 1-100 int each cell, how would I go about finding every 3rd number in the set.
1
by: spynx | last post by:
import javax.swing.JOptionPane; import java.io.*; import java.util.Arrays; public class election5 { public static void main( String args ) {
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.