SlideShare a Scribd company logo
1 of 23
Introduction to C
     Workshop India
     Wilson Wingston Sharon
     wingston.sharon@gmail.com
Writing the first program
#include<stdio.h>
int main()
{
   printf(“Hello”);
   return 0;
}

   This program prints Hello on the screen when we
    execute it
Header files
   The files that are specified in the include section is
    called as header file
   These are precompiled files that has some functions
    defined in them
   We can call those functions in our program by
    supplying parameters
   Header file is given an extension .h
   C Source file is given an extension .c
Main function

   This is the entry point of a program
   When a file is executed, the start point is the main
    function
   From main function the flow goes as per the
    programmers choice.
   There may or may not be other functions written by
    user in a program
   Main function is compulsory for any c program
Comments in C
   Single line comment
     // (double slash)
     Termination of comment is by pressing enter key

   Multi line comment
    /*….
    …….*/
    This can span over to multiple lines
Data types in C
   Primitive data types
     int,   float, double, char
   Aggregate data types
     Arrays come under this category
     Arrays can contain collection of int or float or char or
      double data
   User defined data types
     Structures   and enum fall under this category.
Variables
   Variables are data that will keep on changing
   Declaration
    <<Data type>> <<variable name>>;
    int a;
   Definition
    <<varname>>=<<value>>;
    a=10;
   Usage
    <<varname>>
    a=a+1;   //increments the value of a by 1
Operators

   Arithmetic (+,-,*,/,%)
   Relational (<,>,<=,>=,==,!=)
   Logical (&&,||,!)
   Bitwise (&,|)
   Assignment (=)
   Compound assignment(+=,*=,-=,/=,%=,&=,|=)
   Shift (right shift >>, left shift <<)
Variable names- Rules
   Should not be a reserved word like int etc..
   Should start with a letter or an underscore(_)
   Can contain letters, numbers or underscore.
   No other special characters are allowed including
    space
   Variable names are case sensitive
    A   and a are different.
Input and Output
   Input
     scanf(“%d”,&a);

     Gets an integer value from the user and stores it under
      the name “a”
   Output
     printf(“%d”,a)

     Prints   the value present in variable a on the screen
Task01- I/O
Write a program to accept 3 numbers a , b and c as
coefficients of the quadratic equation
              ax2 + bx + c = 0
And output the solution.

Hint:
6.There will be two answers for every input combination.

7.Look in a math textbook for the solution formula.
For loops
   The syntax of for loop is
    for(initialisation;condition checking;increment)
    {
      set of statements
    }
    Eg: Program to print Hello 10 times
    for(I=0;I<10;I++)
    {
      printf(“Hello”);
    }
While loop
     The syntax for while loop
      while(condn)
      {
            statements;
      }
Eg:
      a=10;
      while(a != 0)               Output: 10987654321
      {
            printf(“%d”,a);
            a--;
      }
Do While loop
   The syntax of do while loop
    do
    {
       set of statements
    }while(condn);

    Eg:
    i=10;                         Output:
    do                            10987654321
    {
       printf(“%d”,i);
       i--;
    }while(i!=0)
Task02 - loops
   Write a program to identify which day ( sat – fri) a
    particular given date (e.g. : 3/3/2015) falls upon.

   Hint:
    http://en.wikipedia.org/wiki/Zeller%27s_congruence

   Read through the algorithm and implement it.
   You can make your own algorithm and get bonus
    marks.
Conditional statements
if (condition)
{
   stmt 1;       //Executes if Condition is true
}
else
{
   stmt 2;       //Executes if condition is false
}
Conditional statement

switch(var)
{
case 1: //if var=1 this case executes
                stmt;
                break;
case 2: //if var=2 this case executes
                stmt;
                break;
default:        //if var is something else this will execute
                stmt;
}
Functions and Parameters
 Syntax of function
