473,394 Members | 1,797 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,394 software developers and data experts.

Please answer this

i want to add 2 four digit numbers using modulo 10 addition. One of the number will going to get using Random function(only 4 digits). I want to know how to get the random number and perform Modulo 10 Addition.

1234
6789 (this number is created by random function)
--------------
7913
------------
Sep 8 '06 #1
3 1737
risby
30
i want to add 2 four digit numbers using modulo 10 addition. One of the number will going to get using Random function(only 4 digits). I want to know how to get the random number and perform Modulo 10 Addition.

1234
6789 (this number is created by random function)
--------------
7913
------------
the c library includes functions rand and srand. use srand to set the seed of a sequence of psuedo-random numbers and rand to get the next value from the sequence.

modulo 10 arithmetic means that when you add two digits if the result is greater than 9 subtract 10. From your example above: 4 + 9 = 3 and 8 + 3 = 1.
Sep 8 '06 #2
Banfa
9,065 Expert Mod 8TB
You can use the % operator to help you with modulo arithmatic, it is the modulo operator, it gives the remainder when 1 integer is divided by another

4 + 9 = 13

(4 + 9) % 10 = 3
Sep 8 '06 #3
D_C
293 100+
Addition/subtraction without carry is the same thing as XOR. However, since XOR and computer arithmetic is in binary, it doesn't quite churn out the same result for decimal. However, if you used a base like 8 or 16 (or any power of two) it should come out correct.
Sep 11 '06 #4

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

Similar topics

1
by: Numberwhun | last post by:
Hello everyone! I am trying to learn java and have run into kind of a snag. Here is the code that I have so far: ------ <begin_code> ---------- import javax.swing.*; import...
2
by: A. Wiebenga | last post by:
Hi all! I am currently involved in a project in which I am supposed to write a XSLT-transformation sheet for some XML data. I will outline the situation first: I've got one large XML file...
18
by: free2cric | last post by:
Hi, I attanded an interview on C++ Question asked were and my answers to them.. 1. In a CPP program what does memory leak occure? -- i said.. In a constructor , the pointer variables were...
14
by: HP | last post by:
Hi All i have confussion regarding given problem please help me out 4. What happens with the following program: void main(){ myclass* pmc = new myclass; pmc = 0; delete pmc;}
36
by: amanayin | last post by:
As i am not at school for c programming can you please tell me if there is anything bad about this program /* EX4-9.C FUNCTION TO CALL OTHER FUNCTIONS */ #include<stdio.h> float div(float...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
13
by: sd00 | last post by:
Hi all, can someone give me some coding help with a problem that *should* be really simple, yet I'm struggling with. I need the difference between 2 times (Target / Actual) However, these times...
2
by: Tyla | last post by:
I have been teaching myself javascript and i am having a huge problem with this form. All it has to do is check that every field has something in it and then post, but as soon as it gets to the...
1
PEB
by: PEB | last post by:
POSTING GUIDELINES Please follow these guidelines when posting questions Post your question in a relevant forum Do NOT PM questions to individual experts - This is not fair on them and...
7
by: 511475 | last post by:
What is the best checker to use to find these probles with, besides an experienced set of eyes? This probram is to grade the response to input by user. Grades his marks. Thanks <?xml...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.