SlideShare a Scribd company logo
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

Testing lecture after lec 4
Testing lecture after lec 4Testing lecture after lec 4
Testing lecture after lec 4
emailharmeet
 
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
hassaanciit
 
Functions & Procedures [7]
Functions & Procedures [7]Functions & Procedures [7]
Functions & Procedures [7]
ecko_disasterz
 

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

Datastructure notes
Datastructure notesDatastructure notes
Datastructure notes
Srikanth
 
C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)
indrasir
 

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

Laundry management system project report.pdf
Laundry management system project report.pdfLaundry management system project report.pdf
Laundry management system project report.pdf
Kamal Acharya
 
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdfONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
Kamal Acharya
 
Online blood donation management system project.pdf
Online blood donation management system project.pdfOnline blood donation management system project.pdf
Online blood donation management system project.pdf
Kamal Acharya
 
School management system project report.pdf
School management system project report.pdfSchool management system project report.pdf
School management system project report.pdf
Kamal Acharya
 

Recently uploaded (20)

Natalia Rutkowska - BIM School Course in Kraków
Natalia Rutkowska - BIM School Course in KrakówNatalia Rutkowska - BIM School Course in Kraków
Natalia Rutkowska - BIM School Course in Kraków
 
Pharmacy management system project report..pdf
Pharmacy management system project report..pdfPharmacy management system project report..pdf
Pharmacy management system project report..pdf
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...
NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...
NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...
 
İTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering WorkshopİTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering Workshop
 
Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industries
 
Electrostatic field in a coaxial transmission line
Electrostatic field in a coaxial transmission lineElectrostatic field in a coaxial transmission line
Electrostatic field in a coaxial transmission line
 
AI for workflow automation Use cases applications benefits and development.pdf
AI for workflow automation Use cases applications benefits and development.pdfAI for workflow automation Use cases applications benefits and development.pdf
AI for workflow automation Use cases applications benefits and development.pdf
 
Laundry management system project report.pdf
Laundry management system project report.pdfLaundry management system project report.pdf
Laundry management system project report.pdf
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
 
ENERGY STORAGE DEVICES INTRODUCTION UNIT-I
ENERGY STORAGE DEVICES  INTRODUCTION UNIT-IENERGY STORAGE DEVICES  INTRODUCTION UNIT-I
ENERGY STORAGE DEVICES INTRODUCTION UNIT-I
 
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdfONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
 
ONLINE CAR SERVICING SYSTEM PROJECT REPORT.pdf
ONLINE CAR SERVICING SYSTEM PROJECT REPORT.pdfONLINE CAR SERVICING SYSTEM PROJECT REPORT.pdf
ONLINE CAR SERVICING SYSTEM PROJECT REPORT.pdf
 
shape functions of 1D and 2 D rectangular elements.pptx
shape functions of 1D and 2 D rectangular elements.pptxshape functions of 1D and 2 D rectangular elements.pptx
shape functions of 1D and 2 D rectangular elements.pptx
 
2024 DevOps Pro Europe - Growing at the edge
2024 DevOps Pro Europe - Growing at the edge2024 DevOps Pro Europe - Growing at the edge
2024 DevOps Pro Europe - Growing at the edge
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
Online blood donation management system project.pdf
Online blood donation management system project.pdfOnline blood donation management system project.pdf
Online blood donation management system project.pdf
 
School management system project report.pdf
School management system project report.pdfSchool management system project report.pdf
School management system project report.pdf
 
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdfA CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
 
NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...
NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...
NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...
 

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 }