SabirSazzad

Fardin Project Preodic Table

Feb 23rd, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.81 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3.  
  4. struct Atom
  5. {
  6.     char *Symbol;
  7.     int Number;
  8.     char *Detail;
  9.  
  10. };
  11.  
  12. int main()
  13. {
  14.    struct Atom atom[5];
  15.  
  16.    atom[0].Symbol = "H";
  17.    atom[0].Number = 1;
  18.    atom[0].Detail = " Name Hydrogen, Atomic Symbol H & Atomic Number 1";
  19.  
  20.    atom[1].Symbol = "He";
  21.    atom[1].Number = 2;
  22.    atom[1].Detail = " Name Helium, Atomic Symbol He & Atomic Number 2";
  23.  
  24.    atom[2].Symbol = "Li";
  25.    atom[2].Number = 3;
  26.    atom[2].Detail = " Name Lithium, Atomic Symbol Li & Atomic Number 3";
  27.  
  28.    atom[3].Symbol = "Be";
  29.    atom[3].Number = 4;
  30.    atom[3].Detail = " Name Beryllium, Atomic Symbol Be & Atomic Number 4";
  31.  
  32.    atom[4].Symbol = "B";
  33.    atom[4].Number = 5;
  34.    atom[4].Detail = " Name Boron, Atomic Symbol B & Atomic Number 5";
  35.  
  36.    int i,x=0,choice,num;
  37.    char sym[20];
  38.    printf("For Search by Atomic Number press 1 & For Search By Atomic Symbol press 2\n\n");
  39.    scanf("%d",&choice);
  40.  
  41.    if(choice == 1)
  42.    {
  43.        printf("Input Atomic Number: \n");
  44.        scanf("%d",&num);
  45.        for(i=0; i<5; i++)
  46.        {
  47.            if(num == atom[i].Number)
  48.            {
  49.                printf("Detail for the atom: %s\n",atom[i].Detail);
  50.                x=1;
  51.            }
  52.        }
  53.        if(x==0)
  54.        {
  55.            printf("Detail not Available\n");
  56.            x=0;
  57.        }
  58.    }
  59.    else if(choice == 2)
  60.    {
  61.        printf("Input Atomic Symbol: \n");
  62.        scanf("%s",sym);
  63.        for(i=0; i<5; i++)
  64.        {
  65.            if(strcmp(sym,atom[i].Symbol)==0)
  66.            {
  67.                printf("Detail for the atom: %s\n",atom[i].Detail);
  68.                x=1;
  69.            }
  70.        }
  71.        if(x==0)
  72.        {
  73.            printf("Detail not Available\n");
  74.            x=0;
  75.        }
  76.    }
  77.    else
  78.    {
  79.        printf("Wrong Input\n");
  80.    }
  81.  
  82.    return 0;
  83.  
  84. }
Advertisement
Add Comment
Please, Sign In to add comment