- codewithshiva

Latest

Search Bar

Friday, July 2, 2021

 Sum Related Problem

Description

You are given a number N, find sum of all even numbers which occur before N (inclusive of N if N is even)

Input

Input Format

First and the only line contains one number N.

Constraints

N<10000

Output

Output Format

Output one number which is sum (under above condition)

Sample Input 1 

8

Sample Output 1

20
import java.util.Scanner;

public class Main {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int eng= sc.nextInt();
int sum = 0;
for(int i =0;i<=eng;i++){
if(i%2==0){
sum=sum+i;
}
}
System.out.println(sum);
}
}

No comments:

Post a Comment