Commit f0f2e0bd authored by Nighz's avatar Nighz
Browse files

Added some loop scripts

parent 19d61380
*.o
*.exe
\ No newline at end of file
*.exe
*test*.*
\ No newline at end of file
#include <iostream>
using namespace std;
int main()
{
int eing, quer = 0, tmp;
cout<<"Geben Sie eine natuerliche Zahl ein: ";
cin>>eing;
if(eing < 0)
{
cout<<"Ungueltiger Wert.";
return 1;
}
tmp = eing;
while(eing != 0)
{
quer += eing % 10;
eing /= 10;
}
cout<<"Die Quersumme von "<<tmp<<" ist "<<quer;
return 0;
}
#include <iostream>
using namespace std;
int main()
{
for(int i = 1; i <= 100; i++)
{
if(!(i % 7 == 0 || i % 10 == 7 || i / 10 == 7)) // if(i%7 != 0 && i%10 != 7 && i/10 != 7)
{
cout<<i;
if(i != 100) cout<<", ";
}
}
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int n;
float sum = 0.0, epsilon;
cout<<"Geben Sie ein N ein: ";
cin>>n;
cout<<"Geben Sie ein Epsilon ein: ";
cin>>epsilon;
for(int i = 1; i <= n; i++)
{
if((1.0 / i - 1.0 / (i + 1)) < epsilon && i < n) break;
sum += 1.0 / i;
}
cout<<"Das Ergebnis lautet: "<<sum;
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int a, b = 0, z = 1, tmp;
cout<<"Geben Sie eine natrliche Zahl ein: ";
cin>>a;
if(a < 0)
{
cout<<"Ungueltige Eingabe!";
return 1;
}
tmp = a;
while(a != 0)
{
b += z * (a % 2);
a /= 2;
z *= 10;
}
cout<<"Binaerzahl zu "<<tmp<<" = "<<b;
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment