You are on page 1of 1

#include<iostream>

using namespace std;


int main()
{
int n, i = 0;
char var;
cout << "Enter any Number for its Sum: ";
cin >> n;
cout << "Press 'F' to use for loop or Press 'W' to use while: ";
cin >> var;
switch (var)
{
case'F':
for (n; n > 0; n--)
{
i = i + n;
}
cout << "Sum = " << i << endl;
break;
case'W':
while (n > 0)
{
i = i + n;
n--;
}
cout << "Sum = " << i << endl;
break;
default:
cout << "Invalid" << endl;
}
return 0;
}

You might also like