Algorytmy 24.II.2012, Laborki, ASD
[ Pobierz całość w formacie PDF ]
ParzystoϾ#include <cstdlib>#include <iostream>#include <conio.h>#include <iomanip.h>using namespace std;int main(){int a;cout << "Podaj liczbe: ";cin >> a;if (a%2)cout << "Liczba nieparzysta ";elsecout << "Liczba parzysta \n\n\n";system("PAUSE");return EXIT_SUCCESS;}porownywanie trzech liczb#include <cstdlib>#include <iostream>#include <conio.h>#include <iomanip.h>using namespace std;int main(){int a,b,c;cout << "Podaj a: "; cin >> a;cout << "Podaj b: "; cin >> b;cout << "Podaj c: "; cin >> c;if ((a>=b)&&(a>=c)){if (b>=c) cout <<a << b<< c;else cout << a << c << b;}if ((b>=a)&&(b>=c)){if (a>=c) cout <<b << a<< c;else cout << b << c << a;}if ((c>=a)&&(c>=b)){if (a>=b) cout <<c << a<< b;else cout << c << b << a;}system("PAUSE");return EXIT_SUCCESS;}Sumowanie kolejnych liczb#include <cstdlib>#include <iostream>#include <conio.h>#include <iomanip.h>using namespace std;int main(){int a,s=0;while (a!=0){cout <<"Podaj liczbe "<< endl;cin >>a;s=s+a;}cout<<"Suma wynosi "<< s <<endl;system("PAUSE");return EXIT_SUCCESS;}Znalezenie min i max#include <cstdlib>#include <iostream>#include <conio.h>#include <iomanip.h>using namespace std;int main(){int a,max,min;cout<<"Podaj liczbe ";cin >>a;max=a;min=a;while (a!=0){if (a>max)max=a;if (a<min)min=a;cout<<"Podaj liczbe "; cin >>a;}cout <<"Maksymalna " <<max << endl;cout <<"Minimalna "<<min << endl;system("PAUSE");return EXIT_SUCCESS;}Wczytac liczby n oraz m i wypisac m-ta cyfre liczby n.#include <cstdlib>#include <iostream>#include <conio.h>#include <iomanip>using namespace std;int Potega(int l, int p){int tmp = l;for(int i=1; i<p; i++)tmp *= l;return tmp;}int main(){int n, m;cin>>n;cin>>m;while(n > Potega(10, m)){n /= 10;}cout<<endl<<n%10;cout<<endl<<endl;system("PAUSE");}
[ Pobierz całość w formacie PDF ]