visoft

Pregatire 2, pb 1

Nov 5th, 2020
802
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. typedef struct {
  6.     int n;
  7.     double *coeficienti;
  8.     double x;
  9. } Polinom;
  10.  
  11. Polinom citire(){
  12.     Polinom p;
  13.     printf("n= ");
  14.     scanf("%d", &p.n);
  15.     p.coeficienti = (double*)malloc(p.n * sizeof(double ));
  16.     for(int i = 0; i < p.n; i++){
  17.         scanf("%lf", &p.coeficienti[i]);
  18.     }
  19.     p.x=0.1234;
  20.     return p;
  21. }
  22.  
  23. void afisare(Polinom p){
  24.     printf("\nP(%.3f)=",p.x);
  25.     for(int i=0;i<p.n;i++){
  26.         printf("%lf ", p.coeficienti[i]);
  27.     }
  28.     printf("\n");
  29. }
  30.  
  31. void modificare(Polinom *p){
  32.     p->x = 4534;             // 14
  33.     p->coeficienti[0] = 42;  // 4
  34. }
  35.  
  36. int main() {
  37.  
  38.     Polinom p_citit = citire();
  39.     afisare(p_citit);
  40.     modificare(&p_citit);
  41.     afisare(p_citit);
  42.     printf("Done");
  43.  
  44.     free(p_citit.coeficienti);
  45.     return 0;
  46. }
  47.  
  48.  
RAW Paste Data