View Code of Problem 18

#include<bits/stdc++.h>
using namespace std;

int main() {

	int n;
	while(cin>>n) {
		if(n<3) {
			cout<<0<<endl;
		} else {
			int num=0;
			int k=n/2;
			for(int i=1; i<k; i++) {
				num+=i;
			}
			num*=2;
			if(n%2!=0) {
				num+=k;
			}
			cout<<num<<endl;
		}
	}


	return 0;
}

Double click to view unformatted code.


Back to problem 18