SlideShare a Scribd company logo
For complete theorywithmore than100 programsof c language loginto www.eakanchha.com
Let’s start making a simple program.
1) # Write a program to print a message?
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr():
printf(“Hello. n How are you?”);
getch();
}
 First, compile program  press alt+F9. Now if no errors or warnings are found press
ctrl+F9 to run program.
 Here, stdio.h and conio.h are header files. Which contain pre-defined functions we use in
program.
 printf() is defined in stdio.h (standard input output header file).
clrscr() and getch() are defined in conio.h (console input output header file).
 printf() function allow to print set of characters written inside “”.
 clrscr() function clears output screen so that, previous outputs does not get mix with your
current output.
 getch() function holds output screen until any key is pressed to return from output
screen.
 Each program contains a main() function.
 Void is used as return type of main function. It is used with those functions which do not
return any value.
 Semi-colon (;) is used at end of every statement to terminate.
 { This represents opening of a block.
 }  This represents end of a block.
 Each block which opens must end.
 n  it is an escape sequence. We will discuss it latter in this chapter.
Output of the above program will be as:
Hello
How are you?
For complete theorywithmore than100 programsof c language loginto www.eakanchha.com
2) # Write a program to enter a number and print it?
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
printf(“enter a number”);
scanf(“%d”,&i);
printf(“n you have entered=%d”, i);
getch();
}
 int represents a data type, and I is a variable of integer type.
 %d is a format specifier. It tell which type of data scanf has to read from keyboard and
printf has to print on output screen. Here it is integer type.
 &  address of operator is used in scanf. It tells compiler, address of concerned variable
where input from keyboard has to be saved.
 An, important thing you should remember while writing any program is that, variable
should be declared always first then, write other lines of code.
For ex:
If in the above program you write it as;
Void main()
{
clrscr();
int i;
printf(“enter a number”);
scanf(“%d”,&i);
printf(“n you have entered=%d”, i);
getch();
}
As, first clrscr() is written then, variable I is declared therefore it will not work. It will give
an error “declaration is not allowed here.”
For complete theorywithmore than100 programsof c language loginto www.eakanchha.com

More Related Content

What's hot

Vp lecture 9 ararat
Vp lecture 9 araratVp lecture 9 ararat
Vp lecture 9 ararat
Saman M. Almufti
 
Write a program that accepts percentage from the user and displays its grade ...
Write a program that accepts percentage from the user and displays its grade ...Write a program that accepts percentage from the user and displays its grade ...
Write a program that accepts percentage from the user and displays its grade ...
Farwa Aqeel
 
Operators
OperatorsOperators
Operators
Allah Ditta
 
print even or odd number in c
print even or odd number in cprint even or odd number in c
print even or odd number in c
mohdshanu
 
B.Com 1year Lab programs
B.Com 1year Lab programsB.Com 1year Lab programs
B.Com 1year Lab programs
Prasadu Peddi
 
Chowtodoprogram solutions
Chowtodoprogram solutionsChowtodoprogram solutions
Chowtodoprogram solutions
Musa Gürbüz
 
1 introduction to c program
1 introduction to c program1 introduction to c program
1 introduction to c program
NishmaNJ
 
C Programming Language Part 9
C Programming Language Part 9C Programming Language Part 9
C Programming Language Part 9
Rumman Ansari
 
Input output statement in C
Input output statement in CInput output statement in C
Input output statement in C
Muthuganesh S
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
Mainak Sasmal
 
Bcsl 033 data and file structures lab s1-1
Bcsl 033 data and file structures lab s1-1Bcsl 033 data and file structures lab s1-1
Bcsl 033 data and file structures lab s1-1
Dr. Loganathan R
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
Mainak Sasmal
 
Looping statements in C
Looping statements in CLooping statements in C
Looping statements in CJeya Lakshmi
 
Programming fundamentals
Programming fundamentalsProgramming fundamentals
Programming fundamentals
Zaibi Gondal
 
C Language Programs
C Language Programs C Language Programs
C Language Programs
Mansi Tyagi
 
C programming Lab 1
C programming Lab 1C programming Lab 1
C programming Lab 1
Zaibi Gondal
 

What's hot (20)

Vp lecture 9 ararat
Vp lecture 9 araratVp lecture 9 ararat
Vp lecture 9 ararat
 
Write a program that accepts percentage from the user and displays its grade ...
Write a program that accepts percentage from the user and displays its grade ...Write a program that accepts percentage from the user and displays its grade ...
Write a program that accepts percentage from the user and displays its grade ...
 
Operators
OperatorsOperators
Operators
 
Input And Output
 Input And Output Input And Output
Input And Output
 
print even or odd number in c
print even or odd number in cprint even or odd number in c
print even or odd number in c
 
B.Com 1year Lab programs
B.Com 1year Lab programsB.Com 1year Lab programs
B.Com 1year Lab programs
 
Chowtodoprogram solutions
Chowtodoprogram solutionsChowtodoprogram solutions
Chowtodoprogram solutions
 
1 introduction to c program
1 introduction to c program1 introduction to c program
1 introduction to c program
 
C Programming Language Part 9
C Programming Language Part 9C Programming Language Part 9
C Programming Language Part 9
 
Input output statement in C
Input output statement in CInput output statement in C
Input output statement in C
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
 
Bcsl 033 data and file structures lab s1-1
Bcsl 033 data and file structures lab s1-1Bcsl 033 data and file structures lab s1-1
Bcsl 033 data and file structures lab s1-1
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
 
Looping statements in C
Looping statements in CLooping statements in C
Looping statements in C
 
Programming fundamentals
Programming fundamentalsProgramming fundamentals
Programming fundamentals
 
Semaphore
SemaphoreSemaphore
Semaphore
 
Semaphore
SemaphoreSemaphore
Semaphore
 
C Language Programs
C Language Programs C Language Programs
C Language Programs
 
C programming Lab 1
C programming Lab 1C programming Lab 1
C programming Lab 1
 
First Class
First ClassFirst Class
First Class
 

Similar to Basic of c programming www.eakanchha.com

UNIT-II CP DOC.docx
UNIT-II CP DOC.docxUNIT-II CP DOC.docx
UNIT-II CP DOC.docx
JavvajiVenkat
 
Datastructure notes
Datastructure notesDatastructure notes
Datastructure notesSrikanth
 
Programming Fundamentals lecture 5
Programming Fundamentals lecture 5Programming Fundamentals lecture 5
Programming Fundamentals lecture 5
REHAN IJAZ
 
complete data structure
complete data structurecomplete data structure
complete data structure
Anuj Arora
 
Datastructurenotes 100627004340-phpapp01
Datastructurenotes 100627004340-phpapp01Datastructurenotes 100627004340-phpapp01
Datastructurenotes 100627004340-phpapp01Getachew Ganfur
 
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
imtiazalijoono
 
Chapter3
Chapter3Chapter3
Chapter3
Kamran
 
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
Sivakumar R D .
 
Unit-IV.pptx
Unit-IV.pptxUnit-IV.pptx
Unit-IV.pptx
Mehul Desai
 
C Language Programming Introduction Lecture
C Language Programming Introduction LectureC Language Programming Introduction Lecture
C Language Programming Introduction Lecture
myinstalab
 
CP Handout#2
CP Handout#2CP Handout#2
CP Handout#2
trupti1976
 
Core programming in c
Core programming in cCore programming in c
Core programming in c
Rahul Pandit
 
Basics of c Nisarg Patel
Basics of c Nisarg PatelBasics of c Nisarg Patel
Basics of c Nisarg Patel
TechNGyan
 
Tutorial basic of c ++lesson 1 eng ver
Tutorial basic of c ++lesson 1 eng verTutorial basic of c ++lesson 1 eng ver
Tutorial basic of c ++lesson 1 eng ver
Qrembiezs Intruder
 
Programming in c
Programming in cProgramming in c
Programming in c
Ashutosh Srivasatava
 
