Advertisement
LilChicha174

Untitled

Mar 23rd, 2022
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.96 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. #define N -1000000000
  6.  
  7. struct Node {
  8.     int n;
  9.     struct Node *next;
  10. };
  11.  
  12. struct Node *createNode(int n) {
  13.     struct Node *elem = (struct Node *) malloc(sizeof(struct Node));
  14.     elem->n = n;
  15.     elem->next = NULL;
  16.     return elem;
  17. };
  18.  
  19. int max_elem(struct Node *head) {
  20.     int max = N;
  21.     while(head!=NULL){
  22.         if(head->n > max){
  23.             max = head->n;
  24.         }
  25.         head = head->next;
  26.     }
  27.     return max;
  28. }
  29.  
  30. int main() {
  31.     char end = ' ';
  32.     int n;
  33.     struct Node *head;
  34.     struct Node *elem;
  35.     struct Node *prev;
  36.     for (int i = 0; i < 10; i++) {
  37.         scanf("%d%c", &n, &end);
  38.         elem = createNode(n);
  39.         if (i == 0) {
  40.             head = elem;
  41.             prev = head;
  42.             continue;
  43.         }
  44.         prev->next = elem;
  45.         prev = elem;
  46.         if (end == '\n')
  47.             break;
  48.     }
  49.     printf("%d", max_elem(head));
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement