1#include<bits/stdc++.h>
2#include <iostream>
3
4using namespace std;
5
6
7struct n{
8 int d;
9 struct n*next;
10 };
11
12void push(struct n**headref, int new_d)
13{
14 struct n* new_node=new n;
15 new_node->d=new_d;
16 new_node->next=(*headref);
17 (*headref)=new_node;
18 }
19
20 float avgofnodes(struct n*head)
21 {
22 if(!head){return -1;}
23 int c=0;
24 int s=0;
25 float avg =0.0;
26 struct n*now=head;
27 while(now!=NULL)
28 {
29 c++;
30 s+=now->d;
31 now=now->next;
32 }
33 avg=(double)s/c;
34 return avg;
35 }
36
37int main()
38{
39struct n*head=NULL;
40push(&head , 7);
41push(&head, 6);
42push(&head, 8);
43push(&head, 4);
44push(&head, 1);
45 cout<<"Average of nodes = "<<avgofnodes(head);
46return 0;
47}
1#include <iostream>
2
3using namespace std;
4
5int main()
6
7{ int n=4,num-n-1; for(int i=1;i<n;i++) {
8
9for(int j=1;j<=i;j++) cout<<num; cout<<endl;
10
11num++;
12
13}
14
15num-;
16
17for(int i=n;i>=1;i-)
18
19{ for(int j=1;j<=i;j++) cout<<num; num--; cout<<endl;
20
21}
22
23return 0;