language
large_stringclasses
1 value
text
stringlengths
9
2.95M
C
/* c---------------------------------------------------------------------c c c c COMPUTER PROGRAMS IN SEISMOLOGY c c VOLUME I c c ...
C
#include <stdio.h> double HelloWorld_dobro (int x) { printf("Metodo dobro!\n"); return x * 2; } int somar(int n, int m) { return n + m; }
C
#include "ush.h" static bool iisdigit(int c) { int n = 0; if (c >=48 && c <=57) { n++; return n; } else { return n; } } static bool iisalpha(int c) { int n = 0; if ((c >=65 && c <=90) || (c >=97 && c <=122)) { n++; return n; } else { ...
C
#include "../sign.h" #include "../dh.h" #include "print.h" #include <stdlib.h> #include <time.h> #define mes_len 1 #define loop_min 0 #define loop_len 10 int main(void) { unsigned long long i; /* Checking signatures */ int j; unsigned char sk[64]; unsigned long long mlen = mes_len; unsigne...
C
//Cory Bekker //Steve kyle #include <stdio.h> #include <stdlib.h> #include <pthread.h> #include <omp.h> int main(int argc, char* argv[]){ int num_threads; long long num_throws = 0; long long throw = 0; long long int numberInCircle = 0; if(argc != 3){ printf("Usage: [num threads] [num t...
C
/* * @lc app=leetcode id=2492 lang=c * * [2492] Minimum Score of a Path Between Two Cities */ // @lc code=start typedef struct { int count; int *parent; unsigned int *size; } UNION; UNION *union_find_init(int n) { UNION *u = malloc(sizeof(UNION)); u->count = n; u->parent = malloc(n * sizeo...
C
/********************************************************* * $Author: o-rooneo $ * $Date: 2015/02/10 07:36:49 $ * $Log: main.c,v $ * Revision 1.7 2015/02/10 07:36:49 o-rooneo * Finished project with bugs. View readme for full listing * * Revision 1.6 2015/02/09 21:53:05 o-rooneo * it compiles! Added queue f...
C
/* * cloudfs: memory source * By Benjamin Kittridge. Copyright (C) 2013, All rights reserved. * */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdint.h> #include <semaphore.h> #include "config.h" #include "log.h" #include "object.h" #include "misc.h" #include "cache/memory.h" //////////...
C
/* * Title: showargv.c (display argv-array) * Created: 04 Dec 2019 * Modified: * 05 Dec 2019, add show_argv2(), for cases where verb differs */ #define CUR_PTYPES #include "ptypes.h" MODULE_ID("$Id: showargv.c,v 12.2 2019/12/05 10:07:19 tom Exp $") /* * Function: Displays a command + argument-string, using ar...
C
#include <stdio.h> #include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> #include <time.h> #include <string.h> #define PORT 8080 int main(int argc, char* argv[]){ char sendBuff[1025]; char recvBuff[1025]; time_t ticks; int sockfd, connfd, len; struct sockaddr_in server_addr, client...
C
void arrcpy(char* dstarr,int *start,char* src) { while(*src) dstarr[(*start)++] = *(src++); }
C
/* ** parallel.c for bswireframe in /B1-MUL/bswireframe/projections ** ** Made by Quentin Laille ** Login <QuentinLaille@epitech.net> ** ** Started on Fri Nov 18 11:43:20 2016 Quentin Laille ** Last update Fri Dec 9 22:39:17 2016 Laille */ #include "my_wireframe.h" sfVector2i my_parallel_projection(sfVector3f inp...
C
#include <stdio.h> #include <stdlib.h> #include <GL/glut.h> int o; void initRendering(void); void drawScene(void); void keyboardToggler(unsigned char, int, int); int main(int argc, char* argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowPosition(300, 300); g...
C
#include<stdio.h> #include<conio.h> struct student{ int rollno; char name[10]; int regno; }s1[3]; void main() { int i; for(i=0;i<=1;i++) { printf("enter rollno of %d student",i+1); scanf("%d",&s1[i].rollno); printf("enter regno of %d student",i+1); scanf("%d",&s1[i].regno); printf("enter name of %d student",i+1); fflu...
C
#include "set.h" #include "memory.h" #include <stdint.h> #include <string.h> #define THRESHOLD (285) #define N_PROBES (3) s_cache_info cache; s_memory_info memory; s_set **potentially_conflict_sets = NULL; size_t n_potentially_conflict_sets = 0; // s_set **eviction_sets = NULL; // size_t n_eviction_s...
C
#include <stdio.h> #include <ctype.h> void First(char[],char ); void addToResult(char[],char ); int numofprod; char prodset[10][10]; int main(){ int i; char choice; char c; char result[20]; printf("How many productions: "); scanf(" %d",&numofprod); printf("Enter all the productions:\n"); for...
C
#include <stdio.h> #include <time.h> struct timespec diff(struct timespec start, struct timespec end) { struct timespec temp; if ((end.tv_nsec-start.tv_nsec)<0) { temp.tv_sec = end.tv_sec-start.tv_sec-1; temp.tv_nsec = 1000000000+end.tv_nsec-start.tv_nsec; } else { temp.tv_sec = end.tv_sec-start.tv_sec; tem...
C
#include "binary_trees.h" /** * binary_tree_leaves - function that counts the leaves in a binary tree * @tree: pointer to the root node of the tree * * Return: number of leaves or 0 */ size_t binary_tree_leaves(const binary_tree_t *tree) { size_t left_size, right_size; if (!tree) return (0); if (!tree->left ...
C
#include<stdio.h> #include<string.h> int max(int a, int b) { return (a > b)? a : b; } int lcs_length(char x[],char y[],int m,int n) { char c[m][n]; int i,j; for(i=0;i<=m;i++) c[i][0]=0; for(i=0;i<=m;i++) c[0][i]=0; for (i=0; i<=m; i++) { for (j=0; j<=n;...
C
#include<stdlib.h> #include<stdio.h> int main() { int i=1 , n , j=1 , k , p; scanf("%d",&n); if(n>2) { for(p=1;p<(n-1);p++) { k=i+j; i=j; j=k; } } else { k=1; } printf("%d!=%d",n,k); return 0; }
C
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* get_next_line.c :+: :+: :+: ...
C
#include <assert.h> #include <stdio.h> #include <string.h> char *mystrcat(char*, const char*); int main(void) { char s[1000]; assert( (strcpy(s, "pine"), !strcmp("pineapple", mystrcat(s, "apple"))) ); assert( (strcpy(s, ""), !strcmp("apple", mystrcat(s, "apple"))) ); assert( (strcpy(s, "pine"), !strcm...
C
#include <stdio.h> #include <stdlib.h> #include <sys/socket.h> #include <netinet/in.h> #include <sys/types.h> #include <string.h> #include <arpa/inet.h> #include <unistd.h> #include <fcntl.h> #include <sys/stat.h> #define PORT 8000 #define MAX_CONNECTIONS 3 #define BUFFER_SIZE 10 void sendfile(char filename[1024], in...
C
#include<stdio.h> #include<GL/gl.h> #include<GL/glut.h> #define sign(x) ((x>0)?1:((x<0)?-1:0)) //Returns 1 if x>0, -1 if x<0, 0 otherwise int x1,x2, y2,x3,x4,y3,y4,t1; int x11,y11,x21,y21,x31,x41,y31,y41; int xm1,ym1,xm2,ym2,xm3,ym3,xm4,ym4; void plotpt(int x, int y) { //Plot a single point/pixel on window glB...
C
#include "unit-test.h" #include <stdio.h> /** Module for unit test. Call UNIT_TEST(expr) to verify that expr * is true. */ static int num_tests = 0; static int num_failures = 0; /** Implementation function called by UNIT_TEST() macro; do not call * directly */ void unit_test(const char *fileName, int lineNu...
C
/* shadow_omni.h - shadow for omnidirectional dlights and PCF filtering Copyright (C) 2015 Uncle Mike This program 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 yo...
C
// Program to test arrays using matrix multiplication int main() { int a[100], b[100], res[100], r1, c1, r2, c2, i, j, k; prints("Enter rows and columns for first matrix (r1*c1 <= 100) :\n"); r1 = scani(); c1 = scani(); prints("Enter rows and columns for second matrix (r1*c1 <= 100) :\n"); r2 = s...
C
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <gsl/gsl_linalg.h> #include <gsl/gsl_fft_complex.h> #include <gsl/gsl_errno.h> #define T 1.0 const double sigma = T/20.; double function(double t) { double arg = 2 * M_PI / T * t; return ( sin(arg) + sin(2*arg) + sin(3*arg) ); } // losuje liczbe ...
C
/* * utilFunctions.c * * Created on: Aug 16, 2019 * Author: Lars */ /* Includes ------------------------------------------------------------------*/ #include "utilFunctions.h" extern RTC_HandleTypeDef hrtc; /* Public Function Implementation -----------------------------------------------*/ /** * @brie...
C
/* 134. Program to delete a node for a given element from linked list. */ #include <stdio.h> #include<stdlib.h> typedef struct node { int data; struct node *next; }Node; int main(void) { Node*temp; Node*start=NULL; Node* p=NULL; int n; scanf("%d",&n); while(n--) { temp=(Node *)malloc(sizeo...
C
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* conv_str.c :+: :+: :+: ...
C
// %%cpp macro_example_2.c // %run cat macro_example_2.c | grep -v "// %" > macro_example_2_filtered.c // %run gcc -std=c99 -ansi macro_example_2_filtered.c -o macro_example_2.exe // %run ./macro_example_2.exe // %run gcc -std=gnu99 macro_example_2.c -o macro_example_2.exe // %run ./macro_example_2.exe #include <stdio...
C
#include "Producers.h" #include <stdlib.h> #include <pthread.h> #include <semaphore.h> struct Producers { pthread_t* m_threadIDs; /* ID returned by pthread_create() */ size_t m_nTotalProducers; /* TODO decide if needed */ sem_t m_nCurrentProducers; }; Producers* ProducersCreate(size_t _numOfProducers, vo...
C
/********************************** * @author Jerry Chen * Date: 27 Jul 17 * Email: jerry153fish@gmail.com **********************************/ #include <stdio.h> #include <stdlib.h> #include <pthread.h> #include <unistd.h> #include <time.h> #include "j_threadpool.h" #include "j_queue.h" #include "job.h" //...
C
#include "Pause.h" #include "Stage_1.h" int Pause(SDL_Surface *ecran, SDL_Rect camera, SDL_Rect position_objet , int stage_dispo) { SDL_Rect camera_pause, position_objet_pause; SDL_Surface *pause=NULL; int quit =0,i=1 ; FILE *fichier =NULL ; SDL_Event event; do { switch(i) ...
C
#include <stdio.h> #include <stdbool.h> #include "../lib/prime.h" int main(int argc, char* argv[]) { int limit = 10000; sieve_t sieve = prime_sieve(limit); for(int c = 3; c < limit; c += 2) { // ignore all primes, only want odd composites if(is_prime(c)) continue; bool found = f...
C
#include <stdio.h> #include <string.h> #define MAXLINES 5000 /* 待排序的最大行数 */ char *lineptr[MAXLINES] /* 指向文本行的指针 */ int readlines(char *lineptr, int nlines); void writelines(char *lineptr[], int nlines); void qsort(void *lineptr[], int left, int right, int (*comp) (void *, void *)); int numcmp(char *, char*); ...
C
/*Hardware: see connect.txt */ #include <avr/io.h> #include "lcd.h" #include "KPDScan.h" void mydelay(unsigned char v) { unsigned char j; unsigned int i; for (j=0;j<v;j++) for (i=0;i<8000;i++) asm volatile ("nop"::); } #define demodelay 0xFF int main(void) { uint8_t key_val; /* initialize...
C
/* ** my_revstr.c for my_revstr in /home/clemsx/delivery/CPool_Day06 ** ** Made by clement xia ** Login <clemsx@epitech.net> ** ** Started on Mon Oct 10 10:46:34 2016 clement xia ** Last update Tue Oct 11 08:14:01 2016 clement xia */ int my_putstr(char *str) { int i; i = 0; while (str[i] != '\0') ...
C
#include "holberton.h" /** * _strspn - gets the length of a prefix substring. * * @s: the string to compare. * @accept: value accepted. * * Return: result. */ unsigned int _strspn(char *s, char *accept) { unsigned int result; unsigned int i; unsigned int j; result = 0; i = 0; while (s[i]) { j = 0; ...
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
#ifndef _VECTOR_H #define _VECTOR_H /*2D position struct*/ typedef struct { float x; float y; }Vector2f; Vector2f newVector2f(float x, float y); Vector2f add(Vector2f a, Vector2f b); #endif
C
#include<stdio.h> int main(void) { int num,max,min,i; printf("三つの整数を入力してください\n"); for(i=1;i<=3;i++){ printf("整数(No.%d):",i); scanf("%d",&num); if((i==1)||(num>max)){ max=num; } if((i==1)||(num<min)){ min=num; } } printf("最大値:%d\n",max); printf("最小値:%d\n",min); return 0;...
C
/** * Computaçao Embarcada * Mutirão C * Aula 1 * Rafael Corsi e Fábio Ayres * Entrega do Exercicio 4 do Aluno Felipe Frid Buniac */ #include <stdio.h> #include <math.h> void main(){ int numprodutos; char nome[100]; int preco; int quantidade; int precototal; char nomes[50][100]; int ...
C
#include<stdio.h> #include<string.h> #include<stdlib.h> int main(){ char *a = "hello"; char *b = malloc(100); printf("enter\n"); fgets(b,100,stdin); printf("Output: %s\n", b); return 0; }
C
#include <stdio.h> #include <stdint.h> #include <string.h> #include <time.h> #include "sha1.h" #include "otp.h" static uint8_t sanitize_base32_input(const char ch) { /* Google Authenticator checks for these values and corrects them, assuming this was a human error */ if (ch == '0') return (uint8_t) 'O';...
C
#include <cs50.h> #include <stdio.h> const int BLOCK = 512; int main(int argc, char *argv[]) { if(argc != 2) { fprintf(stderr, "Usage: ./recover card.raw\n"); return 1; } FILE *input = fopen(argv[1], "r"); if (input == NULL) { fprintf(stderr, "Could not open %s", a...
C
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include "quicksort.h" #include <stdbool.h> #include <math.h> #define RAM 4 #define NUM_NUMS 64 #define NUM_CAMINHOS 3 /* ---INTERCALACAO BALANCEADA MULTI-CAMINHOS--- DUPLA: CARLOS ALBERTO ROSA DOS SANTOS E GUILHERME GUIDOLIN */ //ar...
C
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* map.c :+: :+: :+: ...
C
#include <stdio.h> #include <stdlib.h> //һ֮⣬ֶ //ҳֻһε //{ 1, 3, 5, 7, 1, 3, 5, 9 }; //ҳ79 int main(){ int arr[] = { 1, 3, 5, 7, 1, 3, 5, 9 }; int n = sizeof(arr) / sizeof(arr[0]); int i; int tmp = 0; int pos; int a = 0; int b = 0; for (i = 0; i < n; ++i){ tmp ^= arr[i]; } for (i = 0; i < 32; ++i){ if (tmp...
C
// export PATH=$PATH:$(pwd) #include <signal.h> #include <stdio.h> #include <string.h> volatile sig_atomic_t flag = 0; void handler(int sig) { flag = 1; } int main(int argc, char *argv[]) { FILE *file[argc - 1]; char str[256], c; int line_number = 1; signal(SIGINT, handler); if (argc < 2 || ...
C
#include <stdio.h> int encontraSuperior(int funcionario, int matriz[][30], int tamanho){ int i; if (funcionario==0) /*ja e o presidente*/ printf ("0\n"); else{ /*escreve funcionario*/ printf ("%d ", funcionario); /*percorre coluna para achar superior*/ for (i=0; i<tamanho; ...
C
/** * \file * * \brief Empty user application template * */ /** * \mainpage User Application template doxygen documentation * * \par Empty user application template * * Bare minimum empty user application template * * \par Content * * -# Include the ASF header files (through asf.h) * -# "Insert system c...
C
#include "SeqQueue.h" typedef struct Person { char name[64]; int age; }Person; int main() { SeqQueue* seq = InIt_SeqQueue(); Person p1 = { "aaa",10 }; Person p2 = { "bbb",20 }; Person p3 = { "ccc",30 }; Person p4 = { "ddd",40 }; Person p5 = { "eee",50 }; // Push_SeqQueue(seq, &p1); Push_S...
C
#include <string.h> #include "pilha.h" #include "operadores.h" void interfaceCalculadora(PILHA* p1, PILHA* p2, PILHA* po){ int i=0,num; int n1; int n2; char operador; printf("Número de operacoes: "); scanf("%d",&num); while(i<num){ scanf("%d %c %d",&n1,&operador,&n2); push(p1,n1); //free(buffer); //...
C
#ifndef __draughts_moves_h #define __draughts_moves_h #include "board.h" // Special type that describes the move that can be performed typedef struct moves_state { int * params; char * action; struct moves_state * next; int depth; } moves_state; /* Checks if the game is over, returns: -1: game is not over ...
C
#include "spinnaker.h" #define SOFT_RESET 0xf2000018 // CPU soft reset reg #define MISC_CTRL 0xf2000038 // Misc control reg // Write (poke) a single word to a neighbouring chip. Has a simple // timeout mechanism which returns 0 on failure. uint link_write_word (uint addr, uint link, const uint *buf) { volatile uin...
C
#include <stdlib.h> #include <stdio.h> #include <SDL/SDL_image.h> #include <SDL/SDL.h> #include <SDL/SDL_ttf.h> #include <SDL/SDL_mixer.h> #include <time.h> #include "scrolling.h" //initialiser l'image du background et sa position initial void SCROLL_Init(scrollImage *s /*variable de structure*/, char *path /*nom du i...
C
#include "clib.h" #include "yakk.h" #include "lab8defs.h" #include "simptris.h" #define ASTACKSIZE 256 /* Size of each stack in words */ #define BSTACKSIZE 256 #define CSTACKSIZE 256 #define MSGQSIZE 20 #define SEED 1251 np NPArray[NPARRAYSIZE]; /* buffers for new piece content */ cmd CmdArray[CMDARRAYSIZ...
C
# include "stdio.h" # include "stdlib.h" /* 文件位置标志 系统为了对读写进行控制, 为每个文件设置了一个文件位置读写标记, 用来指示 接下来要读写的下一个字符的位置. 每一次读写, 文件读写标志都会向前进位. 在FILE结构体的定义中, 可以发现有一个 unsigned char * curp; 这就使文件位置标记(编译器的不同定义也不同) void rewind(FILE * stream) 使文件位置标志重新回到文件头 int fseek(FILE * stream, long off, int whence) stream 文件类型指针 off 位移量, 其是指以起始点为...
C
#include "holberton.h" /** * print_p - prints a percent sign * * Return: the percent sign */ int print_p(void) { print_c('%'); return (1); }
C
#include "ruzalo.h" #include <stdlib.h> #include <stdio.h> #include <stdbool.h> #include "../structs_shared/jugador.h" Ruzalo *ruzalo_init() { Ruzalo *ruzalo = malloc(sizeof(Ruzalo)); ruzalo->initial_life = 20000; ruzalo->salto_active = false; return ruzalo; } int choose_hability_ruzalo() { // 1: ...
C
#include <stdio.h> #include <stdlib.h> #include <locale.h> #include <ctype.h> #include <stdbool.h> #include <ctype.h> #include <time.h> #include "dados.h" //Biblioteca que implementa a estrutura de dados lista ligada dinâmica #define NUM_TENTATITVAS_LOGIN 3 REGISTRO cadastro() /// Esta funcao recebe os dados do paci...
C
#include <stdio.h> #include <stdlib.h> int ft_atoi(char *str); int main() { char *a; a = " ------+++--+-2147483648fdgs363"; printf("%d", ft_atoi(a)); }
C
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* finish.c :+: :+: :+: ...
C
// // Created by djvas on 28/09/2017. // #include "pr01_ex2017.h" int main_pr01_ex2017(int argc, const char *argv[]) { //readCharPrintAscii(); //readIntsPrintDiv(); //readDateGender(); //printAsciiTableLetters(); //printDigitOrNot(); //parseCountInStream(); //countInsertedChar(); retur...
C
#include <stdio.h> #include <stdlib.h> int *InsertionSort(int *arr,int n); void array_content(int *arr,int n); int main(){ int arr[] = {1,20,5,6,3,4}; int n = 6; int *sortedarr = InsertionSort(arr,n); array_content(sortedarr,n); } int *InsertionSort(int *arr,int n){ int i; for(...
C
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include "mapreduce.h" #include "word_freq.c" void map_worker(int outfd, int infd) { char filename[MAX_FILENAME]; FILE *file; char chunk[READSIZE]; while (read(infd, filename, MAX_FILENAME) > 0) { printf("Filename: %s from: %d\n"...
C
#include "Riostream.h" #include "TFile.h" #include "TTree.h" using namespace std; void MakeTree(void) { // Example of a script which reads some data and fills a TTree // with a branch for each variable describing the data //declaration of a structure for the data struct data_t{ Int_t Eid; Double_t E;...
C
#include <stdio.h> int min(int a, int b); int main() { int read[100]; int read_from_prompt; int i; int ret; scanf("%d", &read_from_prompt); for(i=0; i<read_from_prompt;i++) { scanf("%d", &read[i]); } ret = read[0]; for(i=0; i<read_from_prompt; i++) { ret = min(ret, read[i]); } printf("%d\n", ret)...
C
#include "../inc/vptree.h" #include <stdio.h> #include <stdlib.h> #include <math.h> #include <sys/time.h> #include <omp.h> #define THRESHOLD 100000 #define SWAP(a,b) temp=(a);(a)=(b);(b)=temp; /* is a subtree. Features of this are coordinates, median distance, index of dataset, the left subtree-child and the righ...
C
#include <stdio.h> #include <stdlib.h> #include "queueADT.h" struct node { Item data; struct node *next; }; struct queue_type { struct node *first; struct node *last; }; static void terminate(const char *message) { printf("%s\n", message); exit(EXIT_FAILURE); } Queue create(void) { Queue...
C
#ifndef __UQUEUE_H__ #define __UQUEUE_H__ typedef enum _uqueue_err { UQUEUE_ERROR_SUCCESS = 0, UQUEUE_ERROR_INVALID_ARGS = 0x01010001, UQUEUE_ERROR_NO_RESOURCE = 0x01010002, UQUEUE_ERROR_EMPTY = 0x01010002, }UQUEUE_ERROR_E; typedef struct _UQUEUE_NODE { void *obj; unsigned int len; struct ...
C
#include "gptimer.h" #define ADDR 0x80000600 typedef struct { volatile unsigned int counter; /* 0x0 */ volatile unsigned int reload; /* 0x4 */ volatile unsigned int control; /* 0x8 */ volatile unsigned int latch; /* 0xC */ } timerreg; typedef struct { volatile unsigned int scalercnt; /* 0x00...
C
#include <stdio.h> #include <stdlib.h> #include <string.h> void print_sum(char *CHARSET, int *count){ int len = strlen(CHARSET); int sum = 0; if(len == 0) printf("0\n"); else{ for(int i = 0; i < len; i++){ sum += count[CHARSET[i]]; } printf("%d\n", sum); } ...
C
#include <stdio.h> #include "mpi.h" #define N 1024*1024 int main (int argc, char *argv[]) { int rank, size, color, sum=0, localsum=0, i, chunk; int arr[N], recv_arr[N], partialsum[N]; MPI_Status status; int newrank, newsize; MPI_Comm newcomm; MPI_Init (&argc, &argv); MPI_Comm_rank (MPI_COMM_WORLD, &ran...
C
#include<stdio.h> void chk(char ar[30],char val) { int i=0; int cnt=0; while(ar[i] != val) { if(ar[i]==val) { break; } i++; } printf("found:%d ",i); } int main() { char a[30]; char ch; printf("enter any str...
C
// // Author: huanglijun // Date : 2019/6/6 // Desc : Solution35 // /* * 35. Search Insert Position Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You may assume no duplicates in the array. Example 1: Inp...
C
#include <stdio.h> int linearSearch(int arr[], int n, int x) { int i, z; for (i = 0; i < n; i++) { if (x == arr[i]) { z = i; break; } else { z = -1; } } return z; } int binarySearch(int arr[], int n, int x)...
C
#include <errno.h> #include "file.h" #include "strtype.h" /* * open a file (observing error handling) */ FILE* open_file(char* filename) { FILE *file = fopen(filename, FILE_PERMISSION); if(file == NULL) { fprintf(stderr, "Error during file open. FILE: %s\n", filename); exit(1); } ...
C
#include <stdlib.h> #include <stdio.h> #include <string.h> #include <arpa/inet.h> #include <netinet/in.h> #include "class_compiler.h" #include "method_pool.h" #define _XOPEN_SOURCE 600 #define _POSIX_C_SOURCE 1 #define POOL_SIZE 512 #define BYTECODE_LENGTH 2048 #define MAX_LOCALS 50 extern char *strtok_r(char *, con...
C
#include<stdio.h> #include<sys/socket.h> #include<unistd.h> #include<fcntl.h> #include<sys/stat.h> #include<netinet/in.h> #include<string.h> #include <arpa/inet.h> #include<signal.h> #define PORT 55769 struct communication{ char message[1024]; int flag; // 0 Read, 1 ReadWrite and 2 Close }; int main(int arg...
C
#include <stdio.h> #include <pthread.h> #include <string.h> #include <stdlib.h> #include <unistd.h> pthread_mutex_t mutex; char * buf[10]; int pos; void *thid(void*p) { pthread_mutex_lock(&mutex); buf[pos]=(char *)p; sleep(1); pos++; pthread_mutex_unlock(&mutex); } int main() { pthread_mutex_init(&mutex,NULL);...
C
#include <stdio.h> #include "misc.h" #define MAX_NUM 1001 int main() { int i, j, sum = 1, num; E_PRINTF("%d ", 1); for(i=3;i<=MAX_NUM;i+=2) { for(j=0;j<4;j++) { num = (i-2)*(i-1)+1+(i-1)*j; sum += num; E_PRINTF("%d ", num); } ...
C
#include <stdio.h> #include <stdlib.h> #include <pthread.h> #include <string.h> #include <strings.h> #include <sys/types.h> #include <sys/time.h> #include <unistd.h> #include <errno.h> #include <limits.h> /* * * The producer-consumer problem using pthreads. This one is NOT safe. * A context-switch within the crit...
C
/* * Scheduler.c * * Created: 2013-11-20 18:20:28 * Author: student */ #define F_CPU 16000000UL #define MAX_TASKS 10 #include <avr/io.h> #include <util/delay.h> #include <avr/interrupt.h> typedef void(*TASK_PTR) (void); struct tsk{ TASK_PTR t; uint16_t ToGo; uint16_t Interval; uint8_t...
C
/* Copyright (C) 2005-2005 Henry Cejtin, Matthew Fluet, Suresh * Jagannathan, and Stephen Weeks. * * MLton is released under a BSD-style license. * See the file MLton-LICENSE for details. */ void displayHeap (__attribute__ ((unused)) GC_state s, GC_heap heap, FILE *stream) {...
C
#include <assert.h> #include <errno.h> #include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #include <sys/wait.h> char *cmnd; void usage(void) { fprintf(stderr, "Usage: %s -p maxproc -w maxwork\n", cmnd); exit(1); } int main(int argc, char **argv) { int i; in...
C
#include <stdio.h> #include <string.h> #include "source.h" int main() { /* Count alpha */ char *str = "How many alpha in this string?"; printf("count_isalpha: %d\n", count_isalpha(str)); return 0; }
C
/* * This is newton2.pas, translated into SubsetC. * * It functions identically, except for the text printouts, * since we don't support string literals. */ float epsilon; int number; int foo; int abc; int test1(int j, int) // missing second identifier { return 1; } void test2() // cannot retu...
C
#ifndef TIMER_H_ #define TIMER_H_ #include <sys/time.h> #include "types.h" #define timestamp(tv) ((uint64_t) tv.tv_sec * 1000000ULL + (uint64_t) tv.tv_usec) #define TIMER_INIT (struct timer) { .start = timer_now() } struct timer { uint64_t start; }; static inline uint64_t timer_now() { struct timeval tv; getti...
C
/* ** aff_tree.c for aff_tree.c in /home/ozouf_h//42sh/src/parsing ** ** Made by harold ozouf ** Login <ozouf_h@epitech.net> ** ** Started on Thu Apr 19 13:14:24 2012 harold ozouf ** Last update Mon Apr 23 21:11:40 2012 harold ozouf */ #include <stdlib.h> #include <stdio.h> #include "token.h" #include "tree.h" s...
C
void main() { int a[5][5],i,y; void move(int a[5][5],int n,int m); int judge(int n,int m); for(i=0;i<5;i++) scanf("%d %d %d %d %d",&a[i][0],&a[i][1],&a[i][2],&a[i][3],&a[i][4]); int n,m; scanf("%d %d",&n,&m); y=judge(n,m); if(y==0) printf("error"); else if(y==1) { move(a,n,m); ...
C
#include<stdio.h> #include<string.h> int main(){ char s1[100],s2[100]; printf("Enter first String : "); scanf("%s",s1); printf("Enter second String : "); scanf("%s",s2); strcat(s1,s2); printf("New String is : %s",s1); return 0; }
C
/*main.c Khartikova*/ #include "shell.h" int main() { TMemory *mem = NULL; for (;;) { int t; /*save environment*/ t = open("dev/tty", O_RDWR, 0); dup2(t, 0); dup2(t, 1); /*greeting*/ printf("khash:%s[", getenv("USER")); if (strcmp(getenv("PWD"), getenv("HOME")) == 0) printf("~]"); else ...
C
#include <stdio.h> #include <math.h> int main() { float altura; float peso; float imc; printf("Informe os dados do paciente.\n"); printf("Peso em kg: "); scanf("%f", &peso); printf("Altura em metros: "); scanf("%f", &altura); imc = (peso / pow(altura, 2)); if (imc < 18.5) ...
C
// Distance Measure #ifndef Distance #define Distance ////////////// #include "Main.h" #include "LEDs.h" #define DISTANCE_CLOCK PC5 #define DISTANCE_DATA PC4 #define DISTANCE_PORT PINC #define ClockDistHigh bit_set(PORTC,PC5) #define ClockDistLow bit_clear(PORTC,PC5) //prototypes void InitializeDistance(void...
C
#include <stdio.h> int add(int x, int y) { return x + y; } int subtract(int x, int y) { return x - y; } int multiply(int x, int y) { return x * y; } int divide(int x, int y) { return x / y; } int domath(int (*mathop)(int, int), int x, int y) { int res = (*mathop)(x, y); return res; } int getinput...
C
/******************************************************************************* * This file is part of the "Data structures and algorithms" course. FMI 2018/19 *******************************************************************************/ /** * @file example.c * @author Ivan Filipov * @date 12.2019 * @br...
C
#include "loader.h" /************************************************************************* * loads the contents of a text file into an array and returns the * number of lines that were loaded. The assumption is that each line * of the file is at most LINE_LEN characters long *********************************...