Not Yet Answered # Formatting of number

Discussion Starter K.Vanlalliana selvaganapathy 31 Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...

0

Hi, Mr. debasisdas,

thank you very much for your response. I wamt to tell you that Ican round the number only to the nearest number by writing like this:

C=AXB

D=round(Val(C)+0.001)

But I do not know how to write the code so that the number should be rounded to the nearest integer and nearest number which is divisible by a given number (Say 10)

eg. If a number to be rounded up is 785 it will be rounded upto 780, 788 will be rounded upto 790

I also want to know the code so as to be able to check whether a given number is divisible by some given number (Say 7) or not.

KVL Liana

0

Hi,

It is simple logic.

```
> First Add half of that number (788 + (10/2) = 793)
> Take Modulus (793 MOD 10 = 3), You get the remainder (3)
> Subtract the Remainder from that Number (793 - 3)
```

OR

```
> First Add half of that number (788 + (10/2) = 793)
> Divide the Number (793 by 10 ), you get the quotient (79.3)
> Split the Integer part only (Int(79.3) = 79)
> Again multiply by that Number (79 * 10 = 790)
```

OR

```
> Take Modulus (788 MOD 10 = 8), You get the remainder (8)
> If Remainder > 5 Then
> .....
> Else
> ...
```

In this way you can round of the number.

Also you can customize this for your need.

I hope this is helpful for you

This article has been dead for over six months. Start a new discussion instead.

Recommended Articles

Hi. so this is actually a continuation from another question of mineHere but i was advised to start a new thread as the original question was already answered.

This is the result of previous question answered :

code for the listbox - datagridview interaction

At the top of the code ...

the function that I created to find the ...