E-LAB - Sum integers till n numbers


  • Q.: Sum integers
  • QUESTION DESCRIPTION
    Read Input Until User Enters a Positive Integer.
  • TEST CASE 1 
    INPUT
    5
    OUTPUT

    Sum=15
  • TEST CASE 2
  • INPUT
    12
    OUTPUT
    SUM= 78

CODING


#include <stdio.h>
int main()
{
  int n , i, sum=0;
  scanf("%d",&n);
  for(i=1; i<=n; i++)
  {
    sum=sum+i;
  }
    printf("Sum=%d\n",sum);
   return 0;
}



AFTER EVALUATING



No comments:

Post a Comment

Featured post

Introduction to my blog

INTRODUCTION  TO  MY  BLOG Hello , That was my first blog so I did not know how to start writing my first blog post. So here goes ,...