Skip to content
Snippets Groups Projects
Commit d94348b7 authored by antux18's avatar antux18
Browse files

Initial exercise 1 files.

parent cf52face
Branches
No related merge requests found
L1:
gcc -c l1.c -o libmylib1.a
gcc T3.c -o t3_case1.o -L. -lmylib1
L2:
gcc -c l2.c -o libmylib2.a
gcc T3.c -o t3_case2.o -L. -lmylib2
L3:
gcc -o t3_case3.o T3.c l1.c
clean:
rm *.o
\ No newline at end of file
ex1/T1.c 0 → 100644
#include<stdlib.h>
#include<stdio.h>
int get_frequency(int *, int, int);
void display_results(int param1);
int main(int argc, char *argv[]){
int total_size=1000;
int search_size=1000;
int target=5;
// allocation
int * input_data = (int *) malloc(total_size * sizeof(int));
// initialization
for(int i=0;i<total_size;i++)
input_data[i]=1;
// usage 1
printf("Search for target %d\n",5);
int res=get_frequency(input_data, 10, 5);
display_results(res); // could not find target
// usage 2
printf("Search for target %d\n",1);
res=get_frequency(input_data, 1000, 1);
display_results(res); // target has been found 1000
free(input_data);
return 0;
}
int get_frequency(int * in, int size, int target){
// TODO implement get_get_frequency here
}
void display_results(int param1){
switch(param1){
case -1:
printf("could not find target\n");
break;
default:
printf("target has been found %d\n", param1);
}
}
ex1/T2.c 0 → 100644
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
int main(int argc, char * argv[]){
if(argc<3){
printf("Usage ./T2.o folder_path link_name\n");
}
//TODO -- implement your code here;
return 0;
}
#!/bin/bash/
#the following command returns the number of arguments
#hint $? will be 0 if there are no errors after any bash command
args=$#
if [ $args -lt 2 ]
then
echo Usage sh T2.sh folder_path link.
exit
fi
folder_path=$1
link=$2
#your implementation goes here
ex1/T3.c 0 → 100644
#include "sort.h"
#include <stdio.h>
int main ()
{
int size=5;
int input [] ={5, 9, 1, 2, 3};
printf("input array:");
for(int i=0;i<size;i++){
printf(" %d",input[i]);
}
printf("\nafter sort");
sort(input, size);
printf("\ninput array after sort:");
for(int i=0;i<size;i++){
printf(" %d",input[i]);
}
printf("\n");
}
ex1/l1.c 0 → 100644
void swap(int *xp, int *yp)
{
int temp = *xp;
*xp = *yp;
*yp = temp;
}
void sort(int arr[], int size)
{
int i, j;
for (i = 0; i < size-1; i++)
// Last i elements are already in place
for (j = 0; j < size-i-1; j++)
if (arr[j] > arr[j+1])
swap(&arr[j], &arr[j+1]);
}
ex1/l2.c 0 → 100644
void swap(int *xp, int *yp)
{
int temp = *xp;
*xp = *yp;
*yp = temp;
}
void sort(int arr[], int size)
{
int i, j;
for (i = 0; i < size-1; i++)
// Last i elements are already in place
for (j = 0; j < size-i-1; j++)
if (arr[j] < arr[j+1])
swap(&arr[j], &arr[j+1]);
}
File added
File added
#ifndef SORT
#define SORT
void sort(int input[], int size);
#endif
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment