Rezolvari

Document Sample
Rezolvari Powered By Docstoc
					Problema 1

       #include<stdio.h>
       #include<math.h>
       void main(){
              int n;
              printf("Introduceti        dimensiunea       vectorului,
       n=");scanf("%d",&n);
              float x[100];
              for(int i=0;i<n;i++){
                     printf("x[%d]=",i); scanf("%f", &x[i]); }
              float mg=1; int k = 0;
              for (i=0; i<n;i++)
                     if(x[i] > 0){ mg *= x[i]; k++;}
                     if (k>1) {
                            mg      =     exp(log(mg)/k);printf("Media
       geometrica este %f .", mg);}
                     else printf("Media geometrica nu se poate
       calcula!");
       }



Problema 2

       #include<stdio.h>
       void main(){
              int n;
              float x[100], a;
              printf("Dimensiunea vectorului:");scanf("%d",&n);
              for(int i=0;i<n;i++){printf("x[%d]=",i); scanf("%f",
       &x[i]);}
              printf("Introduceti valoarea:");scanf("%f", &a);
              i=0;
              while ((i<n) && (x[i]<a))i++;
              for(int j=n;j>i;j--) x[j] = x[j-1];
              x[j] = a;n++;
              printf("Vectorul rezultat este:\n");
              for(i=0;i<n;i++)printf("%4.2f ",x[i]);
       }

Problema 3
       #include<stdio.h>
       void main(){
              int n; float x[100], y[100], z[100];
              printf("Introduceti       dimensiunea       vectorilor,
       n=");scanf("%d",&n);
              printf("Introduceti elementele primului vector: \n");
              for(int i=0;i<n;i++){printf("x[%d]=",i); scanf("%f",
       &x[i]);       }
              printf("Introduceti elementele celui de al doilea
       vector: \n");
              for(i=0;i<n;i++){printf("y[%d]=",i);       scanf("%f",
       &y[i]);}
              for(i=0; i< n; i++) z[i] = x[i] * y[i];
              printf("Produsul vectorial este: \n");
              for (i=0;i<n;i++)printf("%6.2f ", z[i]);
       }

Problema 4

       #include<stdio.h>
       void main(){
              int n; float x[100], y[100], ps;
              printf("Introduceti       dimensiunea       vectorilor,
       n=");scanf("%d",&n);
              printf("Introduceti elementele primului vector: \n");
              for(int i=0;i<n;i++){printf("x[%d]=",i); scanf("%f",
       &x[i]);       }
              printf("Introduceti elementele celui de al doilea
       vector: \n");
              for(i=0;i<n;i++){printf("y[%d]=",i);        scanf("%f",
       &y[i]);}
              ps = 0;
              for(i=0; i< n; i++)ps+=x[i]*y[i];
              printf("Produsul scalar este %10.2f . \n", ps);
       }

Problema 5
       Interschimbare

       #include<stdio.h>
       void main(){//metoda bulelor
              int n; float x[100], aux ;
              printf("Introduceti        dimensiunea      vectorului,
       n=");scanf("%d",&n);
              for(int i=0;i<n;i++){printf("x[%d]=",i); scanf("%f",
       &x[i]);       }
              int p=1;
              while(p){
                     p = 0;
                     for(i=0;i<n-1;i++)
                            if(x[i]>x[i+1]){aux    =   x[i];x[i]    =
       x[i+1];x[i+1] = aux;p = 1; }
              }
              printf("Vectorul sortat este: \n");
              for (i=0;i<n;i++)printf("%6.2f ", x[i]);
       }

       Selecţie

       #include<stdio.h>
       void main(){//metoda selectiei
              int n; float x[100], aux ;
              printf("Introduceti        dimensiunea     vectorului,
       n=");scanf("%d",&n);
                  for(int i=0;i<n;i++){printf("x[%d]=",i); scanf("%f",
           &x[i]);       }
                  for(i=0;i<n-1;i++)
                         for(int j=0;j<n;j++)
                                if(x[i]>x[j]){aux    =     x[i];x[i] =
           x[i+1];x[i+1] = aux;}
                  printf("Vectorul sortat este: \n");
                  for (i=0;i<n;i++)printf("%6.2f ", x[i]);
           }

Inserţie

           #include<stdio.h>
           void main(){//sortarea prin insertie
                  int n, poz, j, k; float x[100], aux ;
                  printf("Introduceti        dimensiunea       vectorului,
           n=");scanf("%d",&n);
                  for(int i=0;i<n;i++){printf("x[%d]=",i); scanf("%f",
           &x[i]);}
                  for(i=1;i<n;i++)
                         if(x[i]<x[i-1]){
                                poz = -1; j = 0;
                                do{
                                       if(x[i] < x[j]) poz = j;else j++;
                                } while ((j<=n) && (poz == -1));
                                aux = x[i];
                                for (k=i; k>poz; k--) x[k] = x[k-1];
                                x[poz] = aux;
                         }
                  printf("Vectorul sortat este: \n");
                  for (i=0;i<n;i++)printf("%10.2f ", x[i]);
           }

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:24
posted:1/27/2011
language:Spanish
pages:3