SlideShare a Scribd company logo
Introduction to C
programming
Installation and set up
• Install C compiler – mingw.
• Set up by opening the terminal.
• GCC stands for GNU Compiler Collections which is used to compile mainly C and C++ language.
• To compile:
• gcc programName.c
• gcc programName.c –o outputfilename
• Eg: gcc hello.c –o hello
• To execute:
• ./outputfilename
The C programming language
• C is a procedural programming language initially developed by Dennis Ritchie
in the year 1972
• Structured programming language.
• High-level language because it allows the programmer to concentrate on the
problem at hand and not worry about the machine that the program will be
using.
• C is a compiler-based program.
Sample
/*
* hello.c
* This program prints a welcome message
* to the user.
*/
// preprocessor directive to include library for printf function
#include<stdio.h>
void main(){
printf(“Hey! Hello”);
return 0;
}
What’s the .h file?
• It’s a header file.
• The C developers had defined set of predefined functions and have
stored them as .h files.
• You can include them in your program and use the predefined
function.
Eg:
stdio.h,stlib.h,string.h,math.h,unistd.h
Look at the stdlib.h file functions
Program 1
#include<stdio.h>
int main(){
char gender = 'F';
int age = 40;
printf("Variables stored are: %d and %c", age, gender);
}
Program 2
#include<stdio.h>
int main(){
char gender;
int age;
printf("Enter your age and then gender(M, F or O): ");
scanf("%d %c", &age, &gender);
printf("You entered: %d and %c", age, gender);
}
Program 3
/* swap_var_third.c
This is a program to swap the values of two variables using a
third variable.
*/
#include <stdio.h>
int main() {
int a = 5, b = 10;
printf("a: %d b: %dn", a, b);
int c;
c = a;
a = b;
b = c;
printf("a: %d b: %dn", a, b);
return 0;
}
Program 4
/*
* swap_var_without.c
This is a program to swap the values of two variables using a third variable.
*/
#include <stdio.h>
int main() {
int a = 5, b = 10;
printf("a: %d b: %dn", a, b);
a = a + b;
b = a - b;
a = a - b;
printf("a: %d b: %dn", a, b);
return 0;
}
Program 5
//Sum of n numbers:
#include<stdio.h>
int main(){
int s =0;
s = s+1;
s = s+2;
s = s+3;
s = s+4;
printf(“%d”,s);
Return 0;
}
Program 6
//Sum of n numbers:
#include<stdio.h>
int main(){
for(i =0;i<5;i++){
s = s+i;
}
printf(“%d” ,s);
Return 0;
}
Increment opertor
• ++
Post fix - Used to increment the value after an operation is done.
Prefix – Used to increment first and then the operation is carried out.
int n = 1;
print(“%d”,n);
print(“%d”,n++);
print(“%d”,n);
print(“%d”,++n);
Conditionals - if
/*
This program calculates the maximum of two numbers.
*/
#include <stdio.h>
int main() {
int a, b;
int max;
printf("Enter a: ");
scanf("%d", &a);
printf("Enter b: ");
scanf("%d", &b);
if(a > b) {
max = a;
}
if(b > a) {
max = b;
}
printf("The maximum of %d, %d is %d.n", a, b, max);
return 0;
}
/*
TEST CASES:
4
5
10
10
*/
Nested if
/*
This program calculates the maximum of three numbers.
*/
#include <stdio.h>
int main(void) {
int a, b, c;
int max;
printf("Enter a: ");
scanf("%d", &a);
printf("Enter b: ");
scanf("%d", &b);
printf("Enter c: ");
scanf("%d", &c);
max = a;
if(a > b) {
if(a > c) {
max = a;
}
}
if(b > a) {
if(b > c) {
max = b;
}
}
if(c > a) {
if(c > b) {
max = c;
}
}
printf("The maximum of %d, %d, %d is %d.n", a, b, c, max);
return 0;
}
if else
/*
This program calculates the maximum of two
numbers.
*/
#include <stdio.h>
int main(void) {
int a, b;
int max;
printf("Enter a: ");
scanf("%d", &a);
printf("Enter b: ");
scanf("%d", &b);
max = a;
if(a > b)
max = a;
else
max = b;
printf("The maximum of %d, %d, %d is %d.n",
a, b, c, max);
return 0;
}
if – else if - else
/*
This program calculates the maximum of three numbers.
*/
#include <stdio.h>
int main(void) {
int a, b, c;
int max;
printf("Enter a: ");
scanf("%d", &a);
printf("Enter b: ");
scanf("%d", &b);
printf("Enter c: ");
scanf("%d", &c);
max = a;
if (a > b && a > c) {
max = a;
}
else if (b > a && b > c) {
max = b;
}
else if (c > a && c > b) {
max = c;
}
// else
// max = a;
// What is the difference in execution between this and 02 and 03?
printf("The maximum of %d, %d, %d is %d.n", a, b, c, max);
return 0;
}

More Related Content

PPTX
Introduction to Basic C programming 02
Wingston
 
