C++ program on A NEW GAME



A NEW GAME

C++ program on A New Game (www.bloggerspot.tk)


THE CWG 2010 committee is bored with the usual long jump, high jump and triple jump and they have 
decided to introduce a new game called staircase climbing. The players need to climb a staircase. There are 
n steps and each step is 1 meter higher than the previous one. The player who first reaches the top of the 
staircase will be declared as the winner.
The audio-visual committee is responsible for placing pan and tilt cameras at all locations and one of their 
main objective is to capture the winning moment in all the games. They were pondering on where to place 
the camera for capturing the winning moment of the staircase climbing game. Finally, they decided on 
placing the camera at the same height as the top of the staircase.
Given the number of steps 'n' and the height of the first step 'h', write a C program to find the position 
where the camera needs to be placed.

Input Format:
The input consists of 2 integers which correspond to n and h.

Output Format:
Output consists of a single integer.

Sample Input 1:
5
1

Sample Output 1:
15

Solution:

#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
int n, h, i, sum = 0;
cin >> n;
cin >> h;
for(i = 0; i < n; i++)
{
sum = sum + (h++);
}
cout << sum << '\n';
return 0;
}

No comments:

Post a Comment

Your Comments here.

© Copyright 2015. Website by Way2themes - Published By Gooyaabi Templates