Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //1. ZADATAK
- #include <stdio.h>
- main()
- {
- int a[100],i=0,j;
- float sr=0;
- FILE *f1;
- f1=fopen("brojevi.txt","r");
- while (!feof(f1))
- {
- fscanf(f1,"%d",&a[i]);
- i++;
- }
- fclose(f1);
- for (j=0;j<i;j++)
- sr=a[j]+sr;
- f1=fopen("brojevi.txt","a");
- fprintf(f1," %f",sr/j);
- fclose(f1);
- }
- //2. ZADATAK
- #include <stdio.h>
- #include <string.h>
- main()
- {
- FILE *f1;
- char a[100];
- int i=0,j;
- gets(a);
- f1=fopen("reci.txt","w");
- while (i<strlen(a) && a[i]!=0)
- {
- if (a[i]!=' ')
- {
- while (a[i]!=' ' && a[i]!=0)
- {
- fprintf(f1,"%c",a[i]);
- i++;
- }
- fprintf(f1,"\n");
- }
- i++;
- }
- fclose(f1);
- }
- //3. ZADATAK
- #include <stdio.h>
- main()
- {
- char a[100];
- int i=0,k,br,j;
- gets(a);
- scanf("%d",&k);
- while (i<100 && a[i]!=0)
- {
- if ((a[i]>='a' && a[i]<='z' ) || (a[i]>='A' && a[i]<='Z'))
- {
- br=1;
- j=i+1;
- while (j<100 && a[j]!=0)
- {
- if (a[i]==a[j])
- {
- br++;
- a[j]='0';
- }
- j++;
- }
- if (br>=k)
- printf("%c\t",a[i]);
- }
- i++;
- }
- }
- //4. ZADATAK
- #include <stdio.h>
- #include <string.h>
- main()
- {
- char s[100],pom[100];
- int i,z;
- gets(s);
- for (i=0;i<100 && s[i]!=0;i++)
- if (s[i]==' ')
- z=i;
- strncpy(pom,&s[z+1],strlen(s)-z-1);
- pom[strlen(s)-z-1]=' ';
- pom[strlen(s)-z]='\0';
- strncat(pom,s,z);
- puts(pom);
- }
- //5. ZADATAK
- #include <stdio.h>
- #include <string.h>
- main()
- {
- char r[100],s[20];
- int i=0,br=0;
- gets(r);
- gets(s);
- if (strncmp(r,s,strlen(s))==0)
- br++;
- while (r[i]!=0)
- {
- if (r[i]==s[0] && r[i+strlen(s)]==' ' && r[i-1]==' ')
- if (!strncmp(&r[i],s,strlen(s)-1))
- br++;
- i++;
- }
- printf("%d",br);
- }
- //6. ZADATAK
- #include <stdio.h>
- main()
- {
- FILE *f1;
- int vr=0,br=1,bin;
- f1=fopen("binarne-cifre.txt","r");
- while (!feof(f1))
- {
- fscanf(f1,"%d",&bin);
- vr=vr+bin*br;
- br=br*2;
- }
- printf("%d",vr);
- }
- //7. ZADATAK
- #include <stdio.h>
- #include <string.h>
- main()
- {
- char s[100],c[100];
- int p=0;
- FILE *f1;
- f1=fopen("tekst.txt","r");
- gets(s);
- while (!feof(f1))
- {
- fscanf(f1,"%s",c);
- if (!strcmp(s,c))
- p=1;
- }
- if (p)
- printf("POSTOJI");
- else
- printf("NE POSTOJI");
- }
- //8. ZADATAK
- #include <stdio.h>
- #include <string.h>
- void nadovezi(char a[],char b[])
- {
- int i,j=0;
- i=strlen(a);
- while (b[j]!=0)
- {
- a[i]=b[j];
- i++;
- j++;
- }
- a[i]='\0';
- return;
- }
- main()
- {
- char s1[100],s2[100];
- gets(s1);
- gets(s2);
- nadovezi(s1,s2);
- puts(s1);
- }
- //9. ZADATAK
- #include <stdio.h>
- main()
- {
- char s[100];
- int i=0;
- gets(s);
- while (s[i]!=0)
- {
- if (s[i]>='A' && s[i]<='Z')
- s[i]=s[i]+('a'-'A');
- i++;
- }
- puts(s);
- }
- //10. ZADATAK
- #include <stdio.h>
- #include <string.h>
- main()
- {
- FILE *f1,*f2;
- char s[100];
- int m;
- scanf("%d",&m);
- f1=fopen("recenice.txt","r");
- f2=fopen("sadrze.txt","w");
- while (!feof(f1))
- {
- fgets(s,100,f1);
- if (strlen(s)>m)
- fprintf(f2,"%s",s);
- }
- fclose(f1);
- fclose(f2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement