Professional Documents
Culture Documents
Introduction To C
Introduction To C
CHAPTER I
INTRODUCTION TO C
OUTLINE
¡ Introduction to C
¡ Write Our First Program – Hello World
¡ How a C Program Works
¡ Variables, Expressions, Statements
¡ Print Variables Using Printf
¡ Take Input from User
¡ Comments
INTRODUCTION TO C
People: Computer:
“Hello!” 11010101010101000
Programming
language
PROGRAMING LANGUAGE (2)
PROGRAMING LANGUAGE (3)
#include <stdio.h>
int main()
{
printf("Hello World\n");
return 0;
}
PROGRAMING TOOLS
¡ Online Tools:
¡ www.onlinegdb.com/online_c_compiler
¡ Offline Tools:
¡ CodeBlocks
¡ DevC
¡ CLion
ONLINE TOOL
¡ https://www.onlinegdb.com/online_c_compiler
¡ http://www.codeblocks.org/downloads/binaries
#include <stdio.h>
int main()
{
printf("Hello World\n");
return 0;
}
C BASICS
Data
15
15
Memory
Each location in the memory is unique
Operators
2*y+5
Operands
PRINT VARIABLES USING PRINTF
#include <stdio.h>
int main(){
int x;
x = 5; //Hard Coding
int y = x/2
printf(”y= %i, x = %i,y,x");
return 0;
}
TAKING INPUT FROM USER
¡ In C programming, scanf() is one of the commonly used function to take input from
the user.
¡ The scanf() function reads formatted input from the standard input such as
keyboards.
TAKING INPUT FROM USER
/**********************************************************
Author: Pham Xuan Lam
Description: A Simple HelloWorld Program
Last Update: 20/12/2018
**********************************************************/
¡ Comment Tips:
¡ Don't overdo Comment
¡ Use TODO comment
EXERCISES 1
Write a program that prints the perimeter of a rectangle to take its height and
width as input:
Expected Output :
Input the height of the Rectangle : 5
Input the width of the Rectangle : 7
Perimeter of the Rectangle is : 24
EXERCISES 2
Expected Output :
Input a temperature (in Centigrade): 45
113 degrees Fahrenheit.
EXERCISES 3
Write a program that takes hours and minutes as input, and calculates the total number of
minutes:
Expected Output :
Input hours: 5
Input minutes: 37
Total: 337 minutes.
SUMMARY
¡ Introduction to C
¡ Write Our First Program – Hello World
¡ How a C Program Works
¡ Variables, Expressions, Statements
¡ Print Variables Using Printf
¡ Take Input from User
¡ Comments