Advertisement
catalyn

pr 2 teza model a)

May 14th, 2015
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include <iostream>
  2. #include<fstream>
  3. #include<cstring>
  4. using namespace std;
  5. ifstream f("date.in");
  6. struct nod
  7. {
  8. int info;
  9. nod *urm;
  10. };
  11. nod *prim;
  12.  
  13. void creare()
  14. {
  15. nod *p,*nou;
  16. int x,i;
  17. f>>x;
  18. for (i=0;i<=x;i+=2)
  19. {
  20. if(prim==NULL && (i%2)==0)
  21. {
  22. prim=new nod;
  23. prim->info=i;
  24. p=prim;
  25. }
  26. else
  27. if(i%2==0)
  28. {
  29. nou=new nod;
  30. nou->info=i;
  31. p->urm=nou;
  32. p=nou;
  33. }
  34. p->urm=NULL;
  35. }
  36.  
  37. }
  38.  
  39. void afisare ()
  40. {
  41. nod *p=prim;
  42. while (p)
  43. {
  44. cout<<p->info<<" ";
  45. p=p->urm;
  46. }
  47.  
  48. }
  49.  
  50.  
  51. int main()
  52. { creare();
  53. afisare();
  54. return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement