Advertisement
Guest User

dsdf

a guest
Feb 19th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.42 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. struct node
  4. {
  5.     int id;
  6.     double mark;
  7.     struct node *next;
  8. }*start=NULL;
  9.  
  10. void create()
  11. {
  12.     int i,n;
  13.     struct node *new_node,*current;
  14.     printf("Enter the number of student :");
  15.     scanf("%d",&n);
  16.     for(i=0;i<n;i++){
  17.         new_node=(struct node *)malloc(sizeof(struct node));
  18.         if(new_node==NULL){
  19.             printf("ERORE allocation\n");
  20.         }
  21.         printf("Enter the id of the student: ");
  22.         scanf("%d",&new_node->id);
  23.         printf("Enter the mark of the student: ");
  24.         scanf("%lf",&new_node->mark);
  25.         new_node->next=NULL;
  26.         if(start==NULL){
  27.             start=new_node;
  28.             current=new_node;
  29.         }
  30.         else
  31.         {
  32.             current->next=new_node;
  33.             current=new_node;
  34.  
  35.         }
  36.     }
  37.  
  38.  
  39. }
  40.  
  41. double ave()
  42. {
  43.     double sum=0,ave;
  44.     int c=0;
  45.     struct node *current;
  46.     current=start;
  47.     while(current!=NULL){
  48.         c++;
  49.         sum=sum+current->mark;
  50.         current=current->next;
  51.     }
  52.     ave=sum/(double)c;
  53.     printf("The average quiz mark is=%0.1lf\n",ave);
  54.  
  55. }
  56.  
  57. void display()
  58. {
  59.     struct node *current;
  60.     current=start;
  61.     while(current!=NULL){
  62.       printf("id-%d-%0.1lf-->",current->id,current->mark);
  63.       current=current->next;
  64.     }
  65.     printf("NULL\n");
  66. }
  67.  
  68. int main()
  69. {
  70.     create();
  71.     display();
  72.     ave();
  73.     return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement