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

28 lines
699 B
C++
Raw Normal View History

2017-04-10 21:17:40 +02:00
#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: " << (end*(end+1)-start*(start-1))/2;
getch();
return(0);
}