This shows you the differences between two versions of the page.
programare:laboratoare:lab02 [2020/10/12 11:24] george.muraru |
programare:laboratoare:lab02 [2024/10/19 15:21] (current) darius.neatu [Tipuri de date. Operatori. Masurarea timpului de executie. Functii matematice.] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ===== Tipuri de date. Operatori. Masurarea timpului de executie. Functii matematice. ===== | + | ===== Tipuri de date. Operatori. Functii matematice. ===== |
**Responsabili:** | **Responsabili:** | ||
Line 228: | Line 228: | ||
- Ne dorim să înțelegem tipurile de date. Acest exercițiu presupune rularea mai multor secvențe de cod cu scopul de a clarifica diverse aspecte. Analizați fiecare secvență și încercați să intuiți output-ul acesteia. După aceea verificați. | - Ne dorim să înțelegem tipurile de date. Acest exercițiu presupune rularea mai multor secvențe de cod cu scopul de a clarifica diverse aspecte. Analizați fiecare secvență și încercați să intuiți output-ul acesteia. După aceea verificați. | ||
* <code c ex1a.c> | * <code c ex1a.c> | ||
+ | #include <stdio.h> | ||
+ | |||
+ | int main(void) { | ||
char x = 65; | char x = 65; | ||
Line 233: | Line 236: | ||
printf("%c\n", x); | printf("%c\n", x); | ||
printf("%d\n", x); | printf("%d\n", x); | ||
+ | |||
+ | return 0; | ||
+ | } | ||
</code> | </code> | ||
* <code c ex1b.c> | * <code c ex1b.c> | ||
+ | #include <stdio.h> | ||
+ | |||
+ | int main(void) { | ||
char x = 130; | char x = 130; | ||
Line 241: | Line 250: | ||
else | else | ||
printf("Not sure...\n"); | printf("Not sure...\n"); | ||
+ | |||
+ | return 0; | ||
+ | } | ||
</code> | </code> | ||
* <code c ex1c.c> | * <code c ex1c.c> | ||
+ | #include <stdio.h> | ||
+ | |||
+ | int main(void) { | ||
unsigned char x = 130; | unsigned char x = 130; | ||
Line 249: | Line 264: | ||
else | else | ||
printf("Not sure...\n"); | printf("Not sure...\n"); | ||
+ | |||
+ | return 0; | ||
+ | } | ||
</code> | </code> | ||
* <code c ex1d.c> | * <code c ex1d.c> | ||
+ | #include <stdio.h> | ||
+ | |||
+ | int main(void) { | ||
char x = 321; | char x = 321; | ||
Line 256: | Line 277: | ||
printf("%c\n", x); | printf("%c\n", x); | ||
printf("%d\n", x); | printf("%d\n", x); | ||
+ | |||
+ | return 0; | ||
+ | } | ||
</code> | </code> | ||
* <code c ex1e1.c> | * <code c ex1e1.c> | ||
+ | #include <stdio.h> | ||
+ | |||
+ | int main(void) { | ||
unsigned int x = ~0; | unsigned int x = ~0; | ||
printf("%u\n", x); | printf("%u\n", x); | ||
printf("%u\n", x + 1); | printf("%u\n", x + 1); | ||
+ | |||
+ | return 0; | ||
+ | } | ||
</code> | </code> | ||
* <code c ex1e2.c> | * <code c ex1e2.c> | ||
+ | #include <stdio.h> | ||
+ | |||
+ | int main(void) { | ||
unsigned int x = ~0; | unsigned int x = ~0; | ||
printf("%d\n", x); | printf("%d\n", x); | ||
printf("%d\n", x + 1); | printf("%d\n", x + 1); | ||
+ | |||
+ | return 0; | ||
+ | } | ||
</code> | </code> | ||
* <code c ex1e3.c> | * <code c ex1e3.c> | ||
+ | #include <stdio.h> | ||
+ | |||
+ | int main(void) { | ||
int x = ~0; | int x = ~0; | ||
printf("%u\n", x); | printf("%u\n", x); | ||
printf("%u\n", x + 1); | printf("%u\n", x + 1); | ||
+ | |||
+ | return 0; | ||
+ | } | ||
</code> | </code> | ||
* <code c ex1f1.c> | * <code c ex1f1.c> | ||
+ | #include <stdio.h> | ||
+ | |||
+ | int main(void) { | ||
char x = -1; | char x = -1; | ||
int y = x; | int y = x; | ||
Line 287: | Line 332: | ||
printf("%u\n", a); | printf("%u\n", a); | ||
printf("%u\n", b); | printf("%u\n", b); | ||
+ | |||
+ | return 0; | ||
+ | } | ||
</code> | </code> | ||
* <code c ex1f2.c> | * <code c ex1f2.c> | ||
+ | #include <stdio.h> | ||
+ | |||
+ | int main(void) { | ||
char x = -1; | char x = -1; | ||
int y = x; | int y = x; | ||
Line 300: | Line 351: | ||
printf("%d\n", a); | printf("%d\n", a); | ||
printf("%d\n", b); | printf("%d\n", b); | ||
+ | |||
+ | return 0; | ||
+ | } | ||
</code> | </code> | ||
* <code c ex1g1.c> | * <code c ex1g1.c> | ||
+ | #include <stdio.h> | ||
+ | |||
+ | int main(void) { | ||
float f = 1 / 3; | float f = 1 / 3; | ||
printf("%f\n", f); | printf("%f\n", f); | ||
+ | |||
+ | return 0; | ||
+ | } | ||
</code> | </code> | ||
* <code c ex1g2.c> | * <code c ex1g2.c> | ||
+ | #include <stdio.h> | ||
+ | |||
+ | int main(void) { | ||
float f = 1.0 / 3; | float f = 1.0 / 3; | ||
printf("%f\n", f); | printf("%f\n", f); | ||
+ | |||
+ | return 0; | ||
+ | } | ||
</code> | </code> | ||
* <code c ex1h1.c> | * <code c ex1h1.c> | ||
+ | #include <stdio.h> | ||
+ | |||
+ | int main(void) { | ||
float f = 0.7; | float f = 0.7; | ||
Line 320: | Line 389: | ||
else | else | ||
printf("0.7 > 0.7\n"); | printf("0.7 > 0.7\n"); | ||
+ | |||
+ | return 0; | ||
+ | } | ||
</code> | </code> | ||
* <code c ex1h2.c> | * <code c ex1h2.c> | ||
+ | #include <stdio.h> | ||
+ | |||
+ | int main(void) { | ||
double f = 0.7; | double f = 0.7; | ||
Line 330: | Line 405: | ||
else | else | ||
printf("0.7 > 0.7\n"); | printf("0.7 > 0.7\n"); | ||
+ | |||
+ | return 0; | ||
+ | } | ||
</code> | </code> | ||
Line 352: | Line 430: | ||
==== Probleme ==== | ==== Probleme ==== | ||
+ | |||
- [1p] Studentul va rula împreună cu asistentul exemplele din laborator și va cere lămuriri acolo unde este cazul. | - [1p] Studentul va rula împreună cu asistentul exemplele din laborator și va cere lămuriri acolo unde este cazul. | ||
- [0.5p + 0.5p] Să se verifice dacă un număr citit de la tastatură este număr par (prin două moduri). | - [0.5p + 0.5p] Să se verifice dacă un număr citit de la tastatură este număr par (prin două moduri). | ||
Line 377: | Line 456: | ||
</hidden> | </hidden> | ||
- | ===== Extra ===== | + | ==== Extra ==== |
* [[https://github.com/cs-pub-ro/ComputerProgramming/blob/master/Laboratories/Lab2/cheatsheet.pdf|Cheatsheet]] | * [[https://github.com/cs-pub-ro/ComputerProgramming/blob/master/Laboratories/Lab2/cheatsheet.pdf|Cheatsheet]] | ||
- | * | ||
==== Referinţe ==== | ==== Referinţe ==== | ||