PPT
c-programming
Zulhazmi Harith
 
PDF
C language concept with code apna college.pdf
mhande899
 
PPTX
C programming language
Abin Rimal
 
PPTX
C language
Priya698357
 
PPT
270_1_ChapterIntro_Up_To_Functions (1).ppt
GayathriShiva4
 
PPT
270_1_CIntro_Up_To_Functions.ppt 0478 computer
vynark1
 
PPT
CIntro_Up_To_Functions.ppt;uoooooooooooooooooooo
muhammedcti23240202
 
Introduction to Basic C programming 02
Wingston
 
c-programming
Zulhazmi Harith
 
C language concept with code apna college.pdf
mhande899
 
C programming language
Abin Rimal
 
C language
Priya698357
 
270_1_ChapterIntro_Up_To_Functions (1).ppt
GayathriShiva4
 
270_1_CIntro_Up_To_Functions.ppt 0478 computer
vynark1
 
CIntro_Up_To_Functions.ppt;uoooooooooooooooooooo
muhammedcti23240202
 

Similar to C BASICS.pptx FFDJF/,DKFF90DF SDPJKFJ[DSSIFLHDSHF (20)

PPTX
Overview of C Mrs Sowmya Jyothi
Sowmya Jyothi
 
PPTX
Each n Every topic of C Programming.pptx
snnbarot
 
PPTX
Chapter 1_C Fundamentals_HS_Tech Yourself C.pptx
ssuser71a90c
 
PPT
slidenotesece246jun2012-140803084954-phpapp01 (1).ppt
yatakonakiran2
 
PPT
Introduction to Basic C programming 01
Wingston
 
PDF
Subject:Programming in C - Lab Programmes
vasukir11
 
PPT
C tutorial
Anurag Sukhija
 
PPT
Survey of programming language getting started in C
ummeafruz
 
PPT
270_1_CIntro_Up_To_Functions.ppt
Alefya1
 
PPT
270_1_CIntro_Up_To_Functions.ppt
UdhayaKumar175069
 
PPT
270 1 c_intro_up_to_functions
ray143eddie
 
PPT
270_1_CIntro_Up_To_Functions.ppt
JoshCasas1
 
PDF
C-PPT.pdf
chaithracs3
 
PDF
learn basic to advance C Programming Notes
bhagadeakshay97
 
PPTX
Data structures and algorithms lab1
Bianca Teşilă
 
PPTX
C Programming with oops Concept and Pointer
Jeyarajs7
 
PPT
Unit i intro-operators
HINAPARVEENAlXC
 
ODT
Tut1
Still Abir
 
PDF
UNIT1 PPS of C language for first year first semester
Aariz2
 
Overview of C Mrs Sowmya Jyothi
Sowmya Jyothi
 
Each n Every topic of C Programming.pptx
snnbarot
 
Chapter 1_C Fundamentals_HS_Tech Yourself C.pptx
ssuser71a90c
 
slidenotesece246jun2012-140803084954-phpapp01 (1).ppt
yatakonakiran2
 
Introduction to Basic C programming 01
Wingston
 
Subject:Programming in C - Lab Programmes
vasukir11
 
C tutorial
Anurag Sukhija
 
Survey of programming language getting started in C
ummeafruz
 
270_1_CIntro_Up_To_Functions.ppt
Alefya1
 
270_1_CIntro_Up_To_Functions.ppt
UdhayaKumar175069
 
270 1 c_intro_up_to_functions
ray143eddie
 
270_1_CIntro_Up_To_Functions.ppt
JoshCasas1
 
C-PPT.pdf
chaithracs3
 
learn basic to advance C Programming Notes
bhagadeakshay97
 
Data structures and algorithms lab1
Bianca Teşilă
 
C Programming with oops Concept and Pointer
Jeyarajs7
 
Unit i intro-operators
HINAPARVEENAlXC
 
UNIT1 PPS of C language for first year first semester
Aariz2
 
Ad

Recently uploaded (20)

PPTX
Virus sequence retrieval from NCBI database
yamunaK13
 
DOCX
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
PDF
Biological Classification Class 11th NCERT CBSE NEET.pdf
NehaRohtagi1
 
PPTX
Command Palatte in Odoo 18.1 Spreadsheet - Odoo Slides
Celine George
 
PPTX
PROTIEN ENERGY MALNUTRITION: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
PPTX
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
PDF
Module 2: Public Health History [Tutorial Slides]
JonathanHallett4
 
PDF
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 
PPTX
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
PPTX
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
PPTX
Cleaning Validation Ppt Pharmaceutical validation
Ms. Ashatai Patil
 
PPTX
Care of patients with elImination deviation.pptx
AneetaSharma15
 
PPTX
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
PPTX
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
PDF
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
PPTX
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
PDF
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
PPTX
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
PPTX
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
Virus sequence retrieval from NCBI database
yamunaK13
 
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
Biological Classification Class 11th NCERT CBSE NEET.pdf
NehaRohtagi1
 
Command Palatte in Odoo 18.1 Spreadsheet - Odoo Slides
Celine George
 
PROTIEN ENERGY MALNUTRITION: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
Module 2: Public Health History [Tutorial Slides]
JonathanHallett4
 
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
Cleaning Validation Ppt Pharmaceutical validation
Ms. Ashatai Patil
 
Care of patients with elImination deviation.pptx
AneetaSharma15
 
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
Ad

C BASICS.pptx FFDJF/,DKFF90DF SDPJKFJ[DSSIFLHDSHF

  • 2. Installation and set up • Install C compiler – mingw. • Set up by opening the terminal. • GCC stands for GNU Compiler Collections which is used to compile mainly C and C++ language. • To compile: • gcc programName.c • gcc programName.c –o outputfilename • Eg: gcc hello.c –o hello • To execute: • ./outputfilename
  • 3. The C programming language • C is a procedural programming language initially developed by Dennis Ritchie in the year 1972 • Structured programming language. • High-level language because it allows the programmer to concentrate on the problem at hand and not worry about the machine that the program will be using. • C is a compiler-based program.
  • 4. Sample /* * hello.c * This program prints a welcome message * to the user. */ // preprocessor directive to include library for printf function #include<stdio.h> void main(){ printf(“Hey! Hello”); return 0; }
  • 5. What’s the .h file? • It’s a header file. • The C developers had defined set of predefined functions and have stored them as .h files. • You can include them in your program and use the predefined function. Eg: stdio.h,stlib.h,string.h,math.h,unistd.h
  • 6. Look at the stdlib.h file functions
  • 7. Program 1 #include<stdio.h> int main(){ char gender = 'F'; int age = 40; printf("Variables stored are: %d and %c", age, gender); }
  • 8. Program 2 #include<stdio.h> int main(){ char gender; int age; printf("Enter your age and then gender(M, F or O): "); scanf("%d %c", &age, &gender); printf("You entered: %d and %c", age, gender); }
  • 9. Program 3 /* swap_var_third.c This is a program to swap the values of two variables using a third variable. */ #include <stdio.h> int main() { int a = 5, b = 10; printf("a: %d b: %dn", a, b); int c; c = a; a = b; b = c; printf("a: %d b: %dn", a, b); return 0; }
  • 10. Program 4 /* * swap_var_without.c This is a program to swap the values of two variables using a third variable. */ #include <stdio.h> int main() { int a = 5, b = 10; printf("a: %d b: %dn", a, b); a = a + b; b = a - b; a = a - b; printf("a: %d b: %dn", a, b); return 0; }
  • 11. Program 5 //Sum of n numbers: #include<stdio.h> int main(){ int s =0; s = s+1; s = s+2; s = s+3; s = s+4; printf(“%d”,s); Return 0; }
  • 12. Program 6 //Sum of n numbers: #include<stdio.h> int main(){ for(i =0;i<5;i++){ s = s+i; } printf(“%d” ,s); Return 0; }
  • 13. Increment opertor • ++ Post fix - Used to increment the value after an operation is done. Prefix – Used to increment first and then the operation is carried out. int n = 1; print(“%d”,n); print(“%d”,n++); print(“%d”,n); print(“%d”,++n);
  • 14. Conditionals - if /* This program calculates the maximum of two numbers. */ #include <stdio.h> int main() { int a, b; int max; printf("Enter a: "); scanf("%d", &a); printf("Enter b: "); scanf("%d", &b); if(a > b) { max = a; } if(b > a) { max = b; } printf("The maximum of %d, %d is %d.n", a, b, max); return 0; } /* TEST CASES: 4 5 10 10 */
  • 15. Nested if /* This program calculates the maximum of three numbers. */ #include <stdio.h> int main(void) { int a, b, c; int max; printf("Enter a: "); scanf("%d", &a); printf("Enter b: "); scanf("%d", &b); printf("Enter c: "); scanf("%d", &c); max = a; if(a > b) { if(a > c) { max = a; } } if(b > a) { if(b > c) { max = b; } } if(c > a) { if(c > b) { max = c; } } printf("The maximum of %d, %d, %d is %d.n", a, b, c, max); return 0; }
  • 16. if else /* This program calculates the maximum of two numbers. */ #include <stdio.h> int main(void) { int a, b; int max; printf("Enter a: "); scanf("%d", &a); printf("Enter b: "); scanf("%d", &b); max = a; if(a > b) max = a; else max = b; printf("The maximum of %d, %d, %d is %d.n", a, b, c, max); return 0; }
  • 17. if – else if - else /* This program calculates the maximum of three numbers. */ #include <stdio.h> int main(void) { int a, b, c; int max; printf("Enter a: "); scanf("%d", &a); printf("Enter b: "); scanf("%d", &b); printf("Enter c: "); scanf("%d", &c); max = a; if (a > b && a > c) { max = a; } else if (b > a && b > c) { max = b; } else if (c > a && c > b) { max = c; } // else // max = a; // What is the difference in execution between this and 02 and 03? printf("The maximum of %d, %d, %d is %d.n", a, b, c, max); return 0; }