Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
ОПК, семинар №2
Search
Ilya
February 19, 2015
Education
93
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
ОПК, семинар №2
Массивы, ассерты, тесты
Ilya
February 19, 2015
More Decks by Ilya
See All by Ilya
Программирование на ЯВУ, семинар 3
ilya
0
170
Программирование на ЯВУ, семинар 2
ilya
0
75
ОПК, семинар №8
ilya
0
58
ОПК, семинар №6
ilya
0
79
ОПК, семинар №4
ilya
0
110
Other Decks in Education
See All in Education
[2026前期火5] 論理学(京都大学文学部 前期 第8回)「正規化定理の証明」
yatabe
0
330
Carbohydrates: Classification, Structure & Chemical Properties
pawan_pharm
0
270
第2部-高校生とAI活用/high-school2026-2
okana2ki
0
160
Tema 1. El relieve de España: Formación y características
juanmartin2026
0
8.9k
オンラインコミュニティ TRY部 体験マニュアル
ytapples613
0
360
良書紹介08_ 頭のいい子がやっているすごいグラフの読み方
bunnchinn3
0
160
Fundamentos, Caracteristicas y Aplicaciones de los Modulos NumPy , Matplotlib y Pandas
robintux
0
250
[2026前期火5] 論理学(京都大学文学部 前期 第9回)「正規化の停止性——ヒドラゲームによる証明」
yatabe
0
280
Antigravityを使ってGeminiAPI(NanobananaPro)と連携して挿絵メーカーを作った
yoshimura_datam
0
220
Soluciones al examen de Geografía 2026. JUNIO (Convocatoria Ordinaria)
juanmartin2026
1
10k
人間のために、人間と共に働く時代の終わりの始まり
frievea
0
180
iSpindel & AI
lonbrew
0
110
Featured
See All Featured
Become a Pro
speakerdeck
PRO
31
6.3k
Documentation Writing (for coders)
carmenintech
77
5.5k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.4k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
320
The SEO identity crisis: Don't let AI make you average
varn
0
560
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
330
Speed Design
sergeychernyshev
33
2.1k
Statistics for Hackers
jakevdp
799
230k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
660
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.6k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
Facilitating Awesome Meetings
lara
57
7.1k
Transcript
Функции double linear(double a, double x, double b) { return
a * x + b; } void main() { double a = 1.5, b = 1; int x; double y; for(x = 0; x < 5; x++) { y = linear(a, x, b); printf("%.2f*x+%.2f at %d = %.2f\n", a, b, x, y); } } > 1.50*x+1.00 at 0 = 1.00 > 1.50*x+1.00 at 1 = 2.50 > 1.50*x+1.00 at 2 = 4.00 > 1.50*x+1.00 at 3 = 5.50 > 1.50*x+1.00 at 4 = 7.00
Массивы Массив — последовательная область памяти, для набора однотипных данных.
int array[4]; array[0] array[2] int int int int int int int int int int int int
int a0, a1, a2, a3, a4, a5; a0 = pow(10,
0); a1 = pow(10, 1); a2 = pow(10, 2); a3 = pow(10, 3); a4 = pow(10, 4); a5 = pow(10, 5); printf("%d %d %d %d %d %d\n", a0, a1, a2, a3, a4, a5);
for(i = 0; i < 6; i++) { ai =
pow(10, i); // NO printf("%d ", ai); // NO }
int i; int a[6]; for(i = 0; i < 6;
i++) { a[i] = pow(10, i); printf("%d ", a[i]); } > 1 10 100 1000 10000 100000
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 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) { return c * 9/5 +
32; } int fahrenheit_to_celsius(int f) { return (f - 32) * 5/9; } 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("Zero?!!"); 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]); } }