Mode Gelap

Recent in Fashion

Best Seller Books

1311110004 Input and Output Statement Sum of numbers from 0 to N

We want to generate a function that computes the series starting from 0 and ending until the given number following the sequence:

0 1 3 6 10 15 21 28 36 45 55 ....

which is created by

0, 0+1, 0+1+2, 0+1+2+3, 0+1+2+3+4, 0+1+2+3+4+5, 0+1+2+3+4+5+6, 0+1+2+3+4+5+6+7 etc..

Input:
LastNumber
Output:
result

Example:

Input:
6
Output:
21

Input:
-15
Output:
0

Subscribe Our Newsletter

avatar
"By speaking behind my back, it means that you respect my existence enough not to act in front of my face."

Related Posts

1 Komentar

  1. import java.io.*;
    import java.util.Scanner;
    public class TestClass {
    public static void main(String[] args) {
    int sum=0;
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    for(int i=0;i<=n;i++)
    {
    sum=sum+i;}
    System.out.println(sum);
    }
    }

    ReplyDelete

Article Top Ads

Parallax Ads

Article Center Ads

Article Bottom Ads