Declaration section
<<Returntype>> funname(parameter list);
Definition section
<<Returntype>> funname(parameter list)
{
  body of the function
}
Function Call
Funname(parameter);
Example function
#include<stdio.h>
void fun(int a);     //declaration
int main()
{
   fun(10);                 //Call
}
void fun(int x)      //definition
{
   printf(“%d”,x);
}
Task03 - Primality
   Write a function to check if a given number is prime
    or not.

   http://en.wikipedia.org/wiki/Prime_number

   Try and implement at least 2 algorithms and check
    which one returns faster.
   Use this for time stamping :
    http://www.chemie.fu-berlin.de/chemnet/use/info/libc/
Arrays
   Arrays fall under aggregate data type
   Aggregate – More than 1
   Arrays are collection of data that belong to same
    data type
   Arrays are collection of homogeneous data
   Array elements can be accessed by its position in
    the array called as index
Arrays
   Array index starts with zero
   The last index in an array is num – 1 where num is the
    no of elements in a array
   int a[5] is an array that stores 5 integers
   a[0] is the first element where as a[4] is the fifth
    element
   We can also have arrays with more than one
    dimension
   float a[5][5] is a two dimensional array. It can store
    5x5 = 25 floating point numbers
   The bounds are a[0][0] to a[4][4]
Task04 - Arrays
Produce a spiral array. A spiral array is a square arrangement
of the first N2 natural numbers, where the numbers increase
sequentially as you go around the edges of the array spiralling
inwards.
For example, given 5, produce this array:

 0 1 2 3 4
15 16 17 18 5
14 23 24 19 6
13 22 21 20 7
12 11 10 9 8

More Related Content

What's hot

What's hot (20)

Learn C
Learn CLearn C
Learn C
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Data types in C
Data types in CData types in C
Data types in C
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
 
Control Statement programming
Control Statement programmingControl Statement programming
Control Statement programming
 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programming
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programming
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
Looping in C
Looping in CLooping in C
Looping in C
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
c-programming
c-programmingc-programming
c-programming
 
Function in C program
Function in C programFunction in C program
Function in C program
 
Functions in C
Functions in CFunctions in C
Functions in C
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
 
C programming
C programmingC programming
C programming
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++
 

Viewers also liked

Semiconductors summary
Semiconductors summarySemiconductors summary
Semiconductors summary
radebethapi
 
61739515 functional-english-grammar
61739515 functional-english-grammar61739515 functional-english-grammar
61739515 functional-english-grammar
Hina Honey
 
How to Develop Writing Skill
How to Develop Writing SkillHow to Develop Writing Skill
How to Develop Writing Skill
Rajeev Ranjan
 

Viewers also liked (20)

3 intro basic_elements
3 intro basic_elements3 intro basic_elements
3 intro basic_elements
 
Semiconductors summary
Semiconductors summarySemiconductors summary
Semiconductors summary
 
C fundamentals
C fundamentalsC fundamentals
C fundamentals
 
Physics 2 (Modern Physics)
Physics 2 (Modern Physics)Physics 2 (Modern Physics)
Physics 2 (Modern Physics)
 
What is c
What is cWhat is c
What is c
 
Basic Elements of Java
Basic Elements of JavaBasic Elements of Java
Basic Elements of Java
 
61739515 functional-english-grammar
61739515 functional-english-grammar61739515 functional-english-grammar
61739515 functional-english-grammar
 
Computer Applications - The Basic Computer Networking
Computer Applications - The Basic Computer NetworkingComputer Applications - The Basic Computer Networking
Computer Applications - The Basic Computer Networking
 
Changing structure of family
Changing structure of familyChanging structure of family
Changing structure of family
 
How to improve english writing skill
How to improve english writing skillHow to improve english writing skill
How to improve english writing skill
 
Programming in C Basics
Programming in C BasicsProgramming in C Basics
Programming in C Basics
 
Modern Physics
Modern PhysicsModern Physics
Modern Physics
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
 
Semiconductors
SemiconductorsSemiconductors
Semiconductors
 
PART II.3 - Modern Physics
PART II.3 - Modern PhysicsPART II.3 - Modern Physics
PART II.3 - Modern Physics
 
Basic c++ programs
Basic c++ programsBasic c++ programs
Basic c++ programs
 
Basic c programming and explanation PPT1
Basic c programming and explanation PPT1Basic c programming and explanation PPT1
Basic c programming and explanation PPT1
 
How to Develop Writing Skill
How to Develop Writing SkillHow to Develop Writing Skill
How to Develop Writing Skill
 
Electricity
ElectricityElectricity
Electricity
 
INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMING
 

Similar to Introduction to Basic C programming 01

1584503386 1st chap
1584503386 1st chap1584503386 1st chap
1584503386 1st chap
thuhiendtk4
 
Dti2143 chapter 5
Dti2143 chapter 5Dti2143 chapter 5
Dti2143 chapter 5
alish sha
 

Similar to Introduction to Basic C programming 01 (20)

C intro
C introC intro
C intro
 
Programming in C (part 2)
Programming in C (part 2)Programming in C (part 2)
Programming in C (part 2)
 
An imperative study of c
An imperative study of cAn imperative study of c
An imperative study of c
 
CHAPTER 5
CHAPTER 5CHAPTER 5
CHAPTER 5
 
2. operator
2. operator2. operator
2. operator
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
 
Functions struct&union
Functions struct&unionFunctions struct&union
Functions struct&union
 
1584503386 1st chap
1584503386 1st chap1584503386 1st chap
1584503386 1st chap
 
Sample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.SivakumarSample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.Sivakumar
 
2 EPT 162 Lecture 2
2 EPT 162 Lecture 22 EPT 162 Lecture 2
2 EPT 162 Lecture 2
 
Fundamentals of computer programming by Dr. A. Charan Kumari
Fundamentals of computer programming by Dr. A. Charan KumariFundamentals of computer programming by Dr. A. Charan Kumari
Fundamentals of computer programming by Dr. A. Charan Kumari
 
the refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptxthe refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptx
 
Lecture 9- Control Structures 1
Lecture 9- Control Structures 1Lecture 9- Control Structures 1
Lecture 9- Control Structures 1
 
Unit 1
Unit 1Unit 1
Unit 1
 
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4
 
Storage classes arrays & functions in C Language
Storage classes arrays & functions in C LanguageStorage classes arrays & functions in C Language
Storage classes arrays & functions in C Language
 
Array Cont
Array ContArray Cont
Array Cont
 
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4
 
Programming in C
Programming in CProgramming in C
Programming in C
 
Dti2143 chapter 5
Dti2143 chapter 5Dti2143 chapter 5
Dti2143 chapter 5
 

More from Wingston

03 layouts & ui design - Android
03   layouts & ui design - Android03   layouts & ui design - Android
03 layouts & ui design - Android
Wingston
 
Linux – an introduction
Linux – an introductionLinux – an introduction
Linux – an introduction
Wingston
 
Introduction to the Arduino
Introduction to the ArduinoIntroduction to the Arduino
Introduction to the Arduino
Wingston
 
4.content mgmt
4.content mgmt4.content mgmt
4.content mgmt
Wingston
 
8 Web Practices for Drupal
8  Web Practices for Drupal8  Web Practices for Drupal
8 Web Practices for Drupal
Wingston
 
7 Theming in Drupal
7 Theming in Drupal7 Theming in Drupal
7 Theming in Drupal
Wingston
 
6 Special Howtos for Drupal
6 Special Howtos for Drupal6 Special Howtos for Drupal
6 Special Howtos for Drupal
Wingston
 
5 User Mgmt in Drupal
5 User Mgmt in Drupal5 User Mgmt in Drupal
5 User Mgmt in Drupal
Wingston
 

More from Wingston (20)

OpenCV @ Droidcon 2012
OpenCV @ Droidcon 2012OpenCV @ Droidcon 2012
OpenCV @ Droidcon 2012
 
05 content providers - Android
05   content providers - Android05   content providers - Android
05 content providers - Android
 
04 activities - Android
04   activities - Android04   activities - Android
04 activities - Android
 
03 layouts & ui design - Android
03   layouts & ui design - Android03   layouts & ui design - Android
03 layouts & ui design - Android
 
02 hello world - Android
02   hello world - Android02   hello world - Android
02 hello world - Android
 
01 introduction & setup - Android
01   introduction & setup - Android01   introduction & setup - Android
01 introduction & setup - Android
 
OpenCV with android
OpenCV with androidOpenCV with android
OpenCV with android
 
C game programming - SDL
C game programming - SDLC game programming - SDL
C game programming - SDL
 
C programming - Pointers
C programming - PointersC programming - Pointers
C programming - Pointers
 
Linux – an introduction
Linux – an introductionLinux – an introduction
Linux – an introduction
 
Embedded linux
Embedded linuxEmbedded linux
Embedded linux
 
04 Arduino Peripheral Interfacing
04   Arduino Peripheral Interfacing04   Arduino Peripheral Interfacing
04 Arduino Peripheral Interfacing
 
03 analogue anrduino fundamentals
03   analogue anrduino fundamentals03   analogue anrduino fundamentals
03 analogue anrduino fundamentals
 
02 General Purpose Input - Output on the Arduino
02   General Purpose Input -  Output on the Arduino02   General Purpose Input -  Output on the Arduino
02 General Purpose Input - Output on the Arduino
 
Introduction to the Arduino
Introduction to the ArduinoIntroduction to the Arduino
Introduction to the Arduino
 
4.content mgmt
4.content mgmt4.content mgmt
4.content mgmt
 
8 Web Practices for Drupal
8  Web Practices for Drupal8  Web Practices for Drupal
8 Web Practices for Drupal
 
7 Theming in Drupal
7 Theming in Drupal7 Theming in Drupal
7 Theming in Drupal
 
6 Special Howtos for Drupal
6 Special Howtos for Drupal6 Special Howtos for Drupal
6 Special Howtos for Drupal
 
5 User Mgmt in Drupal
5 User Mgmt in Drupal5 User Mgmt in Drupal
5 User Mgmt in Drupal
 

Recently uploaded

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 

Recently uploaded (20)

Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 

