Advertisement
Dani_info

V 53, S II, pb 5

Oct 29th, 2019
113
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. struct nod{
  7.     int info;
  8.     nod *leg;
  9. };
  10.  
  11. nod* creare(int n, int a, int r){
  12.     nod *prim=new nod;
  13.     prim->info=a;
  14.     a+=r;
  15.     nod *p=prim;
  16.     for (int i=1; i<n; i++, a+=r){
  17.         nod *q=new nod;
  18.         p->leg=q;
  19.         q->info=a;
  20.         p=q;
  21.     }
  22.     p->leg=NULL;
  23.     return prim;
  24. }
  25.  
  26. void parcurgere (nod *prim){
  27.     while (prim){
  28.         cout<<prim->info<<endl;
  29.         prim=prim->leg;
  30.     }
  31. }
  32.  
  33. int main()
  34. {
  35.     int n, a, r;
  36.     cin>>n>>a>>r;
  37.     nod *p=creare (n, a, r);
  38.     parcurgere (p);
  39.     return 0;
  40. }
Advertisement
RAW Paste Data Copied
Advertisement