Advertisement
Guest User

Untitled

a guest
Mar 30th, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include <time.h>
  4. using namespace std;
  5.  
  6. int zad1(int a, int b)
  7. {
  8. int wartosc, sum=0;
  9.  
  10. for(int i=0;i<a;i++)
  11. {
  12. printf("Wczytywanie wiersza nr %d \n", i+1);
  13. for(int j=0;j<b;j++)
  14. {
  15. printf("Podaj liczbe nr %d w wierszu %d: ", j+1, i+1);
  16. cin>>wartosc;
  17. if(wartosc%2==0) sum+=wartosc;
  18. }
  19. }
  20. return sum;
  21. }
  22. void zad2()
  23. {
  24. int array[10][10];
  25. int k1,k2;
  26.  
  27. for(int i=0;i<10;i++)
  28. {
  29. for(int j=0;j<10;j++)
  30. {
  31. array[i][j]=rand()%10;
  32. cin>>array[i][j];
  33. }
  34. cout<<endl;
  35. }
  36. cout<<"Ktore kolumny chcesz dodac?"<<endl;
  37. cin>>k1;
  38. cin>>k2;
  39.  
  40. for(int i=0;i<10;i++) array[i][k1-1] += array[i][k2-1];
  41.  
  42. for(int i=0;i<10;i++)
  43. {
  44. for(int j=0;j<10;j++) printf("%d", array[i][j]);
  45. cout<<endl;
  46. }
  47.  
  48. }
  49.  
  50. void zad3()
  51. {
  52. char tab [50];
  53. cout<<"Napisz zdanie\n";
  54. cin.getline (tab,50);
  55. cout<<tab;
  56. cout<<endl;
  57. int a,indeks;
  58. for (int i=0;i<50;i++)
  59. if (tab[i]==0)
  60. {
  61. indeks=i;
  62. break;
  63. }
  64. cout<<endl;
  65. cout<<endl;
  66. for (int i=indeks-1;i>=0;i--)
  67. {
  68. cout<<tab[i];
  69. }
  70. cout<<endl;
  71. }
  72.  
  73. int main()
  74. {
  75. int spr;
  76. srand(time(NULL));
  77. bool koniec = false;
  78.  
  79. while(!koniec)
  80. {
  81. cout<<"Program glowny \n"<<endl;
  82. cout<<"1. Suma liczb parzystych z tablicy M x N (jako parametry)\n"<<endl;
  83. cout<<"2. Wyswietla wylosowana tablice 10x10, dodaje kolumne x1 do x2 i wyswietla \n"<<endl;
  84. cout<<"3. Wczytuje zdanie do tablicy 100 elementowej, wyswietla je na odwrót \n"<<endl;
  85. cout<<"Podaj dowolny znak by zakonczyc dzialanie programu \n"<<endl;
  86.  
  87. cin>>spr;
  88. system("cls");
  89.  
  90. switch(spr)
  91. {
  92. case 1:
  93. int A,B;
  94. cout<<"Podaj dwa wymiary (A,B): \n";
  95. cin>>A;
  96. cin>>B;
  97. printf("Suma liczb parzystych wynosi: %d \n\n", zad1(A,B));
  98. break;
  99. case 2:
  100. zad2();
  101. break;
  102. case 3:
  103. zad3();
  104. break;
  105. default:
  106. cout<<"Zly numer zadania. Koniec programu."<<endl;
  107. koniec = true;
  108. break;
  109. }
  110. }
  111.  
  112.  
  113. system("pause");
  114. return 0;
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement