SlideShare a Scribd company logo
1 of 4
Download to read offline
First C Program
Write a program to print hello on output screen.
// Program to print Hello on output screen
#include<stdio.h>
#include<conio.h>
main()
{
clrscr(); //clear output screen
printf(“n Hello!!!”); //print hello
getch(); //remain on o/p screen till user enters
any key
Save above program as hello.c
Explanation :
1. First line is comment.
2. “stdio.h” is a standard input output header file which contains function like printf and scanf
which we are going to use in our program. As we are using these functions we need to include this
header file. # include is preprocessor directive which allows to include header files.
3. “conio.h” is console input output header file which contains function like clrscr , getch
4. printf()
Syntax :
printf(“ string”);
This function is used to print any messge on output screen.
In above program “n” is newline character which brings cursor on next line on output screen.
Whatever we write in double quotes (“ ”) will exactly get printed on output screen.
Note: Every C statements (instruction) ends with semicolon(;)
Data Types Used in 'C'
 Data type : It is a type of data which we want to use in our program . It can be of Integer ,
Real or character constanats.
Before using variable in C , we must declare it. To declare a variable we need
data type.
Data Type Storage Size Range Format
Specifier
char 1 byte -128 to 127 (for signed data)
0 to 255 (unsigned data)
%c
unsigned
char
1 byte 0 to 255 %c
signed
char
1 byte -128 to 127 %c
int 2 or 4
bytes
-32,768 to 32,767 or
-2,147,483,648 to
2,147,483,647
%d
unsigned
int
2 or 4
bytes
0 to 65,535 or 0 to
4,294,967,295
%u
short 2 bytes -32,768 to 32,767 %d
unsigned
short
2 bytes 0 to 65,535 %u
long 4 bytes -2,147,483,648 to
2,147,483,647
%ld
unsigned
long
4 bytes 0 to 4,294,967,295 %lu
float 4 byte 1.2E-38 to 3.4E+38 %f
double 8 byte 2.3E-308 to 1.7E+308 %lf
long
double
10 byte 3.4E-4932 to 1.1E+4932 %Lf
Data Types
Signed (+ve or -ve) Unsigned (always +ve)
// program to take a number as input through keyboard and display it on output screen
#include<stdio.h>
#include<conio.h>
main()
{
int num; // declaration of a variable
clrscr(); //clear output screen
printf(“n Enter any number : ”); // ask user to enter number
on o/p screen
scanf(“%d”, &num); // store entered number in variable num
printf(“n You have entered %d”, num); //retrive number
from memory location and display on screen
getch(); //remain on o/p screen till user enters any key
}
Explaination: In above program, num is a variable of type int. Using function scanf value of
variable num is stored in memory.
Syntax for scanf :
scanf(“format specifief” , &variable name);
Here , format specifier is %d for int , % f for float , %c for char (As given in
above Data type table) , & is address operator which stores data at given memory location.
e.g in above program num is a variable , whatever value we print on o/p screen that value is stored
in memory location called num.
Then using printf(); that value we are printing on output screen. So, another syntax for printf is
printf(“string + format specifiers”, list of variables);
e.g printf(“n You have entered %d”, num); in this case %d referes to variable
num. Here value of variable num is retrived from memory and printed on output screen.
Arithmetic Operators in 'C'
Arithmentic Operators :
Operator Description Example
Add + Add two variables (operands) a+b
Subtract - Subtract two variables (operands) a-b
Multiply * Multiply two variables (operands) a*b
Division / Divide two variables (operands) this operator
gives Quotient as a result of division
a/b
Modulus % Divide two variables (operands) this operator
gives Remainder as a result of division
a%d
Equal to
=
Assign value to variable on Left Hand Side
(LHS)
c= a+b
// Program using printf and scanf functions
//WAP to add two numbers and display result on output screen.
// program to add two number and display result on output screen
#include<stdio.h>
#include<conio.h>
main()
{
int a,b,c; // declaration of a variable
clrscr(); //clear output screen
printf(“n Enter two numbers : ”); // ask user to enter number
on o/p screen
scanf(“%d%d”, &a,&b); // store numbers in variable a and b
c= a+b; //addition of a and b
printf(“n Addition = %d”, c); //print addition
getch(); //remain on o/p screen till user enters any key
}

More Related Content

What's hot

C programming Lab 2
C programming Lab 2C programming Lab 2
C programming Lab 2Zaibi Gondal
 
C Programming Language Part 9
C Programming Language Part 9C Programming Language Part 9
C Programming Language Part 9Rumman Ansari
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]Abhishek Sinha
 
C programming Lab 1
C programming Lab 1C programming Lab 1
C programming Lab 1Zaibi Gondal
 
Programming fundamentals
Programming fundamentalsProgramming fundamentals
Programming fundamentalsZaibi Gondal
 
Managing input and output operations in c
Managing input and output operations in cManaging input and output operations in c
Managing input and output operations in cniyamathShariff
 
