Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- struct Atom
- {
- char *Symbol;
- int Number;
- char *Detail;
- };
- int main()
- {
- struct Atom atom[5];
- atom[0].Symbol = "H";
- atom[0].Number = 1;
- atom[0].Detail = " Name Hydrogen, Atomic Symbol H & Atomic Number 1";
- atom[1].Symbol = "He";
- atom[1].Number = 2;
- atom[1].Detail = " Name Helium, Atomic Symbol He & Atomic Number 2";
- atom[2].Symbol = "Li";
- atom[2].Number = 3;
- atom[2].Detail = " Name Lithium, Atomic Symbol Li & Atomic Number 3";
- atom[3].Symbol = "Be";
- atom[3].Number = 4;
- atom[3].Detail = " Name Beryllium, Atomic Symbol Be & Atomic Number 4";
- atom[4].Symbol = "B";
- atom[4].Number = 5;
- atom[4].Detail = " Name Boron, Atomic Symbol B & Atomic Number 5";
- int i,x=0,choice,num;
- char sym[20];
- printf("For Search by Atomic Number press 1 & For Search By Atomic Symbol press 2\n\n");
- scanf("%d",&choice);
- if(choice == 1)
- {
- printf("Input Atomic Number: \n");
- scanf("%d",&num);
- for(i=0; i<5; i++)
- {
- if(num == atom[i].Number)
- {
- printf("Detail for the atom: %s\n",atom[i].Detail);
- x=1;
- }
- }
- if(x==0)
- {
- printf("Detail not Available\n");
- x=0;
- }
- }
- else if(choice == 2)
- {
- printf("Input Atomic Symbol: \n");
- scanf("%s",sym);
- for(i=0; i<5; i++)
- {
- if(strcmp(sym,atom[i].Symbol)==0)
- {
- printf("Detail for the atom: %s\n",atom[i].Detail);
- x=1;
- }
- }
- if(x==0)
- {
- printf("Detail not Available\n");
- x=0;
- }
- }
- else
- {
- printf("Wrong Input\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment