Вы находитесь на странице: 1из 15

KKK 3005 C-Prog (6)

th
Feb 13 2007
Dr. M. Iqbal Saripan
Dept. of Computer and Communication
System Engineering
Basic structure in C
// TITLE
# include <stdio.h>
// Global declaration
main()
{
//Local declaration
//Main source code
}
Getchar and Putchar
A=getchar();
putchar(A);
Operators in C
Definition: Symbols that are used as to
check a condition or as a mathematical
logical
Arithmetic operators: + - / * %
Equality operators: == !=
Relational operators: > < >= <=
Precedence
Determines the Operators Associativity
priority of the * / % Left to right
operations
+ - Left to right

< <= > >= Left to right

== != Left to right

= Right to left
Exercise
Draw a flowchart and main program for
this problem
„ A = 2+(B+C/2)*(7/1)+1
Explicit conversion
Method 1:
short a=2000;
int b;
b=a;
Method 2:
short a=2000;
(int) a;
Assignment Operators
C=C+3;
C+=3; \\ is equal to C=C+3;
A+=B A=A+B
A-=B A=A-B
A*=B A=A*B
A/=B A=A/B
A%=B A=A%B;
Increment and Decrement
Operators
++a Increment a by 1 then use the new value
of a in the expression in which a resides
a++ Use the current value of a in the
expression in which a resides, then
increment by 1
--b Decrement b by 1 then use the new value
of b in the expression in which b resides
b-- Use the current value of b in the
expression in which b resides, then
decrement by 1
Example
C=1;
printf(“%d”,C);

printf(“%d”,C++);
printf(“%d”,C);

printf(“%d”,++C);
printf(“%d”,C);
IF

Condition 1 Process 1
IF only has ONE condition and ONE
outcome process
Example:
„ IF a student gets more than 60 marks
Print “passed”
IF - ELSE

Process 2 Condition 1 Process 1


IF-ELSE has more than one condition, and
more than one outcome process

Exercise: Draw a flowchart:


„ IF { IF { IF {} } } ;
„ IF {IF {} ELSE {} } ELSE {};
„ IF {} ELSE { IF {} ELSE{}};
Exercise
Question 2 Test 1

Вам также может понравиться