language
large_stringclasses
1 value
text
stringlengths
9
2.95M
C
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <fcntl.h> int main() { // read only char file1 = open("foo.txt", O_RDONLY); //read & write char file2 = open("outfoo.txt", O_RDWR); //reads from file printf("Reading! \n"); char info[9]; if(read(file1, info, 9) < ...
C
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> #include <fcntl.h> #include <sys/epoll.h> #include <sys/ioctl.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #define MAX_EVENTS 5 #define MAX_BUF 32 //here comes global variables // int g_server_port = 2777; int...
C
#include <stdio.h> #include <stdlib.h> int main(void) { float height, m, weight, BMI; printf("BMI\n"); printf("height(cm): "); scanf_s("%f", &height); printf("weight(kg): "); scanf_s("%f", &weight); m = height / 100; BMI = weight / (m*m); printf("BMI = %.1f\n\n", BMI); if (BMI < 18.5) pr...
C
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* read_map_textures.c :+: :+: :+: ...
C
#include <stdio.h> #define INT_SIZE sizeof(int) * 8 /* Bits required to represent an integer */ int main() { int raqam, sanamoq, i; printf("Har qanday raqamni kiriting "); scanf("%d", &raqam); sanamoq = 0; for(i=0; i<INT_SIZE; i++) { if((raqam >> i ) & 1) { ...
C
/* * pedro.leite.001@acad.pucrs.br */ #include <stdio.h> double fatorial(double); double fatorial(double n) { double r = 1L; double f; for (f = 1; f <= n; f = f + 1L) r = r * f; return r; } int main() { double n; scanf("%lf", &n); double f = fatorial(n); printf("N=%f\nF=%f\n", n, f); return 0; }
C
/* ** EPITECH PROJECT, 2019 ** 42sh ** File description: ** 42sh */ #include "../../../include/my.h" #include "../../../include/mysh.h" char *cpy_op(int i, char *str) { char *op = x_memset(0, my_strlen(str), sizeof(char)); int k = 0; if (!op) return (NULL); for (; str[i] != '\0' && str[i] != ...
C
#include <conf.h> #include <kernel.h> #include <proc.h> #include <paging.h> pt_t* global_page_table[4]; /*------------------------------------------------------------------------- * initialize global page tables which will map 16MB physical memory *----------------------------------------------------------------...
C
// C++ program to print pattern that first reduces 5 one // by one, then adds 5. Without any loop #include <iostream> using namespace std; // Recursive function to print the pattern. // n indicates input value // m indicates current value to be printed // flag indicates whether we need to add 5 or // subtract...
C
// === Source file: sorting.c === #include "sorting.h" double timestamp(void) { struct timeval tp; gettimeofday(&tp, NULL); return ((double)(tp.tv_sec * 1000.0 + tp.tv_usec / 1000.0)); } void print_array(int *arr, int size) { printf("["); for (int i = 0; i < size - 1; i++) printf("%i ", ar...
C
#include "libmx.h" void *mx_memmem(const void *big, size_t big_len, const void *little, size_t little_len) { char *b = (char*) big; char *l = (char*) little; bool flag; size_t i; size_t j; if (little_len == 0) return NULL; for (i = 0; i < big_len; i++, b++) { ...
C
#define OK 1 #define ERROR 0 #define TRUE 1 #define FALSE 0 #define MAXSIZE 1000 typedef int ElemType; typedef int Status; typedef struct { ElemType data; int cur; }Component, StaticLinkList[MAXSIZE]; Status InitList(StaticLinkList space)/*初始化一个静态数组列表*/ { int i; for (i = 0; i < MAXSIZE - 1; ++i) space[i].cur = i...
C
#include <stdio.h> #include <ctype.h> int read_line(char str[], int n); void capitalize(char str[], int n); #define MSG_LEN 60 int main(void) { char s[MSG_LEN+1]; int n; n = read_line(s, MSG_LEN); printf("%s", s); printf("\n"); capitalize(s, n); printf("%s", s); printf("\n"); return 0; } int ...
C
/* ** EPITECH PROJECT, 2019 ** Title ** File description: ** Description */ #include <stdlib.h> #include "istl/private/p_list.h" #include "istl/utility.h" list_t *list_create(meta_bundle_t meta) { list_t *list = malloc(sizeof(list_t)); if (list == NULL) return (NULL); list->size = 0; list->be...
C
/** * @file * @author * * @brief Biblioteca para operações diversas. * */ #ifndef UTILS_H #define UTILS_H #ifdef __cplusplus extern "C" { #endif #include <stdbool.h> static const char NEWLINE = '\n'; static const char ENDSTRING = '\0'; /** * @brief Limpa o buffer de entrada de dados. * @warning Cas...
C
#include <stdio.h> int factorial(int n); int main(void) { for(int i=1;i<=10;i++) { printf("%d! = %d\n", i, factorial(i)); } return 0; } int factorial(int n) { if(n<=1) return(1); else return(n * factorial(n-1)); }
C
# include <stdio.h> int main() { int n; scanf("%d", &n); int id[n], grade[n]; int k = 0; for (int i=0; i < n; i++) { grade[i] = 0; id[i] = 0; } for (int i=0; i < n; i++) { int id_buffer, grade_buffer, buffer; scanf("%d-%d %d", &id_buffer, &buffer, &grade_buffer); int j; for (j=0; j < k; j++) { ...
C
/* process devide then percent */ /* This peace of code was used to creat the logical pattern * for the program lgates.c so that the information of how * well the person being tested could see there results. */ #include "stdio.h" main() { int endcount; int num_right; /* variabl...
C
#include <iostream> using namespace std; int main() { int i,k,j,m,n,l; cout<<"enter row\n"; cin>>n; l=n; for(i=1 ; i<=n ; i++) { m=n; for(j=1 ; j<=n*m ; j++) { for(k=l ; k >=1 ; k--) { cout<<m; } m--; } l--; cout<<endl; } }
C
#include <stdio.h> #include <stdlib.h> #include "menu.h" #include "dicionario.h" #include "leituraTR.h" #include "DistEuclid.h" int baz; //O(1) int main (){ ...
C
/* * appbase.c * * Created on: 31 May 2016 * Author: ajuaristi <a@juaristi.eus> */ #include <curl/curl.h> #include <json-c/json_object.h> #include <modp_b64.h> #include <stdio.h> #include <stdlib.h> #include <malloc.h> #include <string.h> #include "main.h" #include "utils.h" #include "frame.h" #include "json...
C
#include<stdio.h> #include<stdlib.h> struct circle{ int x,y; int radius; struct circle* next; }; int main () { struct circle *a,*b,*c,*current; a = (struct circle *)malloc(sizeof(struct circle)); printf("пJĤ@Ӷꪺ(x,y):"); scanf("%d %d",&a->x,&a->y); printf("пJĤ@Ӷꪺb|:"); scanf("%d",&a->radius); a...
C
/* exploitme coded in a hurry by Yoann Guillot and Julien Tinnes, used 'man select_tut' as skeleton */ #include <stdlib.h> #include <stdio.h> #include <unistd.h> #include <sys/time.h> #include <sys/types.h> #include <string.h> #include <signal.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #i...
C
#include <stdio.h> #include <stdlib.h> #include <string.h> // Prompt was not a valid choice, notify user. void invalidPrompt(void) { printf("You entered an incorrect choice. Try again.\n"); return; }
C
#include <stdio.h> #include <math.h> #include <assert.h> #include <time.h> #include <stdlib.h> int MAXNUM = 50000000; int main(int argc, char *argv[]){ FILE *fp=NULL; assert((fp=fopen("./largdata.txt","w")) != NULL); int i=0,tmp,j=0,k=0; char ch[5] = {NULL}; srand((int)time(0)); if (argc > 1) MAXNUM = atoi(arg...
C
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* env.c :+: :+: :+: ...
C
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* rotation.c :+: :+: :+: ...
C
#include "mynet.h" int main(void){ char *buf, *p; char arg1[MAXLINE], arg2[MAXLINE], content[MAXLINE]; int n1=0,n2=0; if((buf=getenv("QUERY_STRING")) != NULL){ p = strchr(buf, '&'); *p = '\0'; strcpy(arg1, buf); strcpy(arg2, p+1); n1 = atoi(arg1); n2 = atoi(arg2); } sprintf(content,"QUERY_STRING=%s...
C
#include<stdio.h> #include<stdlib.h> int selection_sort(int a[],int h) { int i,j,k=0,t; for(i=0;i<h-1;i++) { for(j=i+1;j<h;j++) { if(++k&&a[j]<a[i]){ t=a[j]; a[j]=a[i]; a[i]=t;} } } return k; } int main(){ int *a,n,i,t; scanf("%d",&n); a=(int*)malloc(n*sizeof(int)); for(i=0;i<n;i++) scanf("...
C
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_export.c :+: :+: :+: ...
C
/*------------------------------------------------------------------------------------------------ * Author : Rammya Dharshini K * Date : Sat 17 Jul 2021 15:45:04 * File : c_sample_Chapter-1_Program-9_type_modifiers.c * Title : C basic datatypes * Description : A...
C
/* * Alauddin Ansari * 2018-11-20 * ATtiny85 Watchdog settings */ #include <avr/sleep.h> #include <avr/wdt.h> #ifndef cbi #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) #endif #ifndef sbi #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) #endif // Watchdog Interrupt Service / is executed when watchdog ti...
C
#pragma once #include<string.h> #include<stdio.h> #include "MU_declaration.h" static char PATH[256]; inline void musnake::initPath(char* path) { char* p = PATH; strcpy(PATH, path); while (*p)p++; while (*p != '\\' && *p != '/')p--; *(++p) = 0; } inline void musnake::catPath(char* dest, char* relative) { str...
C
// Lined list create,display,insert,insert_At_End, delete, n_th_node, palindrom operations #include<stdio.h> #include<stdlib.h> struct ListNode{ int data; struct ListNode *next; }; struct ListNode *head = NULL,*tail = NULL; struct ListNode *getNodeMemory(){ struct ListNode *temp; temp = (struct ListNode *)malloc...
C
#include "types.h" #include "stat.h" #include "user.h" #include "fs.h" #define NCHILD 30 // number of children struct perf { int ctime; // process creation time int ttime; // process termination time int stime; // the time the process spent in the SLEEPING state int retime; // the time the process spent in...
C
/* * Game.h * * Contains our Game interface implementation * Each function is documented below * */ #ifndef GAME_H_ #define GAME_H_ #include "game_structs.h" /************************* NODE GETTER AND SETTER FUNCTIONS ******************************/ /* * The function gets type, x, y and returns * the valu...
C
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_recursive.c :+: :+: :+: ...
C
#include <ctype.h> #include <limits.h> #include <stdbool.h> #include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <string.h> static bool print(const char* data, size_t length) { const unsigned char* bytes = (const unsigned char*) data; for (size_t i = 0; i < length; i++) { if (putchar(bytes[i]) == EO...
C
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* lst_sort.c :+: :+: :+: ...
C
#include <stdio.h> #include <sys/time.h> #include <stdbool.h> #include <math.h> #include "analisis_estadistico.h" #include "procesos_poisson.h" #include "gen_continuas.h" #define CANT_ITERACIONES 1000 #define TIEMPO_FUNC_SERVER 8 #define FREC_TIEMPO_ARRIBOS 4 #define FREC_TIEMPO_SERVICIO 4.2 #define CANT_CLIENT_SIMU...
C
#include<stdio.h> //for a power n int power(int base,int exp){ if(exp!=0){ return(base*power(base,exp-1)); } else return 1; } int main(){ int base,exp,result; printf("Enter base number and power number :\n"); scanf("%d%d",&base,&exp); result=power(base,exp); printf("%d^...
C
#include <stdio.h> #include <stdlib.h> #include <errno.h> #include <string.h> #include <sys/types.h> #include <sys/ipc.h> #include <sys/msg.h> struct mensaje { long mtype; char mtext[100]; }; int main(int argc, char *argv[]) { struct mensaje buf; int msqid; key_t key; long mtype; if ( arg...
C
/*This program accesses elements of an array using the array name, *and using pointers. */ #include <stdio.h> #define NROWS 3 #define NCOLS 3 void main(){ long array[NROWS][NCOLS]={ {10L,11L,12L}, {20L,21L,22L}, {30L,31L,32L} }; long *plong=NULL; int index=0; int index2=0; /*The significance of next line is that plo...
C
#include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <termios.h> #include <unistd.h> void dumpTermios(const struct termios *t) { printf("c_iflag: %08x\n", t->c_iflag); printf("c_oflag: %08x\n", t->c_oflag); printf("c_cflag: %08x\n", t->c_cflag); printf("c_lflag: %08x\n", t->c_lflag); } v...
C
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <stdbool.h> #include <sys/types.h> #include <sys/stat.h> /* name is obvious*/ bool file_exists(const char* file) { if(access(file, F_OK ) != -1) { return true; } else { return false; } } /* simple function...
C
#include "usertraps.h" #include "misc.h" #include "producer.h" void main (int argc, char *argv[]) { //uint32 h_mem; // Handle to the shared memory page sem_t s_procs_completed; // Semaphore to signal the original process that we're done //init the semaphores unsigned int h_mem; molecules *mol; ...
C
#include <stdio.h> #include <string.h> #include <errno.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> int main(int argc, char* argv[]) { int sockfd; struct sockaddr_in server_addr; struct sockaddr_in client_addr; int sin_size, iDataNum; char buffer[4096]; ...
C
#include <stdio.h> #include <time.h> #include <string.h> #include <stdlib.h> typedef struct _Book{ int book_id; //도서번호 char *book_name; //도서명 char *purblisher; //출판사 char *writer; //저자명 long isbn; //ISBN char *local; //소장처 char book_rent; //대여가능 여부 st...
C
#include <linux/types.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <poll.h> #include <sys/select.h> #include <sys/time.h> /* 定义按键值 */ #define KEY_VALUE 0X0F /* 按键按下键值 */ #define KEY_INVAL 0X00 /* 无效的按键值 */ ...
C
#include <stdio.h> #include<time.h> int binarys(int a); int main() { int x,n; clock_t start,end; printf("Enter a number to find the square root"); scanf("%d",&x); start=clock(); { n=binarys(x); printf("Square root of %d is %d \n",x,n); } end=clock(); double t=(double)(end-start)/(double)(CLOCKS_PER_SEC); printf("Runt...
C
#ifndef QUEUE_H_ #define QUEUE_H_ #include <stdint.h> struct queue_t { uint8_t *buffer; unsigned int size; uint8_t head_idx; uint8_t tail_idx; }; void queue_init(struct queue_t* q); void queue_push_back(struct queue_t* q, uint8_t c); uint8_t queue_pop_front(struct queue_t* q); int queue_empty(struc...
C
/* Сегмент памяти Данные (Data) Также в сегменте памяти данные хранятся статические переменные. Статические переменные создаются внутри функций с помощью ключевого слова static. Такие переменные создаются и инициализируются только один раз, во время первого вызова функции. Во время последующих вызо...
C
/** *Author: wuyangchun *Date: 2012-06-05 *Description: 哈希表, 大小不够的时候会自动扩展,但数据被移除的时候不会自动缩小,需要手动调用, 这样可以避免添加和删除的时候刚好在自动扩展的边界上,导致不停的调整哈希表大小 * **/ #ifndef CLIB_HASH_H_ #define CLIB_HASH_H_ #include <clib/types.h> #ifdef __cplusplus exte...
C
//pc2.c #include <stdio.h> #include <stdlib.h> #include <pthread.h> #include <semaphore.h> #include <time.h> #define P 2 #define C 4 #define N 20 #define iteraciones 30 sem_t mutex; sem_t empty; sem_t full; int buffer[N]; int indiceProd=-1; int indiceCons=-1; int main(){ pthread_t hProd[P], hCons[C]; int vProd[P...
C
#include<stdio.h> //#include<conio.h> void main() { float area,h,w; //clrscr(); printf("Enter Height of Rectangle: "); scanf("%f",&h); printf("Enter Width of Rectangle: "); scanf("%f",&w); area=h*w; printf("Area of Rectangle is: %0.2f",area); //getch(); }
C
#include <stdio.h> #include <stdlib.h> #include <string.h> #define BUFFER_SIZE 192 //strcpyn(buffer, 192, argv[1], strlen(argv[1])) void strcpyn(char * destination, unsigned int destination_length, char * source, unsigned int source_length) { unsigned int i; for (i = 0; i <= destination_length && i <= source_leng...
C
/* * File: service.c */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> #include <arpa/inet.h> #include <sys/wait.h> #include <signal.h> #include "service.h" #include "util.h" ...
C
// // SeqList.c // SeqList // // Created by Lrc mac on 2018/6/19. // Copyright © 2018年 Lrc mac. All rights reserved. // #include <stdio.h> #include "SeqList.h" void SeqListInit(SeqList* pSeq) { for (int i = 0; i<MAX_SIZE; i++) { pSeq->_array[i] = 0; pSeq->_size = 0; } } void SeqListPus...
C
//---------------------------------------------------------------------------- // support functions and macros for C style strings use //---------------------------------------------------------------------------- #include <string.h> inline void CopyString( char *pszDest, int nDestSize, const char *pszOrig) { if (ps...
C
#ifndef __KLIBC_H #define __KLIBC_H /* 在屏幕上输出字符,字符串及整数 */ #include "global_type.h" //打印一个字符 void kputchar( char ch ) ; //打印字符串,以'\0'为结尾字符 void kputstr( const char *str ) ; //以2进制打印一个uint32_t类型 void kput_uint32_bin( uint32_t num ) ; //以16进制形式打印一个uint32_t类型 void kput_uint32_hex( uint32_t num ) ; //以10进制打印一个uint32_t类型 voi...
C
#include <stdio.h> /*Esse programa calcula x^n*/ int main(void) { int n , x , resultado , contador ; printf("Entre com os valores de x e n: "); scanf("%d %d", &x , &n); resultado = 1; contador = 1; while(contador <=n) { resultado = resultado * x; contador = contador + 1; } printf("O result...
C
/** * @Author: Kyle Andrews * @Date: September 23, 2010 * @Description: Takes the factorial via while looping */ #include <stdio.h> main() { int start,stop=1,factorial=1; printf("Take the factorial of: "); scanf("%i",&start); if (start >25) { printf("Error. Answer too large!"); return; } while(stop<=start) { factorial...
C
int searchInsert(int* nums, int numsSize, int target) { int i; for(i = 0; i < numsSize; i++) if(nums[i] >= target) return i; return i; }
C
// #include<stdio.h> void Display(char *str) { int i=0,iCnt=0; if(str == NULL) { return; } while(*str!=0) { iCnt++; str++; } str--; while(iCnt>0) { printf("%c",*str); iCnt--; str--; } } int main() { char Arr[10]; int iRet=0; printf("Enter string:"); scanf("%[^...
C
#include "cub.h" int mapp(t_map *m, int fd) { char *line; int linelen = 0; int count = 0; while (get_next_line(fd, &line)) { int i = 0; while(line[i] == ' ' || line[i] == '\t') ++i; if(line[i] == 'R') { ++i; m->width = ft_atoi(line...
C
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* sort_algoritms.c :+: :+: :+: ...
C
/* CLIPS Version 4.30 4/25/89 */ /*******************************************************/ /* "C" Language Integrated Production System */ /* EVALUATION MODULE */ /*******************************************************/ #include <stdio.h> #include "clip...
C
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* draw.c :+: :+: :+: ...
C
/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file : main.c * @brief : Main program body ****************************************************************************** * @attention * * <h2><center>&copy; Copyright (c) ...
C
#include <stdio.h> #include <stdlib.h> #include "../../include/Queue.h" #include "mu_test.h" int CheckQueueContent(Queue* _queue, int* _arr, int _size) { size_t i; int num = 3,*val = &num; for (i = 0; i < _size; ++i) { ASSERT_THAT( Queue_Remove(_queue,(void**) &val) == QUEUE_SUCCESS); ASSERT_THAT( *val == _...
C
#include<stdio.h> #include<math.h> int main(void){ int length,width,height; scanf("%d %d %d",&length,&width,&height); int a,b,c; a=length*width; b=width*height; c=length*height; printf("the surface area is %d\n",2*(a+b+c)); printf("the volumn is %d\n",sqrt(a*b*c)); return 0; }
C
#include <stdio.h> #include <stdlib.h> typedef struct bovino { int* num_id; float* peso; } Bovino; int main () { int i, n, menor = 0, maior = 0; float menor_peso = 1000000, maior_peso = 0; Bovino boi; scanf("%d", &n); boi.num_id = (int*) malloc(sizeof(int)*n); boi.peso = (float*) malloc(sizeof(float)*n); for...
C
include<stdio.h> int main() { int n; printf("enter the year\n"); scanf("%d",&n); if(n%400==0) printf("leap year\n"); else if(n%4==0&&n%100!=0) printf("year is leap year\n"); else printf("not a leap year\n"); return 0; }
C
// // Created by HP on 2019/9/26. // #include <stdio.h> #include <stdlib.h> int main() { printf("How long the r\y\g lights cotinue?"); int red,green,yellow; scanf("%d %d %d",&red,&yellow,&green); if(red > 106 || green > 106 || yellow > 106) { printf("input again."); scanf("%d %d %d"...
C
/* * the possible way to implement strcpy() function. */ #include <stdio.h> #include <string.h> char *strcpy(char *strDest, const char *strSrc) { char *temp = strDest; while (*strDest++ = *strSrc++); return temp; } void* my_memcpy(void *dst, void *src, unsigned int count) { void *ret = dst; // If dst and...
C
#include <math.h> #include <stdio.h> #include <stdlib.h> #include "tools.h" #include "io.h" double f (int i,int j){ return fabs(i-j); //return (i>j)?i:j; } double identity (int i, int j){ if (i==j) return 1.; else return 0.; } void searchMainBlock(void *inv, void *inoutv, int *len, MPI_Datatype *MPI_mainBlock...
C
#include "holberton.h" int prime(int n, int x); /** * prime - Entry point * @n: d * @x: d * * Return: Always 0 (Success) */ int prime(int n, int x) { if (n % x == 0 && x < n) { return (0); } else if (n % x != 0 && x < n) { return (prime(n, x + 1)); } return (1); } /** * is_prime_number - Entry point * @n: d ...
C
#include<stdio.h> #include<stdlib.h> int main () { int num, cont, par=0, impar=0, positivo=0, negativo = 0; for (cont=0;cont<5;cont++){ printf("Digite um numero: "); scanf("%i", &num); if(num%2 == 0) { par++; } else { impar++; } ...
C
#pragma once #include "labels.h" struct label* make_label_variable(char* line, int* address) { char* context = NULL; struct label* label = NULL; int asterisk = 0; int count = 1; //Sprawdź czy w linii występuje znak '*' asterisk = (strchr(line, '*') != NULL); label = malloc(sizeof(struct label)...
C
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_lstmap.c :+: :+: :+: ...
C
/* recognizeExp.c, Gerard Renardel, 29 January 2014 * * In this file a recognizer acceptExpression is definined that can recognize * arithmetical expressions generated by the following BNF grammar: * * <expression> ::= <term> { '+' <term> | '-' <term> } * * <term> ::= <factor> { '*' <factor> | '/' <facto...
C
#include <stdio.h> int fib(int i){ if(i==1) { return 1; } else { if(i==2) { return 1; } else { return fib(i-1)+fib(i-2); } } } int main(void) { int i; scanf("%d",&i); printf("Resultado = %d\n",fib(i)); return 0; }
C
/* * Copyright (c) 2007 - 2014 Joseph Gaeddert * * This file is part of liquid. * * liquid is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any lat...
C
#include <stdio.h> unsigned mulinv_euclid(d){ // d must be odd. unsigned x1, v1, x2, v2, x3, v3, q; x1= 0xFFFFFFFF; v1 = -d; x2 = 1; v2 = d; while (v2 > 1){ q = v1/v2; x3 = x1 - q*x2; v3 = v1 - q*v2; x2 = x3; v2 = v3; } return x2; } unsigned mulinv_newton(unsigned d){ // d must be odd. un...
C
// // Exercise2-17 // // Created by Greg Tosato on 8/11/18. // Copyright © 2018 Dingo Byte Solutions. All rights reserved. // // This program prints the numbers 1-4 using various methods. #include <stdio.h> void exercise2_17(void) { int num1 = 1, num2 = 2, num3 = 3, num4 = 4; printf("The numbers...
C
#include <stdio.h> struct student { char name[10]; int roll; }; void display(struct student stu); // function prototype should be below to the structure declaration otherwise compiler shows error int main() { struct student stud; printf("Enter student's name: "); scanf ("%[^\n]%*c"...
C
#include "delay.h" void init__delay(void){ RCC_ClocksTypeDef RCC_clocks; RCC_GetClocksFreq(&RCC_clocks); SysTick_Config(RCC_clocks.HCLK_Frequency/100000); } void _delay_ms(int ms){ sysTickCounter = 100 * ms; while (sysTickCounter != 0); } void SysTick_Handler(void) { if(sysTickCounter != 0) sysTickCount...
C
#include <stdio.h> int global = 2; int global_un; int main() { int i = 0, sum = 0, *p; char * string = "Nyat!"; char temp[1000]; FILE *fp = fopen("/proc/self/maps", "r"); printf("address of const string %p\n",string); printf("address of local variable %p\n",&i); printf("address of initialized global %p\n",&g...
C
#ifndef FINISHEDGAMEDATA_H #define FINISHEDGAMEDATA_H #include <QMetaType> #include <QTime> struct FinishedGameData { int nbStars; QTime bestTime; bool hasSomethingBetterThan(const FinishedGameData& other) const { return nbStars > other.nbStars || (bestTime.isValid() && !other.bestTime.isVali...
C
#include <stdio.h> #include <stdlib.h> /* <ul>Function returnPointerArray: <li>Arguments: [1] an array of ints and [2] an array length <li>Malloc’s an int* array of the same element length <li>Initializes each element of the newly-allocated array to point to the corresponding element of the pa...
C
#include <stdio.h> #include <stdlib.h> #include <time.h> #include "pca.h" #include <math.h> float norm2(float **a, int n, int m) { int i, j; float accum = 0.0; for(i=1; i<=n; i++) { for(j=1; j<=m; j++) { accum += a[i][j] * a[i][j]; } } return sqrt(accum); } float frand() { return ((float) rand()) /...
C
#include <fcntl.h> #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> #include <limits.h> #include <stdio.h> #include <string.h> #define MAX_BUF 1024 int main() { int fd, ret; char buf[MAX_BUF]; char * myfifo = "/tmp/myserverfifo"; /* write PID to the FIFO */ fd = open(myfifo, O_WRO...
C
/* mosiscrc -- calculate and print POSIX.2 checksums and sizes of text or binary files. This file is a modified version of the file "cksum.c" from GNU textutils version 1.22. The changes were made on October 27, 1999. It packages most of what that program did into a single file, for ease of ...
C
#include<stdio.h> #include<string.h> #include<conio.h> void main() { char str[90],i,l; scanf("%s ",&str); l=strlen(str); for(i=l-1;i>=0;i--) { printf("%c",str[i]); } }
C
#include "uls.h" static char *make_error_message(char *dirname) { char *error_message = mx_strnew( mx_strlen(dirname) + mx_strlen(strerror(errno)) + 8); mx_strcat(error_message, "uls: "); mx_strcat(error_message, dirname); mx_strcat(error_message, ": "); mx_strcat(error_message, strerror(e...
C
/* * Routines for dealing with processes. */ #include "cxtk.h" #include "kernel.h" #include "ksh.h" #include "slab.h" #include "socket.h" #include "string.h" #include "wait.h" #include "mm.h" #include "config.h" struct list_head process_list; struct process *current = NULL; struct slab *proc_slab; static uint32_t pi...
C
#include<stdio.h> int main() { int a,b,c; printf("enter the number of rows:"); scanf("%d",&c); for(a=0;a<c;a++) { for(b=0;b<c;b++) { if(a==b||a+b==(c-1)) { printf("*"); } else { printf(" "); } } printf("\n"); } }
C
/** * * Return an array of size *returnSize. * * Note: The returned array must be malloced, assume caller calls free(). * */ int* singleNumber(int* nums, int numsSize, int* returnSize) { int n = nums[0]; for(int i = 1; i < numsSize; i ++){ n = n^nums[i]; } int d[32]; int j = 0; ...
C
//#include <stdio.h> //#include <stdlib.h> // //#include <fcntl.h> //#include <unistd.h> // //#include <string.h> //#include <stdbool.h> // //#include <time.h> // // ////set //#define bufferSize 256 //#define blockSize 256 // // ////make sth //// //int createLinuxFile(char *fileName); //int openLinuxFile(char* fileName...
C
#include <math.h> #define LAG_COMPARISON_ENABLED extern double * baseline; double max_xcorr(double *signal, double *template, int bins); double normalized_xcorr(double *signal, double *template, int bins, int lag); double avg(double *data, int length); double std_dev(double *data, int length, double avg); int match(...