Introduction to Basic C programming 01

  • 1. Introduction to C Workshop India Wilson Wingston Sharon wingston.sharon@gmail.com
  • 2. Writing the first program #include<stdio.h> int main() { printf(“Hello”); return 0; }  This program prints Hello on the screen when we execute it
  • 3. Header files  The files that are specified in the include section is called as header file  These are precompiled files that has some functions defined in them  We can call those functions in our program by supplying parameters  Header file is given an extension .h  C Source file is given an extension .c
  • 4. Main function  This is the entry point of a program  When a file is executed, the start point is the main function  From main function the flow goes as per the programmers choice.  There may or may not be other functions written by user in a program  Main function is compulsory for any c program
  • 5. Comments in C  Single line comment  // (double slash)  Termination of comment is by pressing enter key  Multi line comment /*…. …….*/ This can span over to multiple lines
  • 6. Data types in C  Primitive data types  int, float, double, char  Aggregate data types  Arrays come under this category  Arrays can contain collection of int or float or char or double data  User defined data types  Structures and enum fall under this category.
  • 7. Variables  Variables are data that will keep on changing  Declaration <<Data type>> <<variable name>>; int a;  Definition <<varname>>=<<value>>; a=10;  Usage <<varname>> a=a+1; //increments the value of a by 1
  • 8. Operators  Arithmetic (+,-,*,/,%)  Relational (<,>,<=,>=,==,!=)  Logical (&&,||,!)  Bitwise (&,|)  Assignment (=)  Compound assignment(+=,*=,-=,/=,%=,&=,|=)  Shift (right shift >>, left shift <<)
  • 9. Variable names- Rules  Should not be a reserved word like int etc..  Should start with a letter or an underscore(_)  Can contain letters, numbers or underscore.  No other special characters are allowed including space  Variable names are case sensitive A and a are different.
  • 10. Input and Output  Input  scanf(“%d”,&a);  Gets an integer value from the user and stores it under the name “a”  Output  printf(“%d”,a)  Prints the value present in variable a on the screen
  • 11. Task01- I/O Write a program to accept 3 numbers a , b and c as coefficients of the quadratic equation ax2 + bx + c = 0 And output the solution. Hint: 6.There will be two answers for every input combination. 7.Look in a math textbook for the solution formula.
  • 12. For loops  The syntax of for loop is for(initialisation;condition checking;increment) { set of statements } Eg: Program to print Hello 10 times for(I=0;I<10;I++) { printf(“Hello”); }
  • 13. While loop  The syntax for while loop while(condn) { statements; } Eg: a=10; while(a != 0) Output: 10987654321 { printf(“%d”,a); a--; }
  • 14. Do While loop  The syntax of do while loop do { set of statements }while(condn); Eg: i=10; Output: do 10987654321 { printf(“%d”,i); i--; }while(i!=0)
  • 15. Task02 - loops  Write a program to identify which day ( sat – fri) a particular given date (e.g. : 3/3/2015) falls upon.  Hint: http://en.wikipedia.org/wiki/Zeller%27s_congruence  Read through the algorithm and implement it.  You can make your own algorithm and get bonus marks.
  • 16. Conditional statements if (condition) { stmt 1; //Executes if Condition is true } else { stmt 2; //Executes if condition is false }
  • 17. Conditional statement switch(var) { case 1: //if var=1 this case executes stmt; break; case 2: //if var=2 this case executes stmt; break; default: //if var is something else this will execute stmt; }
  • 18. Functions and Parameters  Syntax of function Declaration section <<Returntype>> funname(parameter list); Definition section <<Returntype>> funname(parameter list) { body of the function } Function Call Funname(parameter);
  • 19. Example function #include<stdio.h> void fun(int a); //declaration int main() { fun(10); //Call } void fun(int x) //definition { printf(“%d”,x); }
  • 20. Task03 - Primality  Write a function to check if a given number is prime or not.  http://en.wikipedia.org/wiki/Prime_number  Try and implement at least 2 algorithms and check which one returns faster.  Use this for time stamping : http://www.chemie.fu-berlin.de/chemnet/use/info/libc/
  • 21. Arrays  Arrays fall under aggregate data type  Aggregate – More than 1  Arrays are collection of data that belong to same data type  Arrays are collection of homogeneous data  Array elements can be accessed by its position in the array called as index
  • 22. Arrays  Array index starts with zero  The last index in an array is num – 1 where num is the no of elements in a array  int a[5] is an array that stores 5 integers  a[0] is the first element where as a[4] is the fifth element  We can also have arrays with more than one dimension  float a[5][5] is a two dimensional array. It can store 5x5 = 25 floating point numbers  The bounds are a[0][0] to a[4][4]
  • 23. Task04 - Arrays Produce a spiral array. A spiral array is a square arrangement of the first N2 natural numbers, where the numbers increase sequentially as you go around the edges of the array spiralling inwards. For example, given 5, produce this array: 0 1 2 3 4 15 16 17 18 5 14 23 24 19 6 13 22 21 20 7 12 11 10 9 8

Editor's Notes

  1. We can also declare and define a variable in single shot like this. int a=10;
  2. Format specifiers %d is the format specifier. This informs to the compiler that the incoming value is an integer value. Other data types can be specified as follows: %c – character %f – float %lf – double %s – character array (string) Printf and scanf are defined under the header file stdio.h
  3. While – Entry controlled loop Do While – Exit controlled loop