Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Программирование на ЯВУ, семинар 2
Search
Ilya
September 08, 2015
Education
0
68
Программирование на ЯВУ, семинар 2
Ilya
September 08, 2015
Tweet
Share
More Decks by Ilya
See All by Ilya
Программирование на ЯВУ, семинар 3
ilya
0
130
ОПК, семинар №8
ilya
0
49
ОПК, семинар №6
ilya
0
72
ОПК, семинар №4
ilya
0
100
ОПК, семинар №2
ilya
0
74
Other Decks in Education
See All in Education
わたしのメタ学習 / My Own Meta Learning #shinjukurb
expajp
0
120
HyRead2324
cbtlibrary
0
120
Data Presentation - Lecture 5 - Information Visualisation (4019538FNR)
signer
PRO
0
1.8k
View Manipulation and Reduction - Lecture 9 - Information Visualisation (4019538FNR)
signer
PRO
0
1.4k
Introduction - Lecture 1 - Advanced Topics in Big Data (4023256FNR)
signer
PRO
1
1.1k
前期教育実習事前指導0221
naradai
0
130
Copilotとして理解する生成AI利用の基本
gmoriki
0
140
SUMMER SCHOOL 2024
pnuslide
0
140
Visualisation Techniques - Lecture 8 - Information Visualisation (4019538FNR)
signer
PRO
0
1.7k
第1回全国商業高校Webアプリコンテスト総括
asial_corp
0
410
Multimodal Interaction - Lecture 3 - Next Generation User Interfaces (4018166FNR)
signer
PRO
0
1.1k
高可用性システム構築 - Oracle Data Guard基本編
oracle4engineer
PRO
2
1.1k
Featured
See All Featured
Debugging Ruby Performance
tmm1
70
11k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
121
39k
How GitHub Uses GitHub to Build GitHub
holman
468
290k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
25
2.3k
Bash Introduction
62gerente
604
210k
Web Components: a chance to create the future
zenorocha
305
41k
Web development in the modern age
philhawksworth
202
10k
Fontdeck: Realign not Redesign
paulrobertlloyd
76
4.9k
The Cost Of JavaScript in 2023
addyosmani
16
3.9k
YesSQL, Process and Tooling at Scale
rocio
164
13k
The Straight Up "How To Draw Better" Workshop
denniskardys
227
130k
Gamification - CAS2011
davidbonilla
76
4.6k
Transcript
http://en.cppreference.com/w/c http://learnxinyminutes.com/docs/c/ https://en.wikibooks.org/wiki/C_Programming http://c.learncodethehardway.org/book/ Kernigan and Ritchie: The C Programming
Language (K&R) Полезное про C
http://immersivemath.com/ila/index.html http://visualgo.net/ Полезное
void swap(double arr[]) { double x; x = arr[0]; arr[0]
= arr[1]; arr[1] = x; } void main() { double arr[2]; arr[0] = 1.0; arr[1] = 2.0; swap(arr); printf("%f %f\n", arr[0], arr[1]); } > 2.000000 1.000000 Массивы и функции
Нужно больше stdlib.h #include <math.h> printf("%f %2.f %.2f\n", M_PI, M_PI,
M_PI); > 3.141593 3 3.14 printf("%e %2.e %.2e\n", M_PI, M_PI, M_PI); > 3.141593e+00 3e+00 3.14e+00
#include <stdio.h> #include <stdlib.h> void main() { int i, number;
for(i = 0; i < 5; i++) { number = rand() % 100; printf("%d: %d\n", i, number); } } > 0: 83 > 1: 86 > 2: 77 > 3: 15 > 4: 93 Случайные числа
assert.h int factorial(int n) { // вырезано цензурой } void
main() { int i, result; for(i = 1; i < 6; i++) { result = factorial(i); printf("%d! = %d\n", i, result); } } > 1! = 1 > 2! = 2 > 3! = 6 > 4! = 24 > 5! = 120
printf("%d! = %d\n", -5, factorial(-5)); Segmentation fault (core dumped)
int factorial(int n) { assert(n >= 0); // вырезано цензурой
} printf("%d! = %d\n", -5, factorial(-5)); main: main.c:5: factorial: Assertion `n >= 0' failed. Aborted (core dumped)
Тестирование int celsius_to_fahrenheit(int c) { // } int fahrenheit_to_celsius(int f)
{ // } void main() { printf("%d\n", celsius_to_fahrenheit(30)); // 86 assert(celsius_to_fahrenheit(30) == 86); assert(fahrenheit_to_celsius(86) == 30); assert(celsius_to_fahrenheit(0) == 32); assert(fahrenheit_to_celsius(32) == 0); }
Стиль // Вычисление 2*X^2 + 3*X — 5 для X
int some_fun(int i) { int j=2,k,l=3,m,n=-5; if(i!=0) return j*i*i+l*i+n; else {printf("invalid x %d",i);} return -5; }
int polynomial(int x) { int a = 2, b =
3, c = -5; if(x == 0) { printf("Not a very interesting x\n"); return c; } else { return a * pow(x, 2) + b * pow(x, 1) + c; } }
Константы int i; int a[7]; // Ещё хуже, когда a[5]
for(i = 0; i < 6; i++) { a[i] = pow(10, i); printf("%d ", a[i]); } // Совсем плохо, когда так: for(i = 0; i < 6; i++) { ... for(i = 0; i < 6; i++) { ... for(i = 0; i < 6; i++) { ... for(i = 0; i < 6; i++) { ... for(i = 0; i < 6; i++) {
const unsigned size = 6; void main() { int i;
int a[size]; for(i = 0; i < size; i++) { a[i] = pow(10, i); printf("%d ", a[i]); } }