Created
December 1, 2013 16:25
-
-
Save dafr32/7736250 to your computer and use it in GitHub Desktop.
Matura Podstawa 2012 zad.4 "Cyfry"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
using namespace std; | |
int sumaCyfr(int liczba) | |
{ | |
int suma=0,reszta=0; | |
while(liczba>0) | |
{ | |
reszta=(liczba % 10); | |
suma+=reszta; | |
liczba/=10; | |
} | |
return suma; | |
} | |
bool Rosnaca(int liczba) | |
{ | |
int c1=liczba % 10; | |
int c2=0; | |
liczba/=10; | |
while(liczba>0) | |
{ | |
c2=(liczba % 10); | |
if(c2>=c1) return false; | |
c1=c2; | |
liczba/=10; | |
} | |
return true; | |
} | |
int main() | |
{ | |
fstream plik; | |
int liczba,Suma; | |
int ileParzystych=0; | |
int SumaMax=0; | |
int SumaMin=0; | |
// cout <<sumaCyfr(66562)<<endl; | |
// cout <<sumaCyfr(121324); | |
// if (Rosnaca(1232)) cout<<"ok"; | |
// else cout <<"nie"; | |
plik.open("D:\\_Profile\\Darek\\Pulpit\\MaturaRozwiazania\\2012\\Podstawa\\cyfry.txt",ios::in); | |
if (plik) | |
{ | |
int nr=1; | |
while (plik>>liczba) | |
{ | |
if(liczba % 2==0) ileParzystych++; | |
if(sumaCyfr(liczba)>sumaCyfr(SumaMax))SumaMax=liczba; | |
if(nr==1) | |
SumaMin = liczba; | |
else | |
if(sumaCyfr(liczba)<sumaCyfr(SumaMin))SumaMin=liczba; | |
nr++; | |
if (Rosnaca(liczba)) cout<<liczba<<endl; | |
} | |
plik.close(); | |
cout<<"Ilosc liczb parzystych:"<<ileParzystych<<endl; | |
cout<<"Suma najwieksza:"<<SumaMax<<endl; | |
cout<<"Suma najmniejsza:"<<SumaMin<<endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment