Skip to content

Instantly share code, notes, and snippets.

@Esarve
Created October 27, 2016 04:31
Show Gist options
  • Save Esarve/bc28b1dfbda06da7c4f1ffaefa1cc12a to your computer and use it in GitHub Desktop.
Save Esarve/bc28b1dfbda06da7c4f1ffaefa1cc12a to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
typedef struct info
{
char* name;
int bng;
int eng;
int mth;
float avg;
struct info* next;
}Info;
void print(Info* ptr);
void add(Info* ptr, int a, int b, int c, char* name);
int i=0;
int main()
{
Info* start,*temp;
start=(Info*)malloc(sizeof(Info));
temp=start;
temp->next=NULL;
while (i<20)
{
int x,a,b,c;
char *name;
scanf("%d",&x);
switch(x)
{
case 1:
scanf("%d %d %d",&a,&b,&c);
getchar();
printf("\nEnter nAME: ");
gets(name);
add(start,a,b,c,name);
i++;
break;
case 2:
print(start);
break;
}
}
return 0;
}
void add(Info* ptr, int a, int b, int c, char *name)
{
while (ptr!=NULL)
{
ptr=ptr->next;
}
ptr->next=(Info*)malloc(sizeof(Info));
ptr=ptr->next;
ptr->name=name;
ptr->bng=a;
ptr->eng=b;
ptr->mth=c;
ptr->avg=(a+b+c)/3.00;
}
void print(Info* ptr)
{
if (ptr==NULL)
{
return;
}
puts(ptr->name);
print("\n");
printf("\n%d",ptr->bng);
printf("\n%d",ptr->eng);
printf("\n%d",ptr->mth);
printf("\n%f",ptr->avg);
print(ptr->next);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment