SlideShare a Scribd company logo
3
Most read
8
Most read
21
Most read
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 (20)

PPTX
Data types in c++
Venkata.Manish Reddy
 
PPT
RECURSION IN C
v_jk
 
PPTX
Data Types and Variables In C Programming
Kamal Acharya
 
PPTX
Functions in c++
Rokonuzzaman Rony
 
PDF
Introduction to c++ ppt 1
Prof. Dr. K. Adisesha
 
PPTX
File in C language
Manash Kumar Mondal
 
PPTX
Array Introduction One-dimensional array Multidimensional array
imtiazalijoono
 
PPT
C presentation book
krunal1210
 
PPTX
Array Of Pointers
Sharad Dubey
 
PPSX
INTRODUCTION TO C PROGRAMMING
Abhishek Dwivedi
 
PPT
structure and union
student
 
PPTX
Command line arguments
Ashok Raj
 
PPTX
C if else
Ritwik Das
 
PDF
Datatypes in python
eShikshak
 
PPTX
Call by value
Dharani G
 
PPTX
Functions in C
Kamal Acharya
 
PDF
Class and Objects in Java
Spotle.ai
 
PPTX
Unit 2. Elements of C
Ashim Lamichhane
 
PPTX
Pointers in c++
Vineeta Garg
 
PPTX
Functions in C
Shobhit Upadhyay
 
Data types in c++
Venkata.Manish Reddy
 
RECURSION IN C
v_jk
 
Data Types and Variables In C Programming
Kamal Acharya
 
Functions in c++
Rokonuzzaman Rony
 
Introduction to c++ ppt 1
Prof. Dr. K. Adisesha
 
File in C language
Manash Kumar Mondal
 
Array Introduction One-dimensional array Multidimensional array
imtiazalijoono
 
C presentation book
krunal1210
 
Array Of Pointers
Sharad Dubey
 
INTRODUCTION TO C PROGRAMMING
Abhishek Dwivedi
 
structure and union
student
 
Command line arguments
Ashok Raj
 
C if else
Ritwik Das
 
Datatypes in python
eShikshak
 
Call by value
Dharani G
 
Functions in C
Kamal Acharya
 
Class and Objects in Java
Spotle.ai
 
Unit 2. Elements of C
Ashim Lamichhane
 
Pointers in c++
Vineeta Garg
 
Functions in C
Shobhit Upadhyay
 

Viewers also liked (20)

PPT
3 intro basic_elements
Docent Education
 
DOCX
Semiconductors summary
radebethapi
 
PPT
Physics 2 (Modern Physics)
Czarina Nedamo
 
PPTX
What is c
Nitesh Saitwal
 
PPT
Basic Elements of Java
Prof. Erwin Globio
 
PDF
61739515 functional-english-grammar
Hina Honey
 
PDF
Computer Applications - The Basic Computer Networking
Faindra Jabbar
 
PPTX
Changing structure of family
Polytechnic University of the Philippines
 
PPTX
How to improve english writing skill
Nusrat Jahan
 
PPTX
Programming in C Basics
Bharat Kalia
 
PPT
Modern Physics
Keith Carson
 
PPTX
Introduction to Basic C programming 02
Wingston
 
PPT
Semiconductors
Self-employed
 
PDF
PART II.3 - Modern Physics
Maurice R. TREMBLAY
 
PPTX
Basic c++ programs
harman kaur
 
PPTX
Basic c programming and explanation PPT1
Rumman Ansari
 
PPT
How to Develop Writing Skill
Rajeev Ranjan
 
PPTX
Electricity
Karl Coelho
 
PPTX
Artificial Intelligence
Javaria Chiragh
 
3 intro basic_elements
Docent Education
 
Semiconductors summary
radebethapi
 
Physics 2 (Modern Physics)
Czarina Nedamo
 
What is c
Nitesh Saitwal
 
Basic Elements of Java
Prof. Erwin Globio
 
61739515 functional-english-grammar
Hina Honey
 
Computer Applications - The Basic Computer Networking
Faindra Jabbar
 
Changing structure of family
Polytechnic University of the Philippines
 
How to improve english writing skill
Nusrat Jahan
 
Programming in C Basics
Bharat Kalia
 
Modern Physics
Keith Carson
 
Introduction to Basic C programming 02
Wingston
 
Semiconductors
Self-employed
 
PART II.3 - Modern Physics
Maurice R. TREMBLAY
 
Basic c++ programs
harman kaur
 
Basic c programming and explanation PPT1
Rumman Ansari
 
How to Develop Writing Skill
Rajeev Ranjan
 
Electricity
Karl Coelho
 
Artificial Intelligence
Javaria Chiragh
 
Ad

Similar to Introduction to Basic C programming 01 (20)

PPT
C intro
Kamran
 
PPTX
Programming in C (part 2)
Dr. SURBHI SAROHA
 
PPT
An imperative study of c
Tushar B Kute
 
PPTX
CHAPTER 5
mohd_mizan
 
PPTX
Each n Every topic of C Programming.pptx
snnbarot
 
DOC
2. operator
Shankar Gangaju
 
PPTX
C Programming Unit-2
Vikram Nandini
 
PPTX
luckfuckfunctioneekefkfejewnfiwnfnenf.pptx
TriggeredZulkar
 
DOC
Functions struct&union
UMA PARAMESWARI
 
PDF
1584503386 1st chap
thuhiendtk4
 
PPTX
Functions.pptx, programming language in c
floraaluoch3
 
PPTX
Sample for Simple C Program - R.D.Sivakumar
Sivakumar R D .
 
PDF
2 EPT 162 Lecture 2
Don Dooley
 
PPTX
Fundamentals of computer programming by Dr. A. Charan Kumari
THE NORTHCAP UNIVERSITY
 
PPTX
the refernce of programming C notes ppt.pptx
AnkitaVerma776806
 
PPT
Lecture 9- Control Structures 1
Md. Imran Hossain Showrov
 
PPTX
C and C++ programming basics for Beginners.pptx
renuvprajapati
 
PDF
Unit 1
Sowri Rajan
 
PPT
Functions and pointers_unit_4
MKalpanaDevi
 
C intro
Kamran
 
Programming in C (part 2)
Dr. SURBHI SAROHA
 
An imperative study of c
Tushar B Kute
 
CHAPTER 5
mohd_mizan
 
Each n Every topic of C Programming.pptx
snnbarot
 
2. operator
Shankar Gangaju
 
C Programming Unit-2
Vikram Nandini
 
luckfuckfunctioneekefkfejewnfiwnfnenf.pptx
TriggeredZulkar
 
Functions struct&union
UMA PARAMESWARI
 
1584503386 1st chap
thuhiendtk4
 
Functions.pptx, programming language in c
floraaluoch3
 
Sample for Simple C Program - R.D.Sivakumar
Sivakumar R D .
 
2 EPT 162 Lecture 2
Don Dooley
 
Fundamentals of computer programming by Dr. A. Charan Kumari
THE NORTHCAP UNIVERSITY
 
the refernce of programming C notes ppt.pptx
AnkitaVerma776806
 
Lecture 9- Control Structures 1
Md. Imran Hossain Showrov
 
C and C++ programming basics for Beginners.pptx
renuvprajapati
 
Unit 1
Sowri Rajan
 
Functions and pointers_unit_4
MKalpanaDevi
 
Ad

More from Wingston (20)

PPTX
OpenCV @ Droidcon 2012
Wingston
 
PPTX
05 content providers - Android
Wingston
 
PPTX
04 activities - Android
Wingston
 
PPTX
03 layouts & ui design - Android
Wingston
 
PPTX
02 hello world - Android
Wingston
 
PPTX
01 introduction & setup - Android
Wingston
 
PPTX
OpenCV with android
Wingston
 
PPTX
C game programming - SDL
Wingston
 
PPTX
C programming - Pointers
Wingston
 
PPTX
Linux – an introduction
Wingston
 
PPTX
Embedded linux
Wingston
 
PPTX
04 Arduino Peripheral Interfacing
Wingston
 
PPTX
03 analogue anrduino fundamentals
Wingston
 
PPTX
02 General Purpose Input - Output on the Arduino
Wingston
 
PPTX
Introduction to the Arduino
Wingston
 
PPTX
4.content mgmt
Wingston
 
PPTX
8 Web Practices for Drupal
Wingston
 
PPTX
7 Theming in Drupal
Wingston
 
PPTX
6 Special Howtos for Drupal
Wingston
 
PPTX
5 User Mgmt in Drupal
Wingston
 
OpenCV @ Droidcon 2012
Wingston
 
05 content providers - Android
Wingston
 
04 activities - Android
Wingston
 
03 layouts & ui design - Android
Wingston
 
02 hello world - Android
Wingston
 
01 introduction & setup - Android
Wingston
 
OpenCV with android
Wingston
 
C game programming - SDL
Wingston
 
C programming - Pointers
Wingston
 
Linux – an introduction
Wingston
 
Embedded linux
Wingston
 
04 Arduino Peripheral Interfacing
Wingston
 
03 analogue anrduino fundamentals
Wingston
 
02 General Purpose Input - Output on the Arduino
Wingston
 
Introduction to the Arduino
Wingston
 
4.content mgmt
Wingston
 
8 Web Practices for Drupal
Wingston
 
7 Theming in Drupal
Wingston
 
6 Special Howtos for Drupal
Wingston
 
5 User Mgmt in Drupal
Wingston
 

Recently uploaded (20)

PPTX
ENGlish 8 lesson presentation PowerPoint.pptx
marawehsvinetshe
 
PPTX
SD_GMRC5_Session 6AB_Dulog Pedagohikal at Pagtataya (1).pptx
NickeyArguelles
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PDF
Workbook de Inglés Completo - English Path.pdf
shityouenglishpath
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PPTX
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
PDF
Vani - The Voice of Excellence - Jul 2025 issue
Savipriya Raghavendra
 
PPTX
Introduction to Biochemistry & Cellular Foundations.pptx
marvinnbustamante1
 
PPTX
Difference between write and update in odoo 18
Celine George
 
PDF
Characteristics, Strengths and Weaknesses of Quantitative Research.pdf
Thelma Villaflores
 
PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PPTX
How to Create a Customer From Website in Odoo 18.pptx
Celine George
 
PPTX
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PDF
Introduction presentation of the patentbutler tool
MIPLM
 
PDF
Horarios de distribución de agua en julio
pegazohn1978
 
PDF
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
PDF
Is Assignment Help Legal in Australia_.pdf
thomas19williams83
 
PDF
Week 2 - Irish Natural Heritage Powerpoint.pdf
swainealan
 
ENGlish 8 lesson presentation PowerPoint.pptx
marawehsvinetshe
 
SD_GMRC5_Session 6AB_Dulog Pedagohikal at Pagtataya (1).pptx
NickeyArguelles
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
Workbook de Inglés Completo - English Path.pdf
shityouenglishpath
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
Vani - The Voice of Excellence - Jul 2025 issue
Savipriya Raghavendra
 
Introduction to Biochemistry & Cellular Foundations.pptx
marvinnbustamante1
 
Difference between write and update in odoo 18
Celine George
 
Characteristics, Strengths and Weaknesses of Quantitative Research.pdf
Thelma Villaflores
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
How to Create a Customer From Website in Odoo 18.pptx
Celine George
 
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
Introduction presentation of the patentbutler tool
MIPLM
 
Horarios de distribución de agua en julio
pegazohn1978
 
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
Is Assignment Help Legal in Australia_.pdf
thomas19williams83
 
Week 2 - Irish Natural Heritage Powerpoint.pdf
swainealan
 

Introduction to Basic C programming 01

  • 1. Introduction to C Workshop India Wilson Wingston Sharon [email protected]
  • 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

  • #8: We can also declare and define a variable in single shot like this. int a=10;
  • #11: 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
  • #15: While – Entry controlled loop Do While – Exit controlled loop