Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ПРВА ЗАДАЧА
- #include<stdio.h>
- void write() {
- FILE *f = fopen("text.txt", "w");
- char c;
- while((c = getchar()) != '#') {
- fputc(c, f);
- }
- fclose(f);
- }
- int main() {
- char ch;
- write();
- float c = 0, br = 0;
- FILE *f1;
- if ((f1 = fopen("text.txt", "r")) == NULL) {
- printf ("Datotekata ne se otvora.");
- return -1;
- }
- while ((ch = fgetc(f1)) != EOF) {
- if (isalpha(ch)) {
- c++;
- }
- if (isdigit(ch)) {
- br++;
- }
- }
- printf("%.2f",br/c);
- fclose(f1);
- return 0;
- //
- }
- ВТОРА ЗАДАЧА
- #include <stdio.h>
- void writeToFile() {
- FILE *f = fopen("matrica.txt", "w");
- char c;
- while((c = getchar()) != '#') {
- fputc(c, f);
- }
- fclose(f);
- }
- void printFile() {
- FILE *f=fopen("izlez.txt","r");
- char line[100];
- while(!feof(f)){
- fgets(line,100,f);
- if (feof(f))
- break;
- printf("%s",line);
- }
- fclose(f);
- }
- int main() {
- writeToFile();
- FILE *f1, *f2;
- char c;
- int h, b, m[100][100], i, r, s = 0;
- if((f1 = fopen("matrica.txt", "r")) == NULL) {
- printf("Datotekata ne se otvora.");
- return -1;
- }
- fscanf(f1,"%d %d", &h, &b);
- for(i = 0; i < h&&!feof(f1); i++) {
- for(r = 0; r < b&&!feof(f1); r++) {
- fscanf(f1, "%d", &m[i][r]);
- }
- }
- fclose(f1);
- f2 = fopen("output.txt", "w");
- for(i = 0; i < h; i++) {
- for(r = 0; r < b; r++) {
- s=s+m[i][r];
- }
- if(s > 10) {
- printf("%d\n", s);
- }
- s = 0;
- }
- fclose(f2);
- printFile();
- return 0;
- }
- ТРЕТА ЗАДАЧА
- #include <stdio.h>
- void writeToFile() {
- FILE *f = fopen("text.txt", "w");
- char c;
- while((c = getchar()) != '#') {
- fputc(c, f);
- }
- fclose(f);
- }
- void printFile() {
- FILE *f=fopen("print.txt","r");
- char line[100];
- while(!feof(f)){
- fgets(line,100,f);
- if (feof(f))
- break;
- printf("%s",line);
- }
- fclose(f);
- }
- int isPalindrom(char* num) {
- int i, bb = 0;
- char n[101];
- for(i = 0; i < strlen(num); i++) {
- if(isalpha(num[i])) {
- n[bb] = num[i];
- bb++;
- }
- }
- n[bb] = '\0';
- for(i = 0, bb = strlen(n) - 1; i <= bb; i++, bb--) {
- if(toupper(*(n + i)) != toupper(*(n + bb)))
- return 0;
- }
- for(i = 0; i < strlen(n); i++)
- num[i] = n[i];
- num[i] = '\0';
- return 1;
- }
- int main() {
- int len, flag = 0;
- char n[101];
- FILE* input = fopen("text.txt", "r");
- FILE* output = fopen("print.txt", "w");
- writeToFile();
- while((fscanf(input, "%s", n)) != EOF) {
- if(isPalindrom(n))
- fprintf(output, "%s\n", n);
- }
- fclose(input);
- fclose(output);
- printFile();
- return 0;
- printFile();
- return 0;
- }
- ЧЕТВРТА ЗАДАЧА
- #include <stdio.h>
- void writeToFile() {
- FILE *f = fopen("text.txt", "w");
- char c;
- while((c = getchar()) != '#') {
- fputc(c, f);
- }
- fclose(f);
- }
- int main() {
- writeToFile();
- char ch;
- int gb = 0, l = 0, lt=0, i = 1;
- FILE *file = fopen("text.txt", "r");
- if ((ch = fgetc(file)) == 'O'){
- printf("%d", 3);
- return 0;
- }
- else
- while ((ch = fgetc(file)) != EOF) {
- if (isupper(ch))
- gb++;
- if (ch=='\n') {
- if (gb > lt)
- {
- lt = gb;
- l = i;
- }
- gb = 0;
- i++;
- }
- }
- printf("%d", l);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement