This repository has been archived on 2024-09-24. You can view files and clone it, but cannot push or open issues or pull requests.
Schule/Sonstiges/Zähler.cpp
2017-04-14 19:24:44 +02:00

30 lines
779 B
C++

#include<iostream>
#include<conio.h>
#include<sstream>
#include<string>
int main ()
{
long long start=0, end=0;
std::string input;
std::cout << "Geben sie den Startwert ein: ";
getline(std::cin, input);
std::stringstream(input) >> start;
std::cout << "\nGeben sie den Endwert ein: ";
getline(std::cin, input);
std::stringstream(input) >> end;
std::cout << "\n";
if(start<end) for(int idx = start; idx<end; idx++) std::cout << idx << ", ";
else for(int idx = start; idx>end; idx--) std::cout << idx << ", ";
std::cout << end << "\n\nDie Summe der natuerlichen Zahlen von " << start << " bis " << end << " betraegt: ";
if(start<end) std::cout << (end*(end+1)-start*(start-1))/2;
else std::cout << (end*(end-1)-start*(start+1))/2;
getch();
return(0);
}