C programming on Ubuntu
C programming on UbuntuC programming on Ubuntu
C programming on Ubuntu
Binu Joy
 
(Lect. 2 & 3) Introduction to C.ppt
(Lect. 2 & 3) Introduction to C.ppt(Lect. 2 & 3) Introduction to C.ppt
(Lect. 2 & 3) Introduction to C.ppt
atulchaudhary821
 
Basic of C Programming | 2022 Updated | By Shamsul H. Ansari
Basic of C Programming | 2022 Updated | By Shamsul H. AnsariBasic of C Programming | 2022 Updated | By Shamsul H. Ansari
Basic of C Programming | 2022 Updated | By Shamsul H. Ansari
G. H. Raisoni Academy of Engineering & Technology, Nagpur
 
C preprocesor
C preprocesorC preprocesor
C preprocesor
preetikapri1
 

Similar to Basic of c programming www.eakanchha.com (20)

UNIT-II CP DOC.docx
UNIT-II CP DOC.docxUNIT-II CP DOC.docx
UNIT-II CP DOC.docx
 
Datastructure notes
Datastructure notesDatastructure notes
Datastructure notes
 
Programming Fundamentals lecture 5
Programming Fundamentals lecture 5Programming Fundamentals lecture 5
Programming Fundamentals lecture 5
 
complete data structure
complete data structurecomplete data structure
complete data structure
 
Datastructurenotes 100627004340-phpapp01
Datastructurenotes 100627004340-phpapp01Datastructurenotes 100627004340-phpapp01
Datastructurenotes 100627004340-phpapp01
 
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
 
C programming
C programmingC programming
C programming
 
Chapter3
Chapter3Chapter3
Chapter3
 
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
 
Unit-IV.pptx
Unit-IV.pptxUnit-IV.pptx
Unit-IV.pptx
 
C Language Programming Introduction Lecture
C Language Programming Introduction LectureC Language Programming Introduction Lecture
C Language Programming Introduction Lecture
 
CP Handout#2
CP Handout#2CP Handout#2
CP Handout#2
 
Core programming in c
Core programming in cCore programming in c
Core programming in c
 
Basics of c Nisarg Patel
Basics of c Nisarg PatelBasics of c Nisarg Patel
Basics of c Nisarg Patel
 
Tutorial basic of c ++lesson 1 eng ver
Tutorial basic of c ++lesson 1 eng verTutorial basic of c ++lesson 1 eng ver
Tutorial basic of c ++lesson 1 eng ver
 
Programming in c
Programming in cProgramming in c
Programming in c
 
C programming on Ubuntu
C programming on UbuntuC programming on Ubuntu
C programming on Ubuntu
 
(Lect. 2 & 3) Introduction to C.ppt
(Lect. 2 & 3) Introduction to C.ppt(Lect. 2 & 3) Introduction to C.ppt
(Lect. 2 & 3) Introduction to C.ppt
 
Basic of C Programming | 2022 Updated | By Shamsul H. Ansari
Basic of C Programming | 2022 Updated | By Shamsul H. AnsariBasic of C Programming | 2022 Updated | By Shamsul H. Ansari
Basic of C Programming | 2022 Updated | By Shamsul H. Ansari
 
C preprocesor
C preprocesorC preprocesor
C preprocesor
 

More from Akanchha Agrawal

Micro economics questions sets
Micro economics questions setsMicro economics questions sets
Micro economics questions sets
Akanchha Agrawal
 
Number system with conversions www.eakanchha.com
Number system with conversions www.eakanchha.comNumber system with conversions www.eakanchha.com
Number system with conversions www.eakanchha.com
Akanchha Agrawal
 
Lvp law of variable proportions www.eakanchha.com
Lvp law of variable proportions www.eakanchha.comLvp law of variable proportions www.eakanchha.com
Lvp law of variable proportions www.eakanchha.com
Akanchha Agrawal
 
programs of c www.eakanchha.com
 programs of c www.eakanchha.com programs of c www.eakanchha.com
programs of c www.eakanchha.com
Akanchha Agrawal
 
