Sunday, 27 March 2016

Solution of URI 1149 :: Summing Consecutive Integers


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
int main()
{
    int X, N, a,b=0;
    scanf("%d %d", &X, &N);
    while(N<=0)
        scanf("%d", &N);
    for(a=1; a<=N; a++)
    {
        b+=X;
        X++;
    }
    printf("%d\n",b);
    return 0;
}

6 comments:

  1. I had a lot of trouble resolving this problem

    ReplyDelete
  2. why there is no braces in while loop
    please help me Sir.

    ReplyDelete
    Replies
    1. #include
      int main()
      {
      int a,n,i,j,sum;
      scanf("%d%d",&a,&n);

      while(n<=0)
      {
      scanf("%d",&n);
      if(n>0) break;
      }printf("%d\n",(a*n)+1);

      }

      Delete
  3. #include
    int main()
    {
    int a,n,i,j,sum;
    scanf("%d%d",&a,&n);

    while(n<=0)
    {
    scanf("%d",&n);
    if(n>0) break;
    }printf("%d\n",(a*n)+1);

    }

    ReplyDelete
  4. input 3 3 then saw the answer ,
    it's 10, but correct answer is 12 ,
    not only input 3 3 you can try more, then calculate on a page .

    ReplyDelete

Note: only a member of this blog may post a comment.