Thursday 30 April 2020

C program to check prime number of a given number

C Program to Check Whether a Number is Prime or Not


Here is a simple understanding about prime number ,what is prime number ,how can we find prime number in easy way and how to code for finding prime number in c.
let's first see what is prime number:
..Prime Number :  Any number which is only divisible by 1 and itself ,is defined as prime number .We can say the prime number have only two factors i.e 1 and itself.
Ex. - 2,3,,5,7,11.......etc.
Only 2 is the number which is prime as well as even number .

Method to find Number is prime or not :
  • step 1:- find the all the factors of the given number .                                                                                     Ex. we have two  numbers 91 and 17 ,now find the factors                                                                      factors of 91 are 1,7,13,91  and that of 17 are 1 & 17. 
  • step 2 : Check the number of factors of the given number                                                                               In the above example we have taken there are 4 factors in case of 91                                           whereas only 2  factors in case of 17.                                                                                                          
  • step 3 : If the number of factors are more than 2 then it is not a prime number and if it                                 has only two factors it is prime number .                                                                                       so in the above example 91 is not a prime number                                                                            whereas 17 is prime number.   
   let's try to find which of the following are prime number
          43, 23, 56, 89, 103, 11, 71, 28, 9, 98, 203, 345, 7, 93, 107, 67, 83. 

Well, now we will see how to code these concept through programming language .....

//Finding Prime number                                                                                                                 
1. #include<stdio.h>                                                                                                                        
2. int main()                                                                                                                                      
3. {                                                                                                                                                     
4.   int a,flag=0;                                                                                                                                
5.   printf("Enter any number:");                                                                                                  
6.    scanf("%d",&a);                                                                                                                       
7.   for(int i=2;i<a;i++)                                                                                                                     
8.   {                                                                                                                                                    
9.        if(a%i==0)                                                                                                                              
10.       {                                                                                                                                              
11.          printf("Number is not a prime ");                                                                                   
12.          flag=1;                                                                                                                                 
13.         break;                                                                                                                                   
14.        }                                                                                                                                              
15.    }                                                                                                                                                  
16.   if(flag==0)                                                                                                                                  
17.   {                                                                                                                                                   
18.       printf("Number is a prime ");                                                                                             
19.    }                                                                                                                                                  
20.    return 0;                                                                                                                                    
21.  }                                                                                                                                                    


Execution process :  
First cursor go to header file and then main function will  call. Here we  take input as a number 
from user ,now control check the factors of that number if any of the number between 2 to given 
number divide that number so it return flag =1 then break statement will execute and control will
stop executing further .
If non of the number (between 2 and given number i.e i) is such that if(a%i==0) so control move 
out and second if condition will execute .Since flag!=1 then it will remain 0 and that's why if condition will execute .







Monday 27 April 2020

1.Periodic Table (Classification)

classification of periodic table

Here we will learn about periodic table in simple language .We all are familiar with the different type of elements which has different property .Can you ever thought why we study the classification of these elements ?  let's find its answer ...

Need of Classification : In order to systematic study of elements we need to classify elements on the basis of their properties.

"hence periodic table may be defined as the arrangement of element on the basis of their properties." 
          Antoine lavoisier was the first scientist who classified elements into metal and non-metal but later on this classification was failed in case of metalloids. 

Properties of metal 

1. Metals are hard and having high melting and boiling point .
2. Metals have metallic lustre.
3. Metals conduct heat and electricity.
4. Metals are malleable and ductile.
5. Metals produces sound when strike another metal. 

Well, now we are going to move to the definition of periodic table 

Periodic Table : It is a synthetic arrangement of element in the tabular form to study the physical and chemical property.

1.Lavoisier Classification 

He classify the element into metal and non-metal form. This classification was based on certain distinctive physical properties such as hardness, ductile, conductance malleability and luster. On the basis of these properties, sodium and lead were classed together as belonging to the group of metals.
Lavoisier classification was not applicable on general property.So it is not much important for us.

Now we are moving to another classification given by Dobereiner.

2.Dobereiner triad (1815-1829)

According to dobereiner tried the set of three elements put together in the same group whose physical and chemical property are same.
for example :   Cl       Br      I
                      35.5     80    127
It was a good approach in classification but not the successful step.
Now we're moving to another classification.

3.Newland's Law of Octet

Newland classify the periodic table on the basis of musical note in which every eight element will repeat its physical and chemical property.
     Sa          Re         Ga         Ma         Pa          Dha           Ni
     Li            Be          B            C          N             O               F
     Na          Mg         Al            Si          P             S               Cl
     K            Ca        ------->

But it is not valid for next more so we just know it for general knowledge.

4.Lother Mayer 

He classify the periodic table on the basis of atomic volume i.e V= m/D (here m is mass of the element and D is the density of that elements).
This classification was applicable for physical property of the element.
*The pick of the curve is occupied by alkali metal ( Li,Na,K,Rb,Sc).
The minima of the curve is occupied by transition metal ( Mn, Cr, Fe, Co, Ni ) .
     Here is a graph represent the Lother Mayer's classification--


Lother_Mayer_graph
Lother Mayer's graph

The descending line represent the alkaline earth metal ( Be, Mg, Ca ) whereas ascending line represent halogen ( F, Cl, Br, I ).
Here important note is this curve is not useful for chemical property. 


5.Mendeleev's Periodic Table (1869)

Mendeleev classified the elements on the basis of atomic mass of the elements and it was a good approach that gives idea to design the modern periodic table.
Periodic law : "According to Mendeleev's the physical and chemical properties of the elements are the periodic function of atomic mass."
Mendeleev defined the vertical column as the group in which element will have the same physical and chemical property.

   I                H
     II
    III
     IV
      V
   VI
    VII
  VIII

Li

Be

B


N

O



Na

Mg

Al                           

Si

P

S

Cl 

Fe  Co  Ni

K      Cu

Ca    Zn

...... 

.....     Ti

As       V

Se       Cr

Br     Mn 



Rb    Ag

Sr     Cd

In        Y  

Sn        Zr

Sb     Nb 

Te      .... 




Cs     Au

Ba    Hg

Tl      La*
  
Pb       Hf

Bi       Ta

Po





Mendeleev's periodic table was classified into 8th vertical column on the basis of valency of the elements.

Drawback of Mendeleev's periodic table

1.Position of hydrogen : In the Mendeleev's periodic table the position of the hydrogen is controversial .Some of the properties of hydrogen are similar as 1st group as well as some of the properties are similar to 7th group of the table.

2.Anomalous Pair : In Mendeleev's periodic table ,some of the element having lower atomic weight is placed after the element having higher atomic weight.
for example ---    Te             I
                        127.6         127

3.Some of the transition metal are placed together with different element having different physical and chemical property.
      Ex.  -  Cu,   Ag,  Au  are placed together with alkali metal.

4.Their is no explanation for the position of isotope in the periodic table.

5.Some of the element which have the same property are separated in the Mendeleev's periodic table .
  Ex. --  Ba  and Pb

6.No justification about the position of lanthanide and actinide.  

Almost Mendeleev gave the basic idea to form a periodic table and so it is important to understand the Mendeleev's classification before go further.

6.Modified Periodic Table of Mendeleev or Modern Periodic Table




Go further to continue this topic by following link:
         https://shrischool.blogspot.com/2020/05/modern-periodic-table.html


Saturday 4 April 2020

How to code mean deviation and standard deviation with c programming

How to calculate mean 


Let we have some observation :- 12, 21, 9, 5, 7, 54
Their some is 12+ 21+ 9+ 5+ 7+ 54= 108  .and  we have total no of given data is 6.
So the mean of the given data is 108 ÷ 6 =18.

Formula of Mean
Mean of a given data


Mean Deviation:
Mean deviation of an observation is arithmetic meanof it's values from a central value.

⇾Mean deviation from mean
⇾Mean deviation from median 
⇾Mean deviation from mode
        x=x1, x2............... xn
             suppose mean of the given data = A

so,  deviation=di=Xi-A


As we discussed in above example how to get mean of a given data  i.e A=18
    so now we want to find out deviation of the given data--
    here  x1=12 , x2=21 ,  x3=9 , x4=5 ,  x5=7 ,  x6=54

d1 = 12-18 = -6 ,   d2= 21-18=3 ,   d3=9-18=-9 ,   d4=5-18=-13 ,  d5=7-18=-11 , d6=54-18=26.

Mean deviation of the given data is find using given formula:
Standard deviation formulla
mean deviation

here n=no. of data ,  di=deviation , A=mean of the data


simply we can see:--
How to find mean deviation in simple way
mean deviation in simple form

So now from given data
       

                                            

Variance: 
Variance of a values of a variate is arithmetic mean of square of deviation of it's values from arithmetic mean of the variable.
Variance of variable x is denoted by σx or V(x).  
   
Add caption

Now from given data  12,21,9,5,7,54 we have to find mean of square and square of their mean -     
How to find square of mean
Mean of square value and square of mean 
          
so ,  V(x)= 609.3333- 324 =285.33    



 # Standard deviation:

positive square root of variance of a variate is defined as std deviation.                                               
  standard deviation formula
standard deviation

Now from above example standard deviation =



Now we will see how to code for standard deviation through 'c'


  1#include<stdio.h>
  2. #include<math.h>
  3. int main( )
  4. {
  5.  int sum;
  6.  float avg,sd;
  7. stddev(&sum,&avg,&sd);
  8. printf("sum=%d ,average=%f,standard
      deviation=%f",sum,avg,sd);
  9.  }

 10. stddev(int *sum,float *avg,float *sd)
 11. {
 12.  int a,b,c,d,e;
 13.  printf("Enter five integers: ");
 14.  scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
 15.  *sum=a+b+c+d+e;
 16. *avg=*sum/5;
 18. *sd=sqrt ((a*a+b*b+c*c+d*d+e*e)/5)-(*avg)*(*avg));
19.   }

//Execution process:
Here we use  #include<math.h> because mathh is a header file in the standard library of the C programming language designed for basic mathematical operations. ... 
Mathematical library functions that operate on integers, such as abs , labs , div , and ldiv , are instead specified in the stdlib. h header. Here we use because of square root.
Here we use concept of pointer and passe the address of arguments and use basic coding
knowledge to implement the mathematical formula into code.                                         
                                                           







Periodic properties ( types of bonds)

Why we study periodic properties Here we will continue periodicity of a periodic table . In the last post we have seen the important conc...