Click here to Skip to main content
15,886,799 members
Home / Discussions / C#
   

C#

 
AnswerRe: Program Help Pin
OriginalGriff11-Aug-18 19:31
mveOriginalGriff11-Aug-18 19:31 
GeneralRe: Program Help Pin
Bloodyway11-Aug-18 19:47
Bloodyway11-Aug-18 19:47 
GeneralRe: Program Help Pin
OriginalGriff11-Aug-18 20:08
mveOriginalGriff11-Aug-18 20:08 
GeneralRe: Program Help Pin
AnotherKen18-Aug-18 9:04
professionalAnotherKen18-Aug-18 9:04 
GeneralRe: Program Help Pin
Mycroft Holmes18-Aug-18 13:30
professionalMycroft Holmes18-Aug-18 13:30 
GeneralRe: Program Help Pin
AnotherKen18-Aug-18 19:18
professionalAnotherKen18-Aug-18 19:18 
AnswerRe: Program Help Pin
Richard Andrew x6412-Aug-18 3:32
professionalRichard Andrew x6412-Aug-18 3:32 
QuestionSplit a number into multiple number in a specific way Pin
Mou_kol10-Aug-18 11:14
Mou_kol10-Aug-18 11:14 
This is my code which is not returning data as per my requirement. So please rectify my code which will give me the desired output.
C#
static void Main(string[] args)
{
    List<int> test1 = DivideInt(10,1).ToList().OrderBy(s=> s).ToList();
    List<int> test2 = DivideInt(10, 2).ToList().OrderBy(s => s).ToList();
    List<int> test3 = DivideInt(10, 3).ToList().OrderBy(s => s).ToList();
    List<int> test4 = DivideInt(10, 4).ToList().OrderBy(s => s).ToList();
    List<int> test5 = DivideInt(10, 5).ToList().OrderBy(s => s).ToList();
    List<int> test6 = DivideInt(10, 6).ToList().OrderBy(s => s).ToList();
    List<int> test7 = DivideInt(10, 7).ToList().OrderBy(s => s).ToList();
    List<int> test8 = DivideInt(10, 8).ToList().OrderBy(s => s).ToList();
    List<int> test9 = DivideInt(10, 9).ToList().OrderBy(s => s).ToList();
    List<int> test10 = DivideInt(10, 10).ToList().OrderBy(s => s).ToList();

}

public static IEnumerable<int> DivideInt(int pagetotal, int userinput)
{
    if(userinput==0)
    {
        yield   return  0;
    }
    else
    {
        int rest =pagetotal % userinput;
        double  result =pagetotal / (double) userinput;

        for(int i=0; i< userinput;i++)
        {
            if(rest-- >0)
                yield return (int) Math.Ceiling(result);
            else
                yield return (int) Math.Floor(result);
        }
    }
}


My requirement as following.

1) if total page is 10 and user split into 2 files then two files will be generated each file will have 5 pages

2) if total page is 10 and user split into 3 files then 3 files will be generated. first 2 files will have 3 pages and last pages will have 4 pages.

3) if total page is 10 and user split into 4 files then 4 files will be generated. first 3 files will have 3 pages and last pages will have 1 pages.

4) if total page is 10 and user split into 5 files then 5 files will be generated. each files will have 2 pages

5) if total page is 10 and user split into 6 files then first 5 files will be generated with 1 page. last file will have 5 pages

6) if total page is 10 and user split into 7 files then first 6 files will be generated with 1 page. last file will have 4 pages.

7) if total page is 10 and user split into 8 files then first 7 files will be generated with 1 page. last file will have 3 pages.

8) if total page is 10 and user split into 9 files then first 8 files will be generated with 1 page. last file will have 2 pages.

8) if total page is 10 and user split into 10 files then 10 files will be generated with 1 page.

again

1) if total page is 9 and user split into 2 files then first file will be generated with 4 page. last file will have 5 pages.2) if total page is 9 and user split into 3 files then each 3 files will have 3 pages.

3) if total page is 9 and user split into 4 files then first 3 files will have 2 pages and last page will have 3 pages.

4) if total page is 9 and user split into 5 files then first 4 files will have 2 pages and last page will have 2 pages.5) if total page is 9 and user split into 6 files then first 5 files will have 1 pages and last page will have 4 pages.

6) if total page is 9 and user split into 7 files then first 6 files will have 1 pages and last page will have 3 pages.

7) if total page is 9 and user split into 8 files then first 7 files will have 1 pages and last page will have 2 pages.

8) if total page is 9 and user split into 9 files then each file will have 1 pages.

Hopefully I am clear what I am looking for.

The output i am getting from my program.

Here i am mentioning what kind of output i am getting from above code and what kind of i am expecting.

1) List test4 = DivideInt(10, 4).ToList().OrderBy(s => s).ToList(); output is getting 2,2,3,3 but output should be 2,2,2,4

2) List test6 = DivideInt(10, 6).ToList().OrderBy(s => s).ToList(); output is getting 1,1,2,2,2,2 but output should be 1,1,1,1,1,5

3) List test7 = DivideInt(10, 7).ToList().OrderBy(s => s).ToList(); output is getting 1,1,1,1,2,2,2 but output should be 1,1,1,1,1,1,4

4) List test8 = DivideInt(10, 8).ToList().OrderBy(s => s).ToList(); output is getting 1,1,1,1,1,1,2,2 but output should be 1,1,1,1,1,1,1,3

5) List test9 = DivideInt(10, 9).ToList().OrderBy(s => s).ToList(); output is getting 1,1,1,1,1,1,1,1,2 but output should be 1,1,1,1,1,1,1,1,2

please guide me what to change in routine DivideInt() thanks

modified 12-Aug-18 12:10pm.

AnswerRe: Number distribution in a specific way Pin
Mycroft Holmes10-Aug-18 13:34
professionalMycroft Holmes10-Aug-18 13:34 
AnswerRe: Number distribution in a specific way Pin
Luc Pattyn11-Aug-18 6:22
sitebuilderLuc Pattyn11-Aug-18 6:22 
QuestionGet file metada Pin
Member 1193763910-Aug-18 0:04
Member 1193763910-Aug-18 0:04 
AnswerRe: Get file metada Pin
Richard MacCutchan10-Aug-18 0:22
mveRichard MacCutchan10-Aug-18 0:22 
QuestionRDP connections in tabs Pin
Member 114416229-Aug-18 19:41
Member 114416229-Aug-18 19:41 
AnswerRe: RDP connections in tabs Pin
Mycroft Holmes9-Aug-18 20:20
professionalMycroft Holmes9-Aug-18 20:20 
GeneralRe: RDP connections in tabs Pin
Member 1144162212-Aug-18 23:54
Member 1144162212-Aug-18 23:54 
GeneralRe: RDP connections in tabs Pin
Pete O'Hanlon13-Aug-18 0:27
mvePete O'Hanlon13-Aug-18 0:27 
GeneralRe: RDP connections in tabs Pin
Member 1144162213-Aug-18 1:17
Member 1144162213-Aug-18 1:17 
GeneralRe: RDP connections in tabs Pin
Pete O'Hanlon13-Aug-18 1:23
mvePete O'Hanlon13-Aug-18 1:23 
GeneralRe: RDP connections in tabs Pin
Mycroft Holmes13-Aug-18 2:16
professionalMycroft Holmes13-Aug-18 2:16 
GeneralRe: RDP connections in tabs Pin
Member 1144162213-Aug-18 3:10
Member 1144162213-Aug-18 3:10 
GeneralRe: RDP connections in tabs Pin
Mycroft Holmes13-Aug-18 13:28
professionalMycroft Holmes13-Aug-18 13:28 
QuestionClasses In Threads - Pause One Until Another Finished Pin
Kevin Marois8-Aug-18 6:43
professionalKevin Marois8-Aug-18 6:43 
AnswerRe: Classes In Threads - Pause One Until Another Finished Pin
Richard Deeming8-Aug-18 8:05
mveRichard Deeming8-Aug-18 8:05 
AnswerRe: Classes In Threads - Pause One Until Another Finished Pin
OriginalGriff8-Aug-18 8:09
mveOriginalGriff8-Aug-18 8:09 
GeneralRe: Classes In Threads - Pause One Until Another Finished Pin
Kevin Marois8-Aug-18 8:22
professionalKevin Marois8-Aug-18 8:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.