Lesson 2: Data Types. Program Structure / Input - Output. Selection
Lesson 2: Data Types. Program Structure / Input - Output. Selection
Review:
Program • Commands
Programming
• Final
Result data
So, what is
programming?
Cybernetics
Кибернетика
Cybernetics
– реакционная лженаука,
"the scientific study of возникшая в США после
control and второй мировой войны и
Just for fun communication in the получившая широкое
animal and the распространение и в других
machine.“ капиталистических странах:
форма современного
Norbert Wiener, 1948 механицизма1
Краткий философский словарь,
Москва, 1954
1 Cybernetics - reactionary pseudoscience that arose in the USA after the Second World War and
became widespread in other capitalist countries: a form of modern mechanism
Information,
Data
and
Data types
Information — is a designation of content that
we received from the outside world in the
Information process of adapting us and our feelings to it.
(Norbert Winner)
of
computer
system
Data and
memory
Data and memory
C basics
Program structure / Input - output
• Alphabet letters: from a to z, from A to Z;
• Digit symbols: from 0 to 9;
• Special symbols like: @ # $ % ^ & * ( ) { } [ ] | \ ,
C : ; etc.
language
alphabet
identifiers - sequence of letters, numbers and the _ symbol, which
does not contain spaces. The first symbol of the identifier cannot be a
digit.
C Examples:
language number_1, n2, A, b6, draw_object
Example:
int, double, float, system, getch, struct, return,…
Variables are memory locations of predefined sizes that can
store data of a certain type and are identified by name.
Inverse sign -
Increment ++
Decrement --
Operators Addition +
Substraction -
Multiplication *
Division /
Remainder %
S. Corlat, 2009
Relational
Operators Logic
Negation !
Conjuncion &&
Disjunction ||
S. Corlat, 2009
Operators
priority
Input / Output
Description: The C library function int getchar(void) gets a
character (an unsigned char) from stdin.
Declaration: int getchar(void)
Parameters - NONE
Return Value: the function returns the character read as an
unsigned char cast to an int or EOF on end of file or error.
Primary IO
Description: The C library function int putchar(int char) writes a
functions character (an unsigned char) specified by the argument char to
stdout.
Declaration: int putchar(int char)
Parameters: char − This is the character to be written.
Return Value: the function returns the character written as an
unsigned char cast to an int or EOF on error.
Prototypes in: <stdio.h>
Description: the C library function char *gets(char *str) reads a line
from stdin and stores it into the string pointed to by str. It stops when
either the newline character is read or when the end-of-file is reached,
whichever comes first.
Declaration: char *gets(char *str)
Parameters: str − the pointer to an array of chars.
Return Value: the function returns str on success, and NULL on error or
when end of file occurs, while no characters have been read.
gets / puts
Description: the C library function int puts(const char *str) writes a
string to stdout up to but not including the null character. A newline
character is appended to the output.
Parameters:
format − This is the C string that contains one or more of the following
scanf() items − whitespace character, Non-whitespace character and Format
specifiers.
printf()
Parameters:
format − This is the string that contains the text to be written to
stdout. It can optionally contain embedded format tags that are
replaced by the values specified in subsequent additional
arguments and formatted as requested.
Format tags prototype is
%[flags][width][.precision][length]specifier
width Descriere
.număr Pentru specificatorii întregi (d, i, o, u, x, X): numărul minim de caractere pentru afișare. Posibile
0 în față, dacă lungimea reală este mai mica decât cea cerută. Numerele mai lungi nu se
trunchiază.
Precizia 0 înseamnă că nu se va scris nici un caracter pentru valoarea 0.
Pentru a, A, e, E, f și F specifică numărul de cifre tipărite după punctul zecimal.
Pentru g și G: Numărul maximal de cifre semnificative care urmează a fi tipărit.
Pentru s: numărul maximal de caractere pentru a fi tipărite. Implicit se afișează toate
caracterele până la ‘\0’.
.* Precizia nu este specificată explicit, dar ca un argument adițional de tip întreg care precede
argumentul care trebuie formatat.
Escape sequence Description
Note. Exclude the operator fflush(stdin). Verify the new result after execution.
1. Write a program to convert x MDL to USD and EUR. Use rates
for the day of code writing.
2. Write a program to calculate the volume of a sphere (try find
the formula!). Print results with at least 10 significant digits
3. Write a program to print using pseudo graphics symbols a table
of 3 rows and 4 columns. The first column will contain student
Homework name (no more than 15 symbols); second column – student
birthplace(no more than 20 symbols); third column – student
school (no more than 25 symbols) ; last one – the student
amount of Facebook friends ( no more than 5000).
(Laboratory Data will be entered from the keyboard. You have to obtain a
prefect alignment for any data!
Lesson) Example:
Ion Duruitoarea Liceu 257
Maria Pepeni Liceu 18
Emanuela Ciocana CEFB 3214