C# .NET - find modules in C# for my situation

Asked By muthuraman alexander on 30-Nov-11 07:28 AM
hi all ,

i want to find the modulo of the give value for the following scenario

i have the following case
int total =2500;
int [] strValue=[400,300,200,100];
2500 % 400 =6  remainder=100
100 % 300 =0 remainder =100
100 % 200=0 remainder=100
100 % 100 =1 remainder=0

returns array [6,0,0,1]

i cant get the code logic for this calculation

please advice me

thanks in advance
MUTHU





Chintan Vaghela replied to muthuraman alexander on 30-Nov-11 08:07 AM

Hello

 

Try this way

 

int total = 2500;

        int[] strValue = new int[] { 400, 300, 200, 100 };

        int[] finalResult = new int[strValue.Length];

      

        for (int i = 0; i < strValue.Length; i++)

        {

          int reminder = total / Convert.ToInt32(strValue[i]);

          int mod = total % Convert.ToInt32(strValue[i]);

          finalResult[i] = reminder;

          total = mod;

 

        }