Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstdlib>
- #include <time.h>
- using namespace std;
- int zad1(int a, int b)
- {
- int wartosc, sum=0;
- for(int i=0;i<a;i++)
- {
- printf("Wczytywanie wiersza nr %d \n", i+1);
- for(int j=0;j<b;j++)
- {
- printf("Podaj liczbe nr %d w wierszu %d: ", j+1, i+1);
- cin>>wartosc;
- if(wartosc%2==0) sum+=wartosc;
- }
- }
- return sum;
- }
- void zad2()
- {
- int array[10][10];
- int k1,k2;
- for(int i=0;i<10;i++)
- {
- for(int j=0;j<10;j++)
- {
- array[i][j]=rand()%10;
- cin>>array[i][j];
- }
- cout<<endl;
- }
- cout<<"Ktore kolumny chcesz dodac?"<<endl;
- cin>>k1;
- cin>>k2;
- for(int i=0;i<10;i++) array[i][k1-1] += array[i][k2-1];
- for(int i=0;i<10;i++)
- {
- for(int j=0;j<10;j++) printf("%d", array[i][j]);
- cout<<endl;
- }
- }
- void zad3()
- {
- char tab [50];
- cout<<"Napisz zdanie\n";
- cin.getline (tab,50);
- cout<<tab;
- cout<<endl;
- int a,indeks;
- for (int i=0;i<50;i++)
- if (tab[i]==0)
- {
- indeks=i;
- break;
- }
- cout<<endl;
- cout<<endl;
- for (int i=indeks-1;i>=0;i--)
- {
- cout<<tab[i];
- }
- cout<<endl;
- }
- int main()
- {
- int spr;
- srand(time(NULL));
- bool koniec = false;
- while(!koniec)
- {
- cout<<"Program glowny \n"<<endl;
- cout<<"1. Suma liczb parzystych z tablicy M x N (jako parametry)\n"<<endl;
- cout<<"2. Wyswietla wylosowana tablice 10x10, dodaje kolumne x1 do x2 i wyswietla \n"<<endl;
- cout<<"3. Wczytuje zdanie do tablicy 100 elementowej, wyswietla je na odwrót \n"<<endl;
- cout<<"Podaj dowolny znak by zakonczyc dzialanie programu \n"<<endl;
- cin>>spr;
- system("cls");
- switch(spr)
- {
- case 1:
- int A,B;
- cout<<"Podaj dwa wymiary (A,B): \n";
- cin>>A;
- cin>>B;
- printf("Suma liczb parzystych wynosi: %d \n\n", zad1(A,B));
- break;
- case 2:
- zad2();
- break;
- case 3:
- zad3();
- break;
- default:
- cout<<"Zly numer zadania. Koniec programu."<<endl;
- koniec = true;
- break;
- }
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement