Integer/Integer division

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?
kitesAsked:
Who is Participating?
 
for_yanCommented:
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
 
for_yanCommented:

float flnum = (float)v1/(float)v2;
0
 
for_yanCommented:
Of cousrse teh same thing with double:

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

0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
kitesAuthor Commented:
Thanks!
How do we allocate memory for int[3][5] in C?
Also how do we time any C program?
0
 
for_yanCommented:

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
 
kitesAuthor Commented:
Dnt we use malloc?
0
 
for_yanCommented:
0
 
for_yanCommented:

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
 
kitesAuthor Commented:
Thanks!!!
0
 
for_yanCommented:
You are always welcome.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.