Friday, 21 March 2014

FUNCTIONS IN C

                            FUNCTIONS

A function is a self contained block of statements that perform a task of some kind. More basically they can be called as the building blocks of C. Without function C cannot work. Beginners must have observed that every program in C has abody that begins with main(). This main() is basic function  of C. Apart from function main any body can define their own function according to their needs. An example of which is 
                                   float power(float x)
                                     {
                                             float sum;
                                             sum=x*x;
                                       }            
So here i have defined a function named power which would calculate the square of the input number.

If a program contains only one function, it  should be main() .
Lets give an example to clear concept----
                     #include<stdio.h>
                      void power()
                       {
                                     printf("I am very powerfull");
                       }
                      void main()
                     {
                                printf("hi!");
                                power();
                      }
             The output would be as----
                               
                                  hi!
                                  I am very power full

C PROGRAMMING FOR STUDENTS OF PHYSICS HONs. IN WEST BENGAL

C PROGRAMMING FOR STUDENTS OF PHYSICS HONs. IN   WEST BENGAL

 (dedicated to students of west bengal state university, calcutta university, kalyani university)

  BASICS

    c programming is included in 3rd year for physics honours students , students are either provided borland c++ or turbo c++. The programs are more or less same in both compilers , the main()body is almost same , there are only a few minor difference , the programs provided here can be tried on both of these compilers as they would work on both. Students are requested to try the programs and post for error if any in comments.

Types of programs in c

  The programs  in C are mainly for numerical methods, there are many equations which takes time to be solved by hand and paper, there are lots of datas which takes time to be calculated , so we use C to mainly ease our complication as we would procide the equations and C would compute them for us.

C is used in numerical methods for :-
1. sorting and arranging
2. integraion
3.differentiation
4.generate data for plotting graph
5.calculate mean,median,mode
6.find the solution of a series



SORTING AND ARRANGING

      Sorting means to pick up things and arrange in a desired way , we normally use bubble sorting and selection sorting. A sorting program is provided as under

   Creating an array of 1D array of any 12 integer numbers(1 to 100)taken as input and arranging them in descending order. Also the number of swaps are counted.
   

INTEGRATON

A program to integrate I=  cos(x)dx  in the limit 0 to pi(180) to determine the optimum value of h using Simpson’s 1/3 rule.


DIFFERENTIATION