language
large_stringclasses
1 value
text
stringlengths
9
2.95M
C
#ifndef __Math__ #define __Math__ double saturate(double val){ return max(0,min(val, 1)); } double smoothStep(double edge0, double edge1, double x) { double t = saturate((x - edge0) / (edge1 - edge0)); return t * t * (3.0 - 2.0 * t); } double interpolateCos(double t){ return (cos(PI + saturate(t) * PI) +...
C
#include<stdio.h> int factorial (int); int main() { int user_input = 0; printf("Enter number: "); scanf("%d", &user_input); printf("Factorial of %d is: %d\n", user_input, factorial(user_input)); } int factorial (int i) { if (i > 0) return i*factorial(i-1); else return 1; }
C
#include <stdlib.h> #include <stdio.h> #include <string.h> #include "historique.h" void ajoutListeHistorique (int action, float valeur, listeHistorique liste) { Historique* nouvelleAction = (Historique*)malloc(sizeof(Historique)); nouvelleAction->action = action; nouvelleAction->valeurPrecedente = valeur; nouve...
C
#include <stdio.h> #include <stdlib.h> #include "decoder.h" void read_file(){ char *hexa; int num, instruction = 0, opcode_num, option, a = 0, contador = 0, i = 0; int valid = 0; hexa = (char *)calloc(10000000, sizeof(char)); FILE *arquivo; arquivo = fopen("dados.txt","r"); if(arquivo == NULL){ printf("Arqui...
C
#include <stdio.h> #include <stdlib.h> #include <string.h> #include "sums.h" int sumline(const char* line) { if(line == NULL) /* null guard */ { return 0; } if(strlen(line) == 0) /* trivial case */ { return 0; } int sum = 0; /* running total */ unsigned int...
C
/************************** frame.c ******************************************/ /* Subor: frame.c - */ /* Projekt: Implementacia interpretu ifj16 */ /* Varianta zadania: a/2/II ...
C
#include <stdio.h> #include <float.h> int main(void) { int cost = 12.99; double d1 = 1.0 / 3.0; float f1 = 1.0 / 3.0; printf("%.6f,%.6f,%d,%f\n", d1, f1, cost, cost); printf("%.12f,%.12f\n", d1, f1); printf("%.16Lf,%.16Lf\n", d1, f1); printf("%f,%f\n", FLT_DIG, DBL_DIG); getchar(); return 0; }
C
//======================================================================================== // lib eeprom 24Cxx // // 14/05/21 Jonny zez //=======================================================================================...
C
/*--------------------------------------------------------------------------- * Helper functions to handle the current object. * *--------------------------------------------------------------------------- */ #ifndef I_CURRENT_OBJECT__ #define I_CURRENT_OBJECT__ #include "driver.h" #include "lwobject.h" #include ...
C
#include <stdlib.h> #include "ll_ili9341_init.h" #include "ll_spi_ili9341.h" #include "ll_spi_dma_io.h" #include "spi_tft.h" #include "font24.h" #include "font20.h" #include "font16.h" #include "font12.h" #include "font8.h" uint16_t dsp_width; uint16_t dsp_height; extern uint32_t dma_spi_part; uint8_t frame_buffer[4...
C
void write(int n, float b) { int i; int len; len = 0; for (i = 0; i < n; i = i + 1) { len = n + 1; } } int main(int argc) { int n; float b; b = 0.0; n = 128; write(n, b); return 0; }
C
#include <stdio.h> #include <string.h> #include <student_info_system/base.h> #include <student_info_system/util.h> int show_menu(const menu *menus, size_t menu_num, char *exist_str) { int tmp; int choose = 0; short invalid_input = 1; char _exist_str[255], hint[40], r_hint[40]; if (exist_str == NU...
C
#include<stdio.h> #include<stdlib.h> int main() { /* this program is awesome */ int a,b,c,d,e,f,g; // right //printf("") scanf("%d %d",&a,&b); printf("%d %d\n",a+b,a-b); }
C
#include <yaml.h> #include "myaml.h" #include "utils.h" #include <stdlib.h> #include <string.h> #include <assert.h> #include <stdarg.h> void dump_myaml_t(struct myaml_t *t, int level) { char header[30]; int i = 0; if (!t) return; snprintf(header, 20, "%.*s", level * 2, " "); switch (t->type)...
C
//Write a program to generate Armstrong number. #include<stdio.h> void main() { int r; long int number=0,c,sum=0,temp; printf("Enter an integer upto which you want to find armstrong numbers\n"); scanf("%ld",&number); printf("Following armstrong numbers are found from 1 to %ld\n",number); for(c=1;c<=number...
C
#include <stdio.h> int main(){ char *str = "OfdlDSA|3tXb32~X3tX@sX`4tXtz"; int key=0; for(int i=0;i<=28;i++){ // key = (key+1) ^ 0x7; printf("%c",str[i]^7); } // printf("%s",str); /* OfdlDSA|3tXb32~X3tX@sX`4tXtz 0x1이랑 0x17을 바꾸면서 반복 check 함수 - key 에 들어갈 수 있는 값은 7 아니면 0 */ }
C
#ifndef DIGIT_H #define DIGIT_H /* Data Structures */ // Stores a single digit and its label. typedef struct Digit { float* pixels; // vector of length numPixels that holds data arry, in row major format int label; // set to -1 if unlabelled int numRows; int numCols; int numPixels; } Digit; // Store...
C
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <time.h> #include <getopt.h> #include <errno.h> #include <sys/mman.h> #include <sys/stat.h> #include <fcntl.h> #include "fileutils.h" #include <sodium.h> #include "keyfiles.h" int fileno(FILE *); struct parameters { sh...
C
#include "state.h" #include "gpio.h" #include "climate.h" #include <stdlib.h> #include <stdio.h> struct HouseState init_state() { struct HouseState state; get_sensor_data(&(state.temperature), &(state.humidity)); state.lamp01 = read_device(LAMP01); state.lamp02 = read_device(LAMP02); state.lamp03 ...
C
#include <stdio.h> #include <stdlib.h> int n,k; int f91(int); int main() { while(scanf("%d", &n),n!=0) { k=f91(n); printf("f91(%d) = %d\n",n,k); } return 0; } int f91(int n) { if(n<=100) return f91(f91(n+11)); else return n-10; }
C
//Diógenes Silva Pedro 11883476 void algoritmo1(int *values, int N){ int i, j = 0; //a int tmp; for (i = 0; i < N; i++){ //1. (a+b) 2. n.(2a+b) = a + b + 2an + bn for (j = 0; j < N; j++){ //1. n(a+b) 2. n(n.(2a+b)) = an + bn + 2an² + bn² if (values[j] > values[j...
C
#include <signal.h> #include <unistd.h> #include <stdlib.h> void foo (void); void bar (void); void subroutine (int); void handler (int); void have_a_very_merry_interrupt (void); int main () { foo (); /* Put a breakpoint on foo() and call it to see a dummy frame */ have_a_very_merry_interrupt (); return 0; ...
C
#include "xdvi-config.h" #include "dl_list.h" size_t dl_list_len(struct dl_list *list) { size_t len = 0; struct dl_list *ptr; for (ptr = list; ptr != NULL; ptr = ptr->next, len++) { ; } return len; } /* Insert item to the list and return the result. */ struct dl_list * dl_list_insert(struct dl_list ...
C
#ifndef UTIL_H__ #define UTIL_H__ #define __USE_BSD 1 #define INPUT_WIDTH 7000 #define INPUT_HEIGHT 7000 #include <stdio.h> #include <time.h> #include <sys/time.h> void** alloc_2d(size_t y_size, size_t x_size, size_t element_size); #define TIME_IT(ROUTINE_NAME__, LOOPS__, ACTION__)\ {\ printf(" Timing '%s...
C
#define NULL ((void*)0) typedef unsigned long size_t; // Customize by platform. typedef long intptr_t; typedef unsigned long uintptr_t; typedef long scalar_t__; // Either arithmetic or pointer type. /* By default, we understand bool (as a convenience). */ typedef int bool; #define false 0 #define true 1 /* Forward d...
C
#include<stdio.h> #include<stdlib.h> struct node{ int data; struct node* next; }; int main() { struct node* head = NULL; push(&head,4); push(&head,5); push(&head,6); push(&head,7); swap(&head,6,5); show(head); } void push(struct node** head,int num) { struct node* new_node = (struct n...
C
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct{ char nome[50]; char endereco[100]; int matricula; } estudante; int main(void){ int num, i; printf("Digite o número de posições: "); scanf("%d", &num); estudante * p = (int *)calloc(num, sizeof(estudante)); if(!p) printf("Memória Insufici...
C
#include <stdio.h> int main(void) { int prviDanTin, drugiDanTin, treciDanTin, cetvrtiDanTin, prviDanTan, drugiDanTan, treciDanTan, cetvrtiDanTan; printf("Unesi koliko je Tin napravio koraka za 1. dan: "); scanf("%d", &prviDanTin); printf("Unesi koliko je Tin napravio koraka za 2. dan: "); scanf("%...
C
#include <stdlib.h> #include <stdio.h> int b[3], g[3], c[3]; int bgc(int a1, int a2, int a3) { /*printf("b%d g%d c%d\n", b[a1],g[a2],c[a3]);*/ return b[a1] + g[a2] + c[a3]; } int main() { int count; while (scanf("%d %d %d %d %d %d %d %d %d", b, g, c, b+1, g+1, c+1, b+2, g+2, c+2) == 9) { int best, n...
C
#include <stdio.h> #include <stdlib.h> #include <locale.h> #include <math.h> void main(){ setlocale(LC_ALL, ""); // Variaveis int escolha, valor01, valor02, valor03, soma, sub, div, mult, raiz; // op��es de escolhas matematicas printf("Escolha uma das opcoes abaixo:" "\n 1: Soma de 3 Valores ...
C
#include "function_pointers.h" /** * array_iterator - Entry point * @array: Array of numbers * @size: Size of array * @action: Function pointer to function * * Description: I dont know * Return: Nothing */ void array_iterator(int *array, size_t size, void (*action)(int)) { unsigned int i = 0; if ((size != 0) && (arr...
C
/* * ===================================================================================== * * Filename: branch1.c * * Description: Basics of branching * * Version: 1.0 * Created: 01/30/2018 08:51:46 AM * Revision: none * Compiler: gcc * * Author: Trevor Cul...
C
#include<stdlib.h> #include<stdio.h> #include<string.h> #include<math.h> #include"post_stats.h" void read_post_samples(char* file_name,live_point* psamps,unsigned long num_post_samps,unsigned num_dim) { FILE* infile; unsigned long i; unsigned j; double val; infile=fopen(file_name,"r"); if(infile!=NULL) { fo...
C
#include <stdio.h> int getMax (int *list, int n); //program sorts a user given list of numbers, and //organizes them in accending order. int main (void) { int n = 0; //number to be sorted int i = 0; //counter int list[n]; //array of numbers to be sorted int max = 0; //holds the arrays max index number from f...
C
#include <stdio.h> #include <conio.h> #define BASE_YEAR 1900 int is_leap(int year); long date_to_num(int day, int month, int year); int which_day(int day, int month, int year); void display_calender(int month, int year); int month_day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; char *month_name[] = {"Ja...
C
#include<stdio.h> int main() { int i,a[100],b[100],n,num,m; printf("input how many nums in array\n"); scanf("%d",&m); printf("input %d nums\n",m); for(i = 0; i < m; i++) { scanf("%d",&a[i]); //ԭ } printf("array you input is:\n"); for(i = 0; i < m; i++) { printf("%d ",a[i]); //ԭ } printf("\n--...
C
// %%cpp alarm_handle.c // %run gcc -g alarm_handle.c -o alarm_handle.exe // %run ./alarm_handle.exe ; echo $? # выводим так же код возврата #include <unistd.h> #include <stdio.h> #include <signal.h> #include <sys/types.h> static void handler(int signum) { static char buffer[100]; int size = snprintf(buffer, ...
C
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/wait.h> int main(int argc, char *argv[]) { int *x = NULL; printf("x is %p\n", x); free(x); printf("x is %p\n", x); }
C
///////////////////////////////////////////////////////////// // // Write a program which accept file name from user and print // number of occurrence of Particular cWord in that file. // ///////////////////////////////////////////////////////////// //Header #include<stdio.h> #include<fcntl.h> #include<stdlib.h> #de...
C
#include <armux/memory.h> #include <stdlib.h> #include <stdio.h> Byte readMemBlockByte(void *memBlock, UWord addr) { ARMMemBlock *block; block = (ARMMemBlock *)memBlock; return block->memory[addr - block->base_addr]; } Halfword readMemBlockHalfword(void *memBlock, UWord addr, Endianess end) { ARMMemBlock *block;...
C
#include <stdio.h> #include <conio.h> #include <stdlib.h> struct Registro { int valor; struct Registro *prox; }; struct Registro *aux, *inicio = NULL, *final = NULL; /*funo responsvel por criar a lista*/ struct Registro* cria(void) { return NULL; } /* funo com tipo de retorno ponteiro para estrutura, real...
C
#include "jutil.h" #ifndef abs #define abs(a) ((a) >= 0 ? (a) : -(a)) #endif #define VERBOSE void checkSTREAMresults (REAL* a, REAL* b, REAL* c, int iNumElements, int iNumIterations) { REAL aj,bj,cj,scalar; REAL aSumErr,bSumErr,cSumErr; REAL aAvgErr,bAvgErr,cAvgErr; double epsilon; ssize_t j; int k,ierr,err; ...
C
#include "deque.h" #include <assert.h> int main() { Deque *deque = deque__create(); deque__print(deque); deque__push_back(deque, 1); deque__push_front(deque, 99); deque__print(deque); deque__push_back(deque, 2); deque__push_back(deque, 3); deque__push_front(deque, 98); deque__p...
C
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <termios.h> #include <inttypes.h> #include <string.h> #include <sys/types.h> #include <sys/time.h> #include <sys/select.h> #include <sys/ioctl.h> #include "serial.h" int uart0_filestream = -1; void serial_init(void) { uart0_fi...
C
#include <stdlib.h> /** * alloc_grid - Create a 2 dimensionals array * @width: Width of grid, aka # of columns * @height: Height of grid, aka # of rows * * Return: Pointer to 2D array, NULL if it fails */ int **alloc_grid(int width, int height) { int **grid; int a, b; a = 0; if (width <= 0 || height <= 0) ...
C
#include <pthread.h> #include <malloc.h> int thread_flag; pthread_mutex_t thread_flag_mutex; /* Allocate a temporary buffer. */ void* allocate_buffer (size_t size){ return malloc (size); } /* Deallocate a temporary buffer. */ void deallocate_buffer (void* buffer){ free (buffer); } void do_work (){ /...
C
#include "signal_handler_thread.h" #include <stdio.h> #include "signal.h" #include "uart.h" void signalHandlerThread(void* arg) { signal_handler_thread_t* this = (signal_handler_thread_t*)arg; char input[16]; osStatus_t status; while (1) { if (status != osOK) continue; if (UARTPeek('\r') < 0) { ...
C
#include <stdio.h> int main() { /* * struct <结构体名> { * <成员类型> <成员名>; * ... * } <结构体变量>; * */ // 定义结构体变量 /* * 结构体也是内存中的一片空间 * 结构体在内存中占用的地址头(Person)就是结构体中第一个变量的地址(name) * */ struct Person { char *name; int age; char *id; }; // 不赋值初始化的时候所有的值都是默认值,由编译器决定 struct Person person ...
C
#include <stdio.h> #include <stdlib.h> int main() { int *p = 0x5DC; printf("p = Hexadecimal: %p Decimal: %d\n",p,p); // Incrementa p em uma posição p++; printf("p = Hexadecimal: %p Decimal: %d\n",p,p); // Incrementa p em 15 posições/ avança 15 posições de 4 bytes na memória p = p + 15; printf("p = Hexadecima...
C
#include "utils.h" ino_t get_ino(const char *path) { struct stat buf; if (stat(path, &buf) != 0) return 0; uid_t uid = getuid(); if (buf.st_uid != uid && uid != 0) return -1; return buf.st_ino; } bool is_dir(const char *path) { struct stat buf; stat(path, &buf); return S_ISDIR(buf.st_m...
C
#include "holberton.h" /** * _strstr - Entry point * @haystack: the char for print * @needle: null character or needle * Return: return a variable */ char *_strstr(char *haystack, char *needle) { int i; while (*haystack) { for (i = 0; needle[i]; i++) { if (needle[i] != haystack[i]) break; } if (...
C
//#include <string.h> //#include <stdio.h> //#include <time.h> //#include <stdlib.h> //#include <ctype.h> // // //#include "array.h" //#include "dict.h" // //#define NUM_ARGC 2 //#define NO_ENOUGH_NUM_ARGC 1 //#define CANT_READ_DICT 2 //#define CANT_REPLACE_WORDS 3 // //#define LINE_BUFFER 256 //#define WORD_BUFFER 256...
C
#include <stdio.h> int main() { int a=0, i=1, n=0, raz=0; scanf("%d", &n); for(i=1; i<=n; i++) { scanf("%d", &a); a=a*(-1); raz=raz+a; } printf("%d\n",raz); return 0; }
C
#include <stdio.h> #include <unistd.h> #include <string.h> #include <errno.h> static int usage() { fprintf(stderr,"rmdir <directory>\n"); return -1; } int rmdir_main(int argc, char *argv[]) { int symbolic = 0; int ret; if(argc < 2) return usage(); while(argc > 1) { argc--; arg...
C
#ifndef __SEQLIST_H__ #define __SEQLIST_H__ #include <stdbool.h> typedef int DataType; ////̬˳ #define Dynamic_List #define DEFAULT_CAPACITY 3 #define DEFAULT_ADD 2 typedef struct SeqList { DataType *data;// int sz;//Ч int capacity;// }SeqList, *pSeqList; ////̬˳ //#define static_List // //#define MAX...
C
#include <stdio.h> #include <stdlib.h> #include <string.h> #include "estructuragenerica.h" #define TAMANIO 10 #define OCUPADO 0 #define LIBRE 1 int eGen_init( eGenerica listado[],int limite) { int retorno = -1; int i; if(limite > 0 && listado != NULL) { retorno = 0; f...
C
#include <stdio.h> main(){ int c, condition; condition = (c = getchar()) != EOF; switch (condition) { case 1: printf("El valor es 1\n"); break; case 0: printf("El valor es 0\n"); break; default: printf("El valor es otro\n"); } }
C
#ifndef JUSTPOINT_H #define JUSTPOINT_H /************************************************************************************ * PROTOTIPOS DE FUNCIONES ***********************************************************************************/ void checkname(const char* name,const char* mainname); /*Funcion que se encarga d...
C
#include "functions.h" /****************************************************************************** 1- INITIALISATION D'UN RECTANGLE ******************************************************************************/ Rectangle * createRectangle(float hauteur, float largeur, float x, float y, float xfin, float yfin, ...
C
#include <stdio.h> #include <stdlib.h> #include <locale.h> #include <string.h> #define lb fpurge(stdin) #define lt system("clear") #include "tema.h" #include "escolha.h" #include "inserir.h" #include "errou.h" int main () { printf("\033[34m"); //cor da fonte azul int menu=0; while(menu!=2){ // primeiro while ...
C
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <errno.h> #include <sys/sem.h> #include <sys/ipc.h> #include <sys/shm.h> #include <string.h> #include <sys/resource.h> #define TAMBUF 1024 #define CANTMSJS 1000 /* Sale del programa emitiendo un error */ void error(char *error); u...
C
#include <stdio.h> int main() { unsigned long long int ve[61]; int i, con, con1; ve[0] = 0; ve[1] = 1; for ( i = 2; i < 61; ++i) { ve[i] = ve[i-1] + ve[i-2]; } scanf("%d", &con); for ( i = 0; i < con; ++i) { scanf("%d", &con1); printf("Fib(%d) = %l...
C
// // day03.c // 42_C_piscine // // Created by 游宗諭 on 2020/8/10. // Copyright © 2020 游宗諭. All rights reserved. // #include "day03.h" #include "ft_putchar.h" void test_day03(void) { int nbr = 0; ft_ft(&nbr); printf("%d",nbr); ft_putchar('\n'); int a = 1; int b = 2; ft_swap(&a, &b); p...
C
//Atta Ebrahimi #include "mymalloc.h" #include <unistd.h> #include <stdio.h> //Keeps track of beginning and end void *base = NULL; void *curr_pos = NULL; //Represents doubly linked list used to keep track of memory typedef struct metadata_node *block; struct metadata_node { int chunk_size; //stores s...
C
#include<stdio.h> #include<conio.h> #include<stdlib.h> typedef struct tr { int item; struct tr* left; struct tr* right; }bst; bst *save, *ptr,*parent,*node; int ter=0,terrec=0,n=0; void display(bst *ptr, int level){ int i; if(ptr!=NULL){ display(ptr->right, level+1); printf("\n"); for (i = 0; i < level; i+...
C
#include <stdio.h> #include <stdlib.h> void swap(int *a, int *b, int *c) { *b ^= *c; *c ^= *b; *b ^= *c; *a ^= *b; *b ^= *a; *a ^= *b; } /* * Al llamar al programa se piden tres caracteres a, b y c, * se llama a la funcion swap con estos caracteres, * y finalmente se imprime el valor actual de las variables * d...
C
#include<stdio.h> #include<stdlib.h> #include<string.h> #define MAXCHAR 1000 void main() { FILE *p,*fsym,*fop,*fl; char label[100],opcode[100],operand[100],c,optab[100]; int value,locctr,sa=0,otp,op1,len; p = fopen("input.txt","r"); fsym = fopen("symtab.txt","w"); fl = fopen("length.txt","w"); fscanf(p...
C
/** * @file log.c * @author malin * @mail malinbupt@163.com * @time 二 10/13 16:59:19 2015 */ #include <fcntl.h> #include <unistd.h> #include <stdlib.h> #include <time.h> #include <string.h> #include <stdarg.h> #include <stdio.h> #include "log.h" #include "../util/vector.h" #include "../algo/str.h" int l...
C
#pragma once #include <stddef.h> #ifdef __cplusplus extern "C" { #endif // These are possible errors that can happen with mmap_s3 #define MMAP_S3_OK 0 // everything went okay #define MMAP_S3_ERRNO 1 // some syscall failed, use "errno" to check how #define MMAP_S3_NOT_FOUND 4 ...
C
#pragma once #include "Material.h" #include "Date.h" #include "DynamicArray.h" #include <string.h> typedef struct { Material* _material; char* _operationType; }Operation; Operation* createOperation(Material* material, char* operationType); void destroyOperation(Operation* operation); Operation* copyOperation(Opera...
C
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_part_of_the_stack.c :+: :+: :+: ...
C
#include<stdio.h> int main() { int x,y; scanf("%4d %3d",&x,&y); printf("%d %d\n",x,y); }
C
//Dhruv Modi //110009086 //14-April-2020 //server.c #include <stdio.h> #include <sys/socket.h> #include <arpa/inet.h> #include <sys/signal.h> #include <unistd.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> #include <sys/wait.h> void servicePlayers(int TOTO,int TITI, int zs){ //function cal...
C
#include <stdio.h> #include <stdlib.h> struct Array{ int A[10]; int size; int length; }; void Append(struct Array *arr, int x){ if (arr->length < arr->size){ arr->A[arr->length++] = x; } } void Insert(struct Array *arr, int index, int x){ int i; if(index >= 0 && index...
C
#include <pthread.h> #include <stdio.h> #include <stdlib.h> #include <time.h> #include <unistd.h> #define NUM_FILOS 5 pthread_mutex_t forks[NUM_FILOS]; void actions(){sleep(1+rand()%5);} void *life(void *ptID){ long tid = (long) ptID; srand(time(NULL)+tid); if(NUM_FILOS<2){ printf("No puedo com...
C
/* Evaluate U.S. readability grade computed by the Coleman-Liau formula */ #include <stdio.h> #include <cs50.h> #include <math.h> int count_letters(string text); //count letters in a text int count_words(string text); // count words in a text int count_sentences(string text); // count sentences in a text // calculat...
C
#include<stdio.h> #include<string.h> void stringconvert(char s[], int n){ char c[500][500]; int row=0, column=0, flag=1; int i, j; for(i=0; i<strlen(s); i++){ c[row][column] = s[i]; if(row == n-1){ flag = 0; } if(row == 0){ flag = 1...
C
static int cmp(int *a, int *b) { return *a - *b; } static inline int get(char *a, int n) { return (a[n / 8] >> (n % 8)) & 1; } static inline void set(char *a, int n) { a[n / 8] |= 1 << (n % 8); } int main() { int N, M, i, *k; char *res; #ifdef ONLINE_JUDGE scanf("%d%d", &N, &M); k = malloc(M * sizeof(int)); f...
C
#include "boot.h" #define SECTSIZE 512 void bootMain(void) { /* 加载内核至内存,并跳转执行 */ char* buf = (char*)0x400000; /* loading kMain.elf to memory */ for(int i=0; i<200; i++){ readSect((void*)(buf + i*SECTSIZE), i+1); } struct ELFHeader *elf = (struct ELFHeader*) buf; struct ProgramHeader *ph,*eph; ph = (stru...
C
/** * @file Joy_state.h * @brief Joystick state operations */ #ifndef JOY_STATE_H #define JOY_STATE_H /** * @brief joystick directions */ typedef enum { LEFT, RIGHT, UP, DOWN, NEUTRAL, } Dir; /** * @brief joystick state */ typedef struct Joy_state { int x; // -100 -> 100 int y; //...
C
/* union-test3.c -- test copying data into H/EDB's with union Jim Raines, 16Nov99 Result: The union ub2 works fine but writing to edb2.abEDB doesn't seem to read out right from edb2.h.d.X. I think it is an alignment problem in that the union byte2 isn't really only one byte long. */ #include <stdio.h...
C
/** * Polytech Marseille * Case 925 - 163, avenue de Luminy * 13288 Marseille CEDEX 9 * * Ce fichier est l'oeuvre d'eleves de Polytech Marseille. Il ne peut etre * reproduit, utilise ou modifie sans l'avis express de ses auteurs. */ /** * @author GAUDARD Damien <damien.gaudard@etu.univ-amu.fr> * @author AIT S...
C
/** @file mutex_type.h * @brief This file defines the type for mutexes. */ #ifndef _MUTEX_TYPE_H #define _MUTEX_TYPE_H typedef struct mutex { int valid; int lock; int tid; int count; int count_lock; } mutex_t; #endif /* _MUTEX_TYPE_H */
C
/* ATmega 2560, arduino */ #define F_CPU 16000000 #define LED 5 #include <avr/io.h> #include <util/delay.h> #include <avr/interrupt.h> char timer_count = 0; char max_timer_count = 30; void run_timer() { OCR0A = 0xFF; // 8-bit counter OCR0B = 0x00; TIMSK0 |= (1 << OCIE0A); // compare in...
C
#include<stdio.h> int fib(int a) { if (a==0) return 0; if (a==1) return 1; return fib(a-1)+fib(a-2); } void main() { int i,n,s=0; printf("Enter no of elements"); scanf("%d",&n); printf("the series is:: "); for(i=0;i<n;i++) printf("%3d",fib(i)); printf("\n"); }
C
// // exp_mpi.c // // Created by Alina Shipitsyna on 09.04.2020. // Copyright © 2020 Alina Shipitsyna. All rights reserved. // #include "mpi.h" #include <stdio.h> #include <math.h> #include <stdlib.h> /*-----------------------------------------------------------------------------------------------------------------...
C
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<sys/types.h> #include<sys/socket.h> #include<netinet/in.h> #include<arpa/inet.h> void terminateSocket(int sockfd) { close(sockfd); } int * createClientSocket() { int result , sockfd; struct sockaddr_in address; sockfd = socket(AF_INET,SOCK_STREAM,...
C
/* advance */ #include <ansi.h> #include <attribute.h> inherit F_CLEAN_UP; void create() { seteuid(getuid()); } int add_attribute(object me, string attr, int amount) { if( me->query_point("attribute") < amount ) { write("AݩIƤALkɤHݩʡC\n"); return 1; } if( me->query_attr(attr, 1) + am...
C
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* render.c :+: :+: :+: ...
C
#include <sys/ioctl.h> #include <time.h> #include <assert.h> #include <errno.h> #include <math.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <ncurses.h> #define FPS 20 #define PROB_IGNITION 0.001 /* f */ #define PROB_GROWTH 0.025 /* p */ #define CMD_BUF_SIZE 50 #define die(...) do {fp...
C
// To calculate successive fibonacci number #include<stdio.h> long int fibonacci(int count); int main() { int count; auto n; printf("How many fibonacci numbers?="); scanf("%d",&n); printf("\n"); for(count=1;count<=n;++count) printf("\n i=%2d\tF=%ld",count ,fibonacci(count)); getch(); } long int fib...
C
// When a button is pressed, change the speed of an LED blink from 100ms to 1000ms. #include <avr/io.h> // Include neccesary libraries #include <util/delay.h> int main(void) // Main function { DDRB |= 1 << PINB0; // Data Direction Register for PortB; sets Pin0 (LED) output DDRB &= ~(1 << PINB1); // Data...
C
#include <fcntl.h> #include <unistd.h> #include <sys/types.h> #include <sys/socket.h> #include <sys/stat.h> #include <sys/wait.h> #include <arpa/inet.h> #include <netinet/in.h> #include <netdb.h> #include <stdlib.h> #include <string.h> #include <stdio.h> #include <errno.h> #define PATH_MAX 0x100 #define REQUEST_MAX 0x...
C
#include <sys/types.h> #include <sys/socket.h> #include <sys/time.h> #include <netinet/in.h> #include <netdb.h> #include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #include <errno.h> int main(int ac, char *av[]){ int sock; // descriptor del socket struct sockaddr_in dest; // di...
C
/*Вычислить значение функции D=(e^(-1/6)*√(a^2+ln⁡|b| )-tga)/(〖2cos〗^2 a^3 )*/ #include <stdio.h> #include <math.h> #include <locale.h> /*библиотека языков*/ int main() { setlocale(LC_ALL, "Rus");/*подключение русского языка*/ double a , b , D, k, z; do { printf("a="); fflush(stdin); } wh...
C
#ifndef COREATOMIC_H #define COREATOMIC_H /** @return whether the alignedDatum FAILED to increment. * The most common reason for a failure would be that an interrupt occurred during the operation. If you are sure the cause of failure isn't permanent then: do{}while(atomic_increment(arg)); */ extern "C" bool atomic_i...
C
//square of number using function #include<stdio.h> int squarenum(int a);//function prototype declaration int main() { int a,s; printf("enter the number:"); scanf("%d",&a); s=squarenum(a);//function call printf("s=%d\n",s); return 0; } int squarenum(int a)//function definition { int s; s=a*a; return(...
C
int main() { int n; scanf("%d",&n); int k=1,sum=0; while(k<=n) { sum+=k; k++; if(sum==n) { printf("YES"); return 0; } } printf("NO"); return 0; }
C
#define NOCCARGC /* no argument count passing */ extern char *Umemptr; /* ** Return the number of bytes of available memory. ** In case of a stack overflow condition, if 'abort' ** is non-zero the program aborts with an 'S' clue, ** otherwise zero is returned. */ avail(abort) int abort; { char x; if(&x < Umemptr) ...
C
#include "holberton.h" /** * *_strcpy - counting the length of a string *@dest: value waited from the main.c *@src: root * Return: Always 0. */ char *_strcpy(char *dest, char *src) { int c; for (c = 0; src[c]; c++) { dest[c] = src[c]; } dest[c] = '\0'; return (dest); }