Advertisement
Guest User

zap

a guest
Dec 10th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <ctype.h>
  5.  
  6. int count_zeros();
  7. int count_vowels();
  8. int max();
  9. int index();
  10. int largest();
  11. void swap();
  12.  
  13. int main(){
  14.  
  15. ////////////////////////////////////////////COUNT ZEROS
  16. int array[4][4] = { {1, 0, -10, 0},
  17. {0,-3, 0, 8},
  18. {0,0,69,420},
  19. {5,0,1,0}
  20. };
  21. printf("ZEROS = %d\n",count_zeros(4,array));
  22.  
  23. /////////////////////////////////////////////COUNT VOWELS
  24. char strings[3][50] = {"hello WORLD!", "aHOJú", "Ahoj"};
  25. printf("VOWELS = %d\n", count_vowels(3,50,strings));
  26.  
  27. ////////////////////////////////////////////MAX
  28. int array2[4][4] = { {1,5,9,250},
  29. {-5,-95,124,0},
  30. {7,8,666,0},
  31. {2254,-665,14,3},
  32. };
  33. printf("MAX NUMBER = %d\n", max(4,array2));
  34.  
  35. ///////////////////////////////////////LONGEST STRING
  36. char sarray[3][50] = {
  37. {"Hello sdsds u"},
  38. {"jeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"},
  39. {"keeeee"}};
  40. printf("INDEX = %d\n",index(3,50,sarray));
  41.  
  42. ///////////////////////////////////////LARGEST
  43. int array3[3][3] = {{1,0,1},{0,-3,5},{150,1,4}};
  44. printf("%d\n", largest(3, array3));
  45.  
  46. ///////////////////////////////////////SWAP CASE
  47. char strings2[2][50] = {{"Ahoj ako sa Mas FeRo"},
  48. {"jeNbvEfRtoLp"}};
  49. swap(2,50,strings2);
  50. for(int o = 0; o<2; o++){
  51. for(int k=0; k<50; k++){
  52. printf("%c",strings2[o][k]);
  53. }
  54. printf("\n");
  55. }
  56.  
  57.  
  58. return 0;
  59. }
  60. void swap(const int rows, const int cols, char strings[][cols]){
  61. for(int o=0; o<rows; o++){
  62. for(int k=0; k<cols; k++){
  63. if(isupper(strings[o][k])){
  64. strings[o][k] = tolower(strings[o][k]);
  65. }else
  66. strings[o][k] = toupper(strings[o][k]);
  67. }
  68. }
  69. }
  70.  
  71. int largest(const int size, int array[][size]){
  72. if(array == NULL)
  73. return -1;
  74. int number=0, pomnumber=0,index=0;
  75. for(int o=0; o<size; o++){
  76. number+=array[0][o];
  77. }
  78. for(int k=0; k<size; k++){
  79. for(int n=0; n<size; n++){
  80. pomnumber+=array[k][n];
  81. if(pomnumber > number){
  82. number = pomnumber;
  83. index = k;
  84. }
  85. }
  86. }
  87. return index;
  88. }
  89. int index(const int rows, const int cols, char strings[rows][cols]){
  90. if(strings == NULL)
  91. return -1;
  92. int index=0,len0=strlen(strings[0]);
  93. for(int o=0; o<rows; o++){
  94. int len = strlen(strings[o]);
  95. if(len0 < len){
  96. len0 = len;
  97. index=o;
  98. }
  99. }
  100. return index;
  101. }
  102.  
  103. int max(const int size, int array[][size]){
  104. if(array == NULL)
  105. return -1;
  106. int number = 0;
  107. for(int o=0; o<size; o++){
  108. for(int k=0; k<size; k++){
  109. if(array[o][k] > number)
  110. number = array[o][k];
  111. }
  112. }
  113. return number;
  114. }
  115. int count_vowels(const int rows, const int cols, char strings[][cols]){
  116. if(strings == NULL)
  117. return -1;
  118. int count =0;
  119. char lt;
  120. for(int o=0; o<rows; o++){
  121. for(int k=0; k<cols; k++){
  122. lt = tolower(strings[o][k]);
  123. if(lt == 'a' || lt == 'e' || lt == 'i' || lt == 'o' || lt == 'u')
  124. count++;
  125. }
  126. }
  127. return count;
  128. }
  129.  
  130. int count_zeros(const int size, int array[][size]){
  131. if(array == NULL)
  132. return -1;
  133. int count = 0;
  134. for(int o=0; o<size; o++){
  135. for(int k=0; k<size; k++){
  136. if(array[o][k] == 0){
  137. count++;
  138. }
  139. }
  140. }
  141. return count;
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement