Saturday, March 18, 2017

URI problem 1099 solution in C | (Sum of Consecutive Odd Numbers II)

To get the solution, click the link below:


link:
https://codespathshala.com/uri-1099/


/

2 comments:

  1. By JAVA

    int test;
    Scanner sc=new Scanner(System.in);
    test=sc.nextInt();
    int j;

    for(j=1;j<=test;j++)
    {

    int first,sec,i,counta=0;
    first=sc.nextInt();
    sec=sc.nextInt();
    if(first==sec)
    {
    counta=0;
    }
    else if(first<sec)
    {
    if(first%2!=0)
    {
    for(i=first+2;i<sec;i=i+2)
    {
    counta=counta+i;
    }

    }
    else{
    for(i=first+1;i<sec;i=i+2)
    {
    counta=counta+i;
    }


    }
    }
    else
    {
    if(sec%2!=0)
    {
    for(i=sec+2;i<first;i=i+2)
    {
    counta=counta+i;
    }


    }
    else{
    for(i=sec+1;i<first;i=i+2)
    {
    counta=counta+i;
    }


    }
    }

    System.out.println(counta);

    }

    ReplyDelete