Skip to content

Instantly share code, notes, and snippets.

@qassa
qassa / subtitution of positive number by zero
Created September 29, 2013 11:19
//выводит положительные числа, отрицательные заменяет нулями, нули не трогает
#include<conio.h>
#include<stdio.h>
void func (int a[],int SIZE){
int i=0;
for(;i<SIZE;i++){
if(a[i]<0)
a[i]=0;
printf("%d\n",a[i]);
}
}
@qassa
qassa / deleting characters from the line
Last active December 24, 2015 05:39
//удаление из строки введенного с клавиатуры символа
#include<conio.h>
#include<stdio.h>
void del (char *start,char WORD){
int i=0,j=0,k=0;
for(;start[i]!='\0';i++){
if (start[i]==WORD){
for(k=i;start[k]!='\0';k++)
start[k]=start[k+1];
i--;
}
@qassa
qassa / sum of the integer numbers row
Created September 29, 2013 11:43
// сумма целых чисел от 0 до x
#include<conio.h>
#include<stdio.h>
double sum (int n){
int i=0; double h=0;
for(;i<=n;i++)
h+=i;
return h;
}
int main (){
int x;
@qassa
qassa / division by three
Created September 29, 2013 12:00
остаток от деления на 3 (проверка деления на 3)
#include<conio.h>
#include<stdio.h>
double is3 (int n){
return n%3==0;
}
int main (){
double x;
double f;
scanf("%lf",&x);
f=is3(x);
@qassa
qassa / count even numbers in the interval
Created September 29, 2013 12:04
//найти количество четных чисел в промежутке между целыми
#include<conio.h>
#include<stdio.h>
int countChet (int n, int y){
int i=0,h=0,max,min;
if(n>y){
max=n; min=y;
} else {
max=y; min=n;
}
for(i=min;i<=max;i++)
@qassa
qassa / to archive the line
Last active December 27, 2015 19:28
пример простой архивации строки
#include<conio.h>
#include<stdio.h>
#include <string.h>
int main(){
char str[100], repeat;
gets(str);
int i=0, count = 1, k=0, tempCount =0, length=strlen(str);
repeat = str[0];
for (i=1;str[i]!='\0';i++)
{
@qassa
qassa / queue
Created November 22, 2013 19:45
Данные queue: MAXSIZ - (константа) максимальное количество элементов в очереди. data - массив данных. top - индекс первого элемента в очереди. Интерфейс queue: push - положить значение value в очередь q. В случае переполнения значение в очередь помещено не будет. pop - извлечь значение из очереди q. back - получить последний элемент из очереди q…
#include <stdio.h>
#include <assert.h>
#define MAXSIZ 10
typedef struct {
int data[MAXSIZ];
int top;
} queue_t;
@qassa
qassa / Java lerp
Last active May 2, 2017 07:41
lerp realization in Java using interpolation by time. Ability to set determine speed of object when it's moving on the straight line (X,Y) on the scene.
public int lerp(float start, float target, float duration, float timeSinceStart){
float value = start;
if(timeSinceStart>=0.0f && timeSinceStart < duration){
float range = target - start;
float percent =timeSinceStart / duration;
value = start + range * percent;
}
else if(timeSinceStart>=duration)
value = target;
return Math.round(value);
@qassa
qassa / Assign variable in while-loop conditional
Last active October 20, 2015 14:23
Assigning variable a in while-loop
int a = 0;
while((a=5) != 0 && 5 > 4){
System.out.println("Hello! It's a loop.");
}
@qassa
qassa / JavaScript First Animation
Last active November 4, 2015 09:46
Анимация плавно выезжающего элемента страницы с заданным значением таймера
var element = document.getElementById("im");
var currentPosition = element.offsetTop; //Получаем текущее положение блока, который будет выплывать
smoothAnimation = requestAnimationFrame(function anim(time) {
currentPosition++;
element.style.top = currentPosition +"px";
smoothAnimation = requestAnimationFrame(anim); // The animation would not stop after 1.5 sec if delete smoothAnimation in this line because the fucntion reference changes every time it's called
});
setTimeout(function(){