Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Integer/Integer division

Posted on 2011-10-11
10
Medium Priority
?
378 Views
Last Modified: 2013-11-23
I have two int variables :
int v1=43;
int v2=9;
I want v1/v2 to be of float or double value. How can this be done?
0
Comment
Question by:kites
  • 7
  • 3
10 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 36953629

float flnum = (float)v1/(float)v2;
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36953636
Of cousrse teh same thing with double:

double dnum = (double)v1/(double)v2;

0
 
LVL 47

Accepted Solution

by:
for_yan earned 500 total points
ID: 36953640
This is how it works:
       int v1=43;
int v2=9;

        float flnum = (float)v1/(float)v2;

        double dnum10 = (double)v1/(double)v2;

        System.out.println("flnum: " + flnum);

          System.out.println("dnum10: " + dnum10);

Open in new window


Output:

flnum: 4.7777777
dnum10: 4.777777777777778

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:kites
ID: 36953647
Thanks!
How do we allocate memory for int[3][5] in C?
Also how do we time any C program?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36953700

Are you taliking about C or about Java?

In C you can allocate memory for an array  of known size using statements such as:

char name[32];
int nums[100];
double coords[60][60]
char names[10][20][64];
double space[32][32][32][32];

read here about timing in C:
http://www.phy.duke.edu/~marts/comp/ins.pdf

0
 

Author Comment

by:kites
ID: 36953741
Dnt we use malloc?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36953749
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36953761

This is if you want to allocate memory dynamically to more than one-dimensional array:
http://c-faq.com/~scs/cclass/int/sx9b.html
0
 

Author Comment

by:kites
ID: 36953772
Thanks!!!
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36953776
You are always welcome.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month15 days, 7 hours left to enroll

575 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question