Professional Documents
Culture Documents
Introduction to Programming
Objectives
Introduction to Programming
Program Data and Actions
Introduction to Programming
Simple C Programs
Source code Output
#include<stdio.h>
Program A
Hello world.
void main(void)
{
printf(“Hello world.”);
}
#include<stdio.h>
Hello world.
Program B
Introduction to Programming
Sequential Execution
#include<stdio.h>
Hello world.
Program C
Introduction to Programming
Data and Instructions
Computer Memory
Program
Instructions
Data
Introduction to Programming
Variables
grade
Computer 95
memory
int grade;
scanf(“%d”, &grade);
Introduction to Programming
A Program Using A Variable
/* A C program that accepts an integer value and
displays it back to the screen */
#include <stdio.h>
int main(void)
{
int grade;
printf(“Enter the student’s grade: ”);
scanf(“%d”,&grade);
printf(“The grade of the student is %d.”, grade);
return 0;
}
Output
Enter the student’s grade: 95
The grade of the student is 95.
Introduction to Programming
Identifiers
Introduction to Programming
Identifiers
Introduction to Programming
Valid Identifiers
Introduction to Programming
Identifiers
Introduction to Programming
C Keywords
• auto • else • register • union
• break • enum • return • unsigne
• case • extern • short d
• char • float • signed • void
• const • for • sizeof • volatile
• continu • goto • static • while
e • if • struct
• default • int • switch
• do • long • typedef
• double Introduction to Programming
Identifiers
• C is a case-sensitive language
• In C, even though two identifiers are spelled
the same, if the case of each corresponding
letter doesn’t match, C regards them as two
different names
• For example, the identifiers student and
Student are considered as two different
identifiers
Introduction to Programming
Invalid Identifiers
Introduction to Programming
Assignment Statements
• For example:
x = 100;
y = 200;
x = y;
Introduction to Programming
Swapping Values
/* A C program that swaps the values of two
variables */
#include <stdio.h>
int main(void)
{
int x, y, temp;
printf(“Enter two numbers: ”);
scanf(“%d %d”,&x, &y);
temp = x;
x = y;
y = temp;
printf(“Value of x: %d\n”, x);
printf(“Value of y: %d”, y);
return 0;
Introduction to Programming
}
Performing Calculations on Data
/* A C program that adds and subtracts the values of
two variables */
#include <stdio.h>
int main(void)
{
int x, y;
printf(“Enter two numbers: ”);
scanf(“%d %d”,&x, &y);
return 0;
}
Introduction to Programming
Summary
Introduction to Programming