cost missing value question www.eakanchha.com
 cost missing value question www.eakanchha.com cost missing value question www.eakanchha.com
cost missing value question www.eakanchha.com
Akanchha Agrawal
 
cost missing value question www.eakanchha.com
 cost missing value question www.eakanchha.com cost missing value question www.eakanchha.com
cost missing value question www.eakanchha.com
Akanchha Agrawal
 
cost micro economics www.eakanchha.com
cost micro economics www.eakanchha.comcost micro economics www.eakanchha.com
cost micro economics www.eakanchha.com
Akanchha Agrawal
 

More from Akanchha Agrawal (7)

Micro economics questions sets
Micro economics questions setsMicro economics questions sets
Micro economics questions sets
 
Number system with conversions www.eakanchha.com
Number system with conversions www.eakanchha.comNumber system with conversions www.eakanchha.com
Number system with conversions www.eakanchha.com
 
Lvp law of variable proportions www.eakanchha.com
Lvp law of variable proportions www.eakanchha.comLvp law of variable proportions www.eakanchha.com
Lvp law of variable proportions www.eakanchha.com
 
programs of c www.eakanchha.com
 programs of c www.eakanchha.com programs of c www.eakanchha.com
programs of c www.eakanchha.com
 
cost missing value question www.eakanchha.com
 cost missing value question www.eakanchha.com cost missing value question www.eakanchha.com
cost missing value question www.eakanchha.com
 
cost missing value question www.eakanchha.com
 cost missing value question www.eakanchha.com cost missing value question www.eakanchha.com
cost missing value question www.eakanchha.com
 
cost micro economics www.eakanchha.com
cost micro economics www.eakanchha.comcost micro economics www.eakanchha.com
cost micro economics www.eakanchha.com
 

Recently uploaded

Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 

Recently uploaded (20)

Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 

Basic of c programming www.eakanchha.com

  • 1. For complete theorywithmore than100 programsof c language loginto www.eakanchha.com Let’s start making a simple program. 1) # Write a program to print a message? #include<stdio.h> #include<conio.h> void main() { clrscr(): printf(“Hello. n How are you?”); getch(); }  First, compile program  press alt+F9. Now if no errors or warnings are found press ctrl+F9 to run program.  Here, stdio.h and conio.h are header files. Which contain pre-defined functions we use in program.  printf() is defined in stdio.h (standard input output header file). clrscr() and getch() are defined in conio.h (console input output header file).  printf() function allow to print set of characters written inside “”.  clrscr() function clears output screen so that, previous outputs does not get mix with your current output.  getch() function holds output screen until any key is pressed to return from output screen.  Each program contains a main() function.  Void is used as return type of main function. It is used with those functions which do not return any value.  Semi-colon (;) is used at end of every statement to terminate.  { This represents opening of a block.  }  This represents end of a block.  Each block which opens must end.  n  it is an escape sequence. We will discuss it latter in this chapter. Output of the above program will be as: Hello How are you?
  • 2. For complete theorywithmore than100 programsof c language loginto www.eakanchha.com 2) # Write a program to enter a number and print it? #include<stdio.h> #include<conio.h> void main() { int i; clrscr(); printf(“enter a number”); scanf(“%d”,&i); printf(“n you have entered=%d”, i); getch(); }  int represents a data type, and I is a variable of integer type.  %d is a format specifier. It tell which type of data scanf has to read from keyboard and printf has to print on output screen. Here it is integer type.  &  address of operator is used in scanf. It tells compiler, address of concerned variable where input from keyboard has to be saved.  An, important thing you should remember while writing any program is that, variable should be declared always first then, write other lines of code. For ex: If in the above program you write it as; Void main() { clrscr(); int i; printf(“enter a number”); scanf(“%d”,&i); printf(“n you have entered=%d”, i); getch(); } As, first clrscr() is written then, variable I is declared therefore it will not work. It will give an error “declaration is not allowed here.”
  • 3. For complete theorywithmore than100 programsof c language loginto www.eakanchha.com