Question
These three questions are C language questions and this code should be run in terminal 1. Three students are working on the same project, and
These three questions are C language questions and this code should be run in terminal
1. Three students are working on the same project, and each of them contributes a C file with the name foo*.c (foo1.c, foo2.c, foo3.c). The main function is included in the file prod.c, which uses functions defined in all the foo*.c files. The goal here is to build an object for each of the foo*.c files, with the name obtained by replacing the extension c by o, and to build the final executable called prod.out. Write a simple Makefile such that one just need to type make in the terminal to build the objects and the executable.
2. Implement a search(int X) function in an C program to search an element X in an array. The array contains integers 1, 2, 4, 6, 8, 9, 13, 19, 29. The return value of search(int X) should be the index of element X in the array if X is found. Otherwise, it returns -1. For instance search(4) returns 2, search(1) returns 0, and search(3) return -1.
#include
int search(int X){
//implement your code here
}
int main(){
printf(index of 10 is %d , search(4));
printf(index of 10 is %d , search(1));
printf(index of 10 is %d , search(3));
printf(index of 10 is %d , search(10));
printf(index of 10 is %d , search(19));
printf(index of 10 is %d , search(13));
printf(index of 10 is %d , search(29));
return 0;
}
3.
Write a C program to sort an array. For instance, the array is initially 6, 5, 3, 1, 8, 7, 2, 4. After calling your sort algorithm, the array will be 1, 2, 3, 4, 5, 6, 7, 8.
Hint: You can use one of the sorting algorithms, such as bubble sort [https://goo.gl/MXLPLP].
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started