Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Labor63.cpp : Defines the entry point for the console application.
- //Sebastian Schwinn und Martin Petter 2k17
- #include "stdafx.h"
- #include <iostream>
- #include <istream>
- using namespace std;
- char z[100];
- bool einlesen();
- unsigned int quersumme(char z[]);
- int main()
- {
- int qus;
- cout << "Bitte geben Sie eine grosse Zahl ein: (beenden mit ENTER)" << endl;
- if (einlesen() == true) {
- qus = quersumme(z);
- }
- else
- cout << "fehler" << endl;
- system("pause");
- return 0;
- }
- bool einlesen() {
- unsigned int t = 0, i;
- cin.width(size(z));
- cin >> z;
- for (i = 0; i < size(z); i++) {
- cin.get(z[i]);
- t = z[i];
- if (t > 47 && t < 58)
- continue;
- else
- cin.unget();
- }
- return true;
- }
- unsigned int quersumme(char z[]) {
- unsigned int qs = 0;
- cout << "Die Quersumme von ";
- for (unsigned int i = 0; i < strlen(z); i++) {
- cout << z[i];
- qs += z[i] - 48;
- }
- cout << " ist " << qs << endl;
- if (qs % 9 == 0)
- cout << "Ihre Zahl ist durch 9 teilbar." << endl;
- return qs;
- }
Advertisement
Add Comment
Please, Sign In to add comment