Skip to content

Instantly share code, notes, and snippets.

@mAlishera
Created March 25, 2017 22:27
Show Gist options
  • Save mAlishera/1da0a5863cb533fb6bfbb0a30743793d to your computer and use it in GitHub Desktop.
Save mAlishera/1da0a5863cb533fb6bfbb0a30743793d to your computer and use it in GitHub Desktop.
//
int x;
int d[] = {3, 4, 5, 6};
x = d[2] + 3*d[3];
const int N = 10;
int i, a[N];
for(i=0; i<N; i++) {
printf("Введите a[%d]: ", i)
scanf("%d\n", &a[i]);
}
//
#include <stdlib.h>
#include <time.h>
srand
rand - from 0 to RAND_MAX
RAND_MAX = 32767
const int N=10;
const unsigned short RANGE = 100;
int i, a[N];
srand((unsigned) time(NULL));
for (i=0; i<N; i++) {
a[i] = int (rand() %RANGE);
printf("%3d\n", a[i]);
}
//
const int N=5;
int a[N] = {1,2,3,4,5};
int i, s;
for (i=0, s=0; i<N; s+=a[i++]);
printf ("s = %d", s);
//Нахождение минимального и его индекса
const int N=5;
int a[N] = {3,1,2,5,4};
int min = a[0], j(0);
for (int i; i<N; i++)
if (a[i]<min) {
min=a[i];
j = i;
}
//
const int N=5;
int a[N] = {3,1,2,5,4};
int i(0), count(0);
int b[N];
for (; i<N; i++)
if (!(a[i]%2))
b[count++] = a[i];
//
const int N=5;
int a[N] = {3,1,2,5,4};
int i(0), count(0);
int b[N] {0};
printf("\n\t" );
for(i=0; i<N; i++)
printf("%2d\n", a[i]);
printf("\n\t");
for(i=0; i<count; i++)
printf("%2d\n", b[i]);
// Сортировка массива
// Пузырьковая сортировка
const int N=5;
int a[N] = {5,4,3,2,1};
int tmp;
for(int i=0; i<(N - 1); i++)
for(int j=0; j<(N - 1)-i; j++)
if(a[j]>a[j+1]) {
tmp = a[j]; a[j] = a[j+1];
a[j+1] = tmp;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment