473,473 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problem with displaying zero in a matrix

7 New Member
Hi,
I have created a program that multiply matrices, but the problem has to do with not showing 0, instead showing 1.795e-09 or some other smaller numbers.
One of the matrices I get for example :
Matrix=[1.795e-09,-1,0,-2.962e-10,
1,1.795e-09,8.034e-36,0.1]
I don't want the elements to be integers, at least floats (I have defined the contents to be double). But, how do you get rid of this problem?

thanks
Nov 15 '07 #1
6 1463
gpraghuram
1,275 Recognized Expert Top Contributor
Hi,
I have created a program that multiply matrices, but the problem has to do with not showing 0, instead showing 1.795e-09 or some other smaller numbers.
One of the matrices I get for example :
Matrix=[1.795e-09,-1,0,-2.962e-10,
1,1.795e-09,8.034e-36,0.1]
I don't want the elements to be integers, at least floats (I have defined the contents to be double). But, how do you get rid of this problem?

thanks
I think u are using a matrix which stored double values and using a wrong format specifier(like %f instead of %lf ) to print it. I am not sure about the format specifier for double.

Raghuram
Nov 15 '07 #2
crazygrey
7 New Member
I haven't specified anything for the double format. If you check the format specifiers here %f is specified for float data.
Nov 15 '07 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
I haven't specified anything for the double format. If you check the format specifiers here %f is specified for float data.
The format specifier %f is for a float and %lf is for a double.

You may bee dealing with uninitialized variables. I can't see your code so I am just guessing here.
Nov 15 '07 #4
crazygrey
7 New Member
The format specifier %f is for a float and %lf is for a double.

You may bee dealing with uninitialized variables. I can't see your code so I am just guessing here.
The variables are initialized. The elements of the matrix are defined to be "double". As my understanding there are no literals for double number (1.456 for e.g.) but for float (1.456f). Anyways, I tried doing
double sum;
sum=0%lf;
but I ran the code, I got this error (" %lf undeclared identifier ")
Nov 15 '07 #5
weaknessforcats
9,208 Recognized Expert Moderator Expert
Anyways, I tried doing
double sum;
sum=0%lf;
but I ran the code, I got this error (" %lf undeclared identifier ")
The %lf is a format specifier for functions like printf(), scanf(), etc.
Expand|Select|Wrap|Line Numbers
  1. printf("%lf", sum);
  2.  
Nov 16 '07 #6
crazygrey
7 New Member
The %lf is a format specifier for functions like printf(), scanf(), etc.
Expand|Select|Wrap|Line Numbers
  1. printf("%lf", sum);
  2.  
Brilliant, thanks very much. This definitely solved my problem.
Nov 16 '07 #7

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

Similar topics

2
by: Tino | last post by:
In the snippet below, if the problem line is present, my program crashes during the Matrix operator*(const Matrix&) call. Would someone point out to me why I'm having this problem? Regards,...
4
by: Leslaw Bieniasz | last post by:
Cracow, 20.09.2004 Hello, I need to implement a library containing a hierarchy of classes together with some binary operations on objects. To fix attention, let me assume that it is a...
3
by: Tony Johansson | last post by:
Hello Experts!! I have two small classes called Intvektor and Matris shown below and a main. Class Intvektor will create a one dimension array of integer by allocate memory dynamically as you...
2
by: Pete Davis | last post by:
I've got an app that plays video using the ActiveMovie COM stuff. I'm using the FilgraphManagerClass to play the movie and I'm trying to get an image from the currently displayed scene. The...
6
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length...
1
by: Marc Webel | last post by:
Hi i have a small(?) problem and i hope you can help me. i have a basis class "Matrix" that contains a 2d matrix. you can fill the matrix by a method called "setData(int x,int y)". two child...
23
by: Babak | last post by:
Hi Everyone, I've written a standard C code for a simple finite element analysis in MSVC++ . When I save the file as a cpp file, it compiles and runs perfectly, but when I save it as a c file,...
5
by: arr1 | last post by:
Hello, I have created an matrix oracle report. In which i'm getting blank spaces for the fields where i dont have data. can i replace these with a zero. I tried the method provided on the...
1
by: afreen | last post by:
this is a complete c# program for a matrix to be solved for echolon form.it is valid only when I enter a non zero number to A11 ( the first element of matrix)....i want such program that when i...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.