nucLeaRsc2

Untitled

Nov 15th, 2012
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. //Tema Lab 7
  2.  
  3. //Pr1
  4. #include <stdio.h>
  5. #include <conio.h>
  6. int main ()
  7. {
  8.     FILE *fin;
  9.     char s[30];
  10.     int primul,x,nr=0,total=1;
  11.     printf("Introdu numele fisierului: ");
  12.     scanf("%s", &s);
  13.     fin=fopen(s, "rt");
  14.     if(!fin)
  15.     {
  16.         printf("Eroare la deschidere");
  17.         getch();
  18.         return 1;
  19.     }
  20.     fscanf(fin, "%i", &primul);
  21.     while(!feof(fin))
  22.     {
  23.         fscanf(fin, "%i ", &x);
  24.         total++;
  25.         if(x>primul)
  26.             nr++;
  27.     }
  28.     printf("%4.2f", (float)nr/total*100);
  29.     getch();
  30.    
  31.     return 0;
  32. }
  33.  
  34.  
  35. //Pr2
  36. #include <stdio.h>
  37. #include <conio.h>
  38. int main ()
  39. {
  40.     FILE *fin;
  41.     char s[50];
  42.     int nrs=0, i=0, maxs=0, max=1, nos=0;
  43.     printf("Introdu numele fisierului: ");
  44.     scanf("%s", &s);
  45.     fin=fopen(s, "rt");
  46.     if(!fin)
  47.     {
  48.         printf("Eroare la deschidere");
  49.         getch();
  50.         return 1;
  51.     }
  52.     while(!feof(fin))
  53.     {
  54.         nrs=0;
  55.         char *p;
  56.         i++;
  57.         fgets(s, 50, fin);
  58.         for(p=s;*p;p++)
  59.             if(*p==' ')
  60.                 nrs++;
  61.         if(nrs>maxs)
  62.             max=i;
  63.         else if(nrs==0 && s[0]!='\n')
  64.             nos++;
  65.     }
  66.     printf("Procent: %.2f\tIndice linie: %i", (float)nos/i*100, max);
  67.     getch();
  68. }
Advertisement
Add Comment
Please, Sign In to add comment