7. input and output functions
7. input and output functions7. input and output functions
7. input and output functionsWay2itech
 
Testing lecture after lec 4
Testing lecture after lec 4Testing lecture after lec 4
Testing lecture after lec 4emailharmeet
 
C programming(Part 1)
C programming(Part 1)C programming(Part 1)
C programming(Part 1)SURBHI SAROHA
 
C Programming Language Part 11
C Programming Language Part 11C Programming Language Part 11
C Programming Language Part 11Rumman Ansari
 
Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04hassaanciit
 
Core programming in c
Core programming in cCore programming in c
Core programming in cRahul Pandit
 
Functions & Procedures [7]
Functions & Procedures [7]Functions & Procedures [7]
Functions & Procedures [7]ecko_disasterz
 
Compiler Design Lab File
Compiler Design Lab FileCompiler Design Lab File
Compiler Design Lab FileKandarp Tiwari
 
Programming in C (part 2)
Programming in C (part 2)Programming in C (part 2)
Programming in C (part 2)SURBHI SAROHA
 

What's hot (20)

C programming Lab 2
C programming Lab 2C programming Lab 2
C programming Lab 2
 
Lab 1
Lab 1Lab 1
Lab 1
 
C Programming Language Part 9
C Programming Language Part 9C Programming Language Part 9
C Programming Language Part 9
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
 
C programming Lab 1
C programming Lab 1C programming Lab 1
C programming Lab 1
 
Programming fundamentals
Programming fundamentalsProgramming fundamentals
Programming fundamentals
 
Managing input and output operations in c
Managing input and output operations in cManaging input and output operations in c
Managing input and output operations in c
 
7. input and output functions
7. input and output functions7. input and output functions
7. input and output functions
 
C lab-programs
C lab-programsC lab-programs
C lab-programs
 
Testing lecture after lec 4
Testing lecture after lec 4Testing lecture after lec 4
Testing lecture after lec 4
 
88 c-programs
88 c-programs88 c-programs
88 c-programs
 
Lecture 3 c++
Lecture 3 c++Lecture 3 c++
Lecture 3 c++
 
Operators
OperatorsOperators
Operators
 
C programming(Part 1)
C programming(Part 1)C programming(Part 1)
C programming(Part 1)
 
C Programming Language Part 11
C Programming Language Part 11C Programming Language Part 11
C Programming Language Part 11
 
Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04
 
Core programming in c
Core programming in cCore programming in c
Core programming in c
 
Functions & Procedures [7]
Functions & Procedures [7]Functions & Procedures [7]
Functions & Procedures [7]
 
Compiler Design Lab File
Compiler Design Lab FileCompiler Design Lab File
Compiler Design Lab File
 
Programming in C (part 2)
Programming in C (part 2)Programming in C (part 2)
Programming in C (part 2)
 

Similar to First c program

Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Functionimtiazalijoono
 
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.pptxAnkitaVerma776806
 
Input and Output In C Language
Input and Output In C LanguageInput and Output In C Language
Input and Output In C LanguageAdnan Khan
 
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.SivakumarSivakumar R D .
 
Programming Fundamentals lecture 5
Programming Fundamentals lecture 5Programming Fundamentals lecture 5
Programming Fundamentals lecture 5REHAN IJAZ
 
Basic of c programming www.eakanchha.com
Basic of c programming www.eakanchha.comBasic of c programming www.eakanchha.com
Basic of c programming www.eakanchha.comAkanchha Agrawal
 
Chapter3
Chapter3Chapter3
Chapter3Kamran
 
Datastructure notes
Datastructure notesDatastructure notes
Datastructure notesSrikanth
 
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4MKalpanaDevi
 
C programming language for beginners
C programming language for beginners C programming language for beginners
C programming language for beginners ShreyaSingh291866
 
C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)indrasir
 
2. Data, Operators, IO.ppt
2. Data, Operators, IO.ppt2. Data, Operators, IO.ppt
2. Data, Operators, IO.pptswateerawat06
 
Function in c program
Function in c programFunction in c program
Function in c programumesh patil
 

Similar to First c program (20)

UNIT-II CP DOC.docx
UNIT-II CP DOC.docxUNIT-II CP DOC.docx
UNIT-II CP DOC.docx
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Function
 
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
 
Input and Output In C Language
Input and Output In C LanguageInput and Output In C Language
Input and Output In C Language
 
Unit1 C
Unit1 CUnit1 C
Unit1 C
 
Unit1 C
Unit1 CUnit1 C
Unit1 C
 
Programming in c
Programming in cProgramming in c
Programming in c
 
Unit-IV.pptx
Unit-IV.pptxUnit-IV.pptx
Unit-IV.pptx
 
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
 
Programming Fundamentals lecture 5
Programming Fundamentals lecture 5Programming Fundamentals lecture 5
Programming Fundamentals lecture 5
 
Basic of c programming www.eakanchha.com
Basic of c programming www.eakanchha.comBasic of c programming www.eakanchha.com
Basic of c programming www.eakanchha.com
 
Chapter3
Chapter3Chapter3
Chapter3
 
Linux_C_LabBasics.ppt
Linux_C_LabBasics.pptLinux_C_LabBasics.ppt
Linux_C_LabBasics.ppt
 
Datastructure notes
Datastructure notesDatastructure notes
Datastructure notes
 
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4
 
Introduction to Input/Output Functions in C
Introduction to Input/Output Functions in CIntroduction to Input/Output Functions in C
Introduction to Input/Output Functions in C
 
C programming language for beginners
C programming language for beginners C programming language for beginners
C programming language for beginners
 
C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)
 
2. Data, Operators, IO.ppt
2. Data, Operators, IO.ppt2. Data, Operators, IO.ppt
2. Data, Operators, IO.ppt
 
Function in c program
Function in c programFunction in c program
Function in c program
 

Recently uploaded

HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2RajaP95
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and usesDevarapalliHaritha
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZTE
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 

Recently uploaded (20)

HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and uses
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 

First c program

  • 1. First C Program Write a program to print hello on output screen. // Program to print Hello on output screen #include<stdio.h> #include<conio.h> main() { clrscr(); //clear output screen printf(“n Hello!!!”); //print hello getch(); //remain on o/p screen till user enters any key Save above program as hello.c Explanation : 1. First line is comment. 2. “stdio.h” is a standard input output header file which contains function like printf and scanf which we are going to use in our program. As we are using these functions we need to include this header file. # include is preprocessor directive which allows to include header files. 3. “conio.h” is console input output header file which contains function like clrscr , getch 4. printf() Syntax : printf(“ string”); This function is used to print any messge on output screen. In above program “n” is newline character which brings cursor on next line on output screen. Whatever we write in double quotes (“ ”) will exactly get printed on output screen. Note: Every C statements (instruction) ends with semicolon(;)
  • 2. Data Types Used in 'C'  Data type : It is a type of data which we want to use in our program . It can be of Integer , Real or character constanats. Before using variable in C , we must declare it. To declare a variable we need data type. Data Type Storage Size Range Format Specifier char 1 byte -128 to 127 (for signed data) 0 to 255 (unsigned data) %c unsigned char 1 byte 0 to 255 %c signed char 1 byte -128 to 127 %c int 2 or 4 bytes -32,768 to 32,767 or -2,147,483,648 to 2,147,483,647 %d unsigned int 2 or 4 bytes 0 to 65,535 or 0 to 4,294,967,295 %u short 2 bytes -32,768 to 32,767 %d unsigned short 2 bytes 0 to 65,535 %u long 4 bytes -2,147,483,648 to 2,147,483,647 %ld unsigned long 4 bytes 0 to 4,294,967,295 %lu float 4 byte 1.2E-38 to 3.4E+38 %f double 8 byte 2.3E-308 to 1.7E+308 %lf long double 10 byte 3.4E-4932 to 1.1E+4932 %Lf Data Types Signed (+ve or -ve) Unsigned (always +ve)
  • 3. // program to take a number as input through keyboard and display it on output screen #include<stdio.h> #include<conio.h> main() { int num; // declaration of a variable clrscr(); //clear output screen printf(“n Enter any number : ”); // ask user to enter number on o/p screen scanf(“%d”, &num); // store entered number in variable num printf(“n You have entered %d”, num); //retrive number from memory location and display on screen getch(); //remain on o/p screen till user enters any key } Explaination: In above program, num is a variable of type int. Using function scanf value of variable num is stored in memory. Syntax for scanf : scanf(“format specifief” , &variable name); Here , format specifier is %d for int , % f for float , %c for char (As given in above Data type table) , & is address operator which stores data at given memory location. e.g in above program num is a variable , whatever value we print on o/p screen that value is stored in memory location called num. Then using printf(); that value we are printing on output screen. So, another syntax for printf is printf(“string + format specifiers”, list of variables); e.g printf(“n You have entered %d”, num); in this case %d referes to variable num. Here value of variable num is retrived from memory and printed on output screen.
  • 4. Arithmetic Operators in 'C' Arithmentic Operators : Operator Description Example Add + Add two variables (operands) a+b Subtract - Subtract two variables (operands) a-b Multiply * Multiply two variables (operands) a*b Division / Divide two variables (operands) this operator gives Quotient as a result of division a/b Modulus % Divide two variables (operands) this operator gives Remainder as a result of division a%d Equal to = Assign value to variable on Left Hand Side (LHS) c= a+b // Program using printf and scanf functions //WAP to add two numbers and display result on output screen. // program to add two number and display result on output screen #include<stdio.h> #include<conio.h> main() { int a,b,c; // declaration of a variable clrscr(); //clear output screen printf(“n Enter two numbers : ”); // ask user to enter number on o/p screen scanf(“%d%d”, &a,&b); // store numbers in variable a and b c= a+b; //addition of a and b printf(“n Addition = %d”, c); //print addition getch(); //remain on o/p screen till user enters any key }