Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
statements
DR. SHARIFAH ADZILA BINTI SYED ABU BAKAR
FACULTY OF MECHANICAL & MANUFACTURING ENGINEERING
I/O of string
gets( string)
puts(string)
scanf
Example printf
Input %s
Used to read string
General form: %ws(w represent length of the string)
This specification terminates reading at the counter of a blank space or new line
Input: %d
Read integer of data
Format; %wd (w is field width)
Can used separator
E.g: : ,
Assignment suppression
%*p
Exp: scanf(%d %*d %d,&a,&b);
Input: 100 200 300, the values of a and b are 100 and 300 respectively. 200 will not be
assigned to any value due to %*d. Useful when data is written in tabular form to skip a
particular column
Input: %f
This format spesification is used to read floating point of data
General form: %wf (w width of data)
Input: 12.3242.423
a=12.300000
b=242.000000
C=0.400000
Output; %f
Width and precision can also be specified dynamically
printf(%*.*f,width,precision, arg);
Exercise
Write a program to find slope and midpoint of straight line whose
two end points are (x1,y1) and (x2,y2)
Write a program to find area of triangle whose coordinates of
vertices are (x1,y1), (x2,y2), (x3,y3)