Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct node{
- double element;
- struct node *next;
- }node_t;
- node_t *head = NULL;
- node_t *add_first(double value, node_t *l){
- node_t *newNode = (node_t*)malloc(sizeof(node_t));
- newNode->element =value;
- newNode->next=l;
- return newNode;
- }
- int getSize(node_t *l){
- int size=0;
- for(node_t *i=head; i!=NULL; i=i->next){
- ++size;
- }
- return size;
- }
- double getSum(node_t *l){
- double value =0;
- for(node_t *i=head; i!=NULL; i=i->next){
- value += i->element;
- }
- return value;
- }
- double pop() {
- return head->element;
- }
- node_t *remove_first(node_t *l){
- node_t *newNode = l->next;
- free(l);
- return newNode;
- }
- int main()
- {
- double input;
- double durchschnitt;
- double temp;
- while(input > 0){
- scanf("%lf", &input);
- head = add_first(input,head);
- }
- //remove negative numbers
- head = remove_first(head);
- durchschnitt = getSum(head)/getSize(head);
- for(node_t *i=head; i!=NULL; i=i->next){
- if(i->element < durchschnitt){
- temp += i->element;
- }
- }
- printf("%.2f", temp);
- for(node_t *i=head; i!=NULL; i=i->next){
- head=remove_first(head);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment