Forgive me if this is obvious to you. I feel somewhat foolish.
I've scribbled together something that demonstrates my problem. It takes the
product of all integers n squared, where n is 1..10.
-----------------
int main() {
int i;
unsigned long long product = 1;
for (i=1; i<=10; i++) product *= i * i;
printf("%U\n", product);
return 0;
}
-----------------
Would someone care to inform me why the output is 4114677760 and not
13168189440000? sizeof() tells me that I'm getting a 64-bit variable, so
what's going on? Is it an issue with printf()? And how do I resolve this?
Thanks,
dmpk2k 7 5682
dmpk2k <dm******@myahoo.com> wrote: Forgive me if this is obvious to you. I feel somewhat foolish.
I've scribbled together something that demonstrates my problem. It takes the product of all integers n squared, where n is 1..10.
----------------- int main() { int i; unsigned long long product = 1;
for (i=1; i<=10; i++) product *= i * i;
printf("%U\n", product);
printf("%llu\n", product); return 0; } -----------------
- Kevin.
In <9X*******************@news04.bloor.is.net.cable.r ogers.com> Tom St Denis <to********@iahu.ca> writes: dmpk2k wrote: Forgive me if this is obvious to you. I feel somewhat foolish.
I've scribbled together something that demonstrates my problem. It takes the product of all integers n squared, where n is 1..10.
----------------- int main() { int i; unsigned long long product = 1;
for (i=1; i<=10; i++) product *= i * i;
printf("%U\n", product);
%U is wrong for long long
%U is wrong for *anything*, being plain undefined behaviour.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
In <Xn**************************@130.133.1.4> Emmanuel Delahaye <em**********@noos.fr> writes: In 'comp.lang.c', dmpk2k <dm******@Myahoo.com> wrote:
int main() { int i; unsigned long long product = 1;
for (i=1; i<=10; i++) product *= i * i;
printf("%U\n", product);
You want "%llu"
Unless he has a conforming C99 implementation, there is no way of telling
what he really needs.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de Da*****@cern.ch (Dan Pop) wrote in message news:<be**********@sunnews.cern.ch>... In <Xn**************************@130.133.1.4> Emmanuel Delahaye <em**********@noos.fr> writes:
In 'comp.lang.c', dmpk2k <dm******@Myahoo.com> wrote:
int main() { int i; unsigned long long product = 1;
for (i=1; i<=10; i++) product *= i * i;
printf("%U\n", product);
You want "%llu"
Unless he has a conforming C99 implementation, there is no way of telling what he really needs. Dan
MS Visual C++ and Bloodshed C++ have a bug in the ostream program
that limits the output to 32 Bits when using printf. It will only
output the lower half of the long long data. MS has listed a
work-around fix on their website. I have tried to use their
recommendation but it does not work. MS states that the bug will be
fixed in Visual C.net.
Bill Hanna Da*****@cern.ch (Dan Pop) wrote in message news:<be**********@sunnews.cern.ch>... In <Xn**************************@130.133.1.4> Emmanuel Delahaye <em**********@noos.fr> writes:
In 'comp.lang.c', dmpk2k <dm******@Myahoo.com> wrote:
int main() { int i; unsigned long long product = 1;
for (i=1; i<=10; i++) product *= i * i;
printf("%U\n", product);
You want "%llu"
Unless he has a conforming C99 implementation, there is no way of telling what he really needs.
Dan
Use "%I64d" or "%I64u" or "%I64x". This works on Bloodshed C++.
I found the info from an old posting in 2001.
Bill Hanna This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jatinder |
last post by:
I found these questions on a web site and wish to share with all of u
out there,Can SomeOne Solve these Porgramming puzzles.
Programming Puzzles
Some companies certainly ask for these...
|
by: Andy |
last post by:
Hi,
Are 1 through 4 defined behaviors in C?
unsigned short i;
unsigned long li; /* 32-bit wide */
1. i = 65535 + 3;
2. i = 1 - 3;
3. li = (unsigned long)0xFFFFFFFF + 3;
4. li = 1...
|
by: Neil Zanella |
last post by:
Hello,
Often I happen to be dealing with nonnegative integers and since I know I won't
need negative numbers here I declare them as unsigned simply to make the program
somewhat clearer....
|
by: TTroy |
last post by:
Hello, I'm relatively new to C and have gone through more than 4 books
on it. None mentioned anything about integral promotion, arithmetic
conversion, value preserving and unsigned preserving. ...
|
by: Mike Miller |
last post by:
What is the best way to convert a managed unsigned int64 to an
unsigned long? Basically I need to do the following:
System::UInt64 managedInt = 10;
unsigned long unmanagedInt;
unmanagedInt =...
|
by: jeff |
last post by:
unsigned long a = ...;
long b = (long)a;
while a overflows, what is the result of b?
Thank you.
|
by: linq936 |
last post by:
I have some algorithm dealing with unsigned int calculation a lot, I am
trying to add some check for overflow. The initial thinking was very
easy, just do something like this,
int...
|
by: John Harrison |
last post by:
I have a problem. I want to compare an integral value, n, against three
half open ranges as follows
[-A, 0) // range 1
[0, B) // range 2
[B, C} // range 3
Each range corresponds to a...
|
by: Tarique |
last post by:
This program was compiled on MS Visual C++ 08
/*Fibonacci Numbers*/
#include<stdio.h>
#include<limits.h>
void fibonacci(int n)
{
unsigned long long fib0 = 0; /*First Fibonacci Number*/
|
by: Keith Thompson |
last post by:
pereges <Broli00@gmail.comwrites:
These types already have perfectly good names already. Why give them
new ones?
If you must rename them for some reason, use typedefs, not macros.
--
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
| |