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

31 lines
736 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;
2017-12-05 19:23:11 +01:00
printf("Geben sie den Startwert ein: ");
2017-04-10 21:17:40 +02:00
getline(std::cin, input);
std::stringstream(input) >> start;
2017-12-05 19:23:11 +01:00
printf("Geben sie den Endwert ein: ");
2017-04-10 21:17:40 +02:00
getline(std::cin, input);
std::stringstream(input) >> end;
2017-12-05 19:23:11 +01:00
printf("\n");
2017-04-10 21:17:40 +02:00
2017-12-05 19:23:11 +01:00
if(start<end) for(int idx = start; idx<end; idx++) printf("%i, ", idx);
else for(int idx = start; idx>end; idx--) printf("%i, ", idx);
2017-04-14 19:24:44 +02:00
2017-12-05 19:23:11 +01:00
printf("%i\n\nDie Summe der natuerlichen Zahlen von %i bis %i betraegt: ",end, start, end);
if(start<end) printf("%i", (end*(end+1)-start*(start-1))/2);
else printf("%i", (end*(end-1)-start*(start+1))/2);
2017-04-10 21:17:40 +02:00
getch();
return(0);
}