0% found this document useful (0 votes)
2 views

Lecture 3

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Lecture 3

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Quiz: What does the line ‘\n’ do

Quiz: When you compile what is


the output?

What happens if place \n here ?


What happens if place \n here ?
Quiz: When you compile what is
the output?
Quiz: Spot any error in the
program
Try this program in Mobile C to test
your hypothesis (your hypothesis is
either error exist or error don’t exist)

What happens if replace with

What happens if replace with

NO ERROR !!
Arithmetic Operator
/* This program is to calculate the surface area of a triangle */
#include <stdio.h>

int main (void)


{
/* declare the variables as integers */
int b,h,surface;
/* define the variables */
b = 4; /* base */
h = 1; /* height */

surface = b*h/2;

/* display the value of surface */


printf("The surface of triangle is: %d", surface);

return 0;
}
Quiz: Arithmetic Operator

What is the common equation for


this graph ?

Express the equation in C


programming along with any
variables involved

Exercise:
Write a program that enters the
value of x to generate a value of y
Quiz: Arithmetic Operator

Write the algebraic equation of this


c code

From your math knowledge what


kind of equation is this ?

Can you recall how the graph looks


like for this equation ?
Reserve keywords in C

DO NOT USE THESE KEYWORDS AS VARIABLES !!


Pseudo code

/* This program is to display the numerical value of ASCII character


*/
#include <stdio.h> • Programming language
(syntax) free
int main (void) • Easily understood by the third
{ party coder
char a; • A draft in a text/descriptive
printf(“Enter a character: “); form
• Not constraint to specific
// Reads character input from the user
scanf(“%c”, &a);
variables use
Start program
// %d displays the integer value of a character Declare a character variable a
// %c displays the actual character Enter an ASCII character
printf(“ASCII value of %c = %d", a, a); Scan the character into variable a
Print the character and its
return 0; equivalent numerical value
} End program
Quiz: Write the pseudocode for
the surface_triangle example
/* This program is to calculate the surface area of a triangle */
#include <stdio.h>

int main (void)


{ Start program
/* declare the variables as integers */ Set b equals 4 i.e. b=4
int b,h,surface; Set h equals 1 i.e. h=1
/* define the variables */
Calculate surface triangle
b = 4; /* base */
h = 1; /* height */ using equation ½ times
base times height
surface = b*h/2; Display the surface triangle
value
/* display the value of surface */ End program
printf("The surface of triangle is: %d", surface);

return 0;
}

You might also like