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)

History of c
History of cHistory of c
History of c
 
C tokens
C tokensC tokens
C tokens
 
Features of c language 1
Features of c language 1Features of c language 1
Features of c language 1
 
Introduction to problem solving in C
Introduction to problem solving in CIntroduction to problem solving in C
Introduction to problem solving in C
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
 
C Language
C LanguageC Language
C Language
 
Structure of a C program
Structure of a C programStructure of a C program
Structure of a C program
 
Basic Structure of C Language and Related Term
Basic Structure of C Language  and Related TermBasic Structure of C Language  and Related Term
Basic Structure of C Language and Related Term
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
Data Type in C Programming
Data Type in C ProgrammingData Type in C Programming
Data Type in C Programming
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
 
C presentation book
C presentation bookC presentation book
C presentation book
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programming
 
Programming in C Presentation upto FILE
Programming in C Presentation upto FILEProgramming in C Presentation upto FILE
Programming in C Presentation upto FILE
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
 
Scope rules : local and global variables
Scope rules : local and global variablesScope rules : local and global variables
Scope rules : local and global variables
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programming
 

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
 
Artificial Intelligence
Artificial IntelligenceArtificial Intelligence
Artificial Intelligence
 

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

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).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
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
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
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 

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