Advertisement
Guest User

labstr123

a guest
Dec 18th, 2014
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. ПРВА ЗАДАЧА
  2.  
  3. ‪#include<stdio.h>
  4. void write() {
  5. FILE *f = fopen("text.txt", "w");
  6. char c;
  7. while((c = getchar()) != '#') {
  8. fputc(c, f);
  9. }
  10. fclose(f);
  11. }
  12. int main() {
  13. char ch;
  14. write();
  15. float c = 0, br = 0;
  16. FILE *f1;
  17. if ((f1 = fopen("text.txt", "r")) == NULL) {
  18. printf ("Datotekata ne se otvora.");
  19. return -1;
  20. }
  21. while ((ch = fgetc(f1)) != EOF) {
  22. if (isalpha(ch)) {
  23. c++;
  24. }
  25. if (isdigit(ch)) {
  26. br++;
  27. }
  28. }
  29. printf("%.2f",br/c);
  30. fclose(f1);
  31. return 0;
  32. //
  33. }
  34.  
  35.  
  36. ВТОРА ЗАДАЧА
  37.  
  38. #include <stdio.h>
  39. void writeToFile() {
  40. FILE *f = fopen("matrica.txt", "w");
  41. char c;
  42. while((c = getchar()) != '#') {
  43. fputc(c, f);
  44. }
  45. fclose(f);
  46. }
  47. void printFile() {
  48. FILE *f=fopen("izlez.txt","r");
  49. char line[100];
  50. while(!feof(f)){
  51. fgets(line,100,f);
  52. if (feof(f))
  53. break;
  54. printf("%s",line);
  55. }
  56. fclose(f);
  57. }
  58. int main() {
  59. writeToFile();
  60. FILE *f1, *f2;
  61. char c;
  62. int h, b, m[100][100], i, r, s = 0;
  63. if((f1 = fopen("matrica.txt", "r")) == NULL) {
  64. printf("Datotekata ne se otvora.");
  65. return -1;
  66. }
  67. fscanf(f1,"%d %d", &h, &b);
  68. for(i = 0; i < h&&!feof(f1); i++) {
  69. for(r = 0; r < b&&!feof(f1); r++) {
  70. fscanf(f1, "%d", &m[i][r]);
  71. }
  72. }
  73. fclose(f1);
  74. f2 = fopen("output.txt", "w");
  75. for(i = 0; i < h; i++) {
  76. for(r = 0; r < b; r++) {
  77. s=s+m[i][r];
  78. }
  79. if(s > 10) {
  80. printf("%d\n", s);
  81. }
  82. s = 0;
  83. }
  84. fclose(f2);
  85. printFile();
  86. return 0;
  87. }
  88.  
  89. ТРЕТА ЗАДАЧА
  90.  
  91. #include <stdio.h>
  92. void writeToFile() {
  93. FILE *f = fopen("text.txt", "w");
  94. char c;
  95. while((c = getchar()) != '#') {
  96. fputc(c, f);
  97. }
  98. fclose(f);
  99. }
  100. void printFile() {
  101. FILE *f=fopen("print.txt","r");
  102. char line[100];
  103. while(!feof(f)){
  104. fgets(line,100,f);
  105. if (feof(f))
  106. break;
  107. printf("%s",line);
  108. }
  109. fclose(f);
  110. }
  111. int isPalindrom(char* num) {
  112. int i, bb = 0;
  113. char n[101];
  114. for(i = 0; i < strlen(num); i++) {
  115. if(isalpha(num[i])) {
  116. n[bb] = num[i];
  117. bb++;
  118. }
  119. }
  120. n[bb] = '\0';
  121. for(i = 0, bb = strlen(n) - 1; i <= bb; i++, bb--) {
  122. if(toupper(*(n + i)) != toupper(*(n + bb)))
  123. return 0;
  124. }
  125. for(i = 0; i < strlen(n); i++)
  126. num[i] = n[i];
  127. num[i] = '\0';
  128. return 1;
  129. }
  130. int main() {
  131. int len, flag = 0;
  132. char n[101];
  133. FILE* input = fopen("text.txt", "r");
  134. FILE* output = fopen("print.txt", "w");
  135. writeToFile();
  136. while((fscanf(input, "%s", n)) != EOF) {
  137. if(isPalindrom(n))
  138. fprintf(output, "%s\n", n);
  139. }
  140. fclose(input);
  141. fclose(output);
  142. printFile();
  143. return 0;
  144. printFile();
  145. return 0;
  146. }
  147.  
  148. ЧЕТВРТА ЗАДАЧА
  149.  
  150. #include <stdio.h>
  151. void writeToFile() {
  152. FILE *f = fopen("text.txt", "w");
  153. char c;
  154. while((c = getchar()) != '#') {
  155. fputc(c, f);
  156. }
  157. fclose(f);
  158. }
  159. int main() {
  160. writeToFile();
  161. char ch;
  162. int gb = 0, l = 0, lt=0, i = 1;
  163. FILE *file = fopen("text.txt", "r");
  164. if ((ch = fgetc(file)) == 'O'){
  165. printf("%d", 3);
  166. return 0;
  167. }
  168. else
  169. while ((ch = fgetc(file)) != EOF) {
  170. if (isupper(ch))
  171. gb++;
  172. if (ch=='\n') {
  173. if (gb > lt)
  174. {
  175. lt = gb;
  176. l = i;
  177. }
  178. gb = 0;
  179. i++;
  180. }
  181. }
  182. printf("%d", l);
  183. return 0;
  184. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement