#include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { if (argc != 3)…
- User
#include <stdio.h> #include <stdlib.h>
int main(int argc, char *argv[]) { if (argc != 3) { fprintf(stderr, "Usage: %s <N_OPS> <N_ENTRIES>\n", argv[0]); return 1; }
int n_ops = atoi(argv[1]); int n_entries = atoi(argv[2]); int i, j; int *vector1, *vector2, *sum; // Allocate memory for vectors vector1 = (int *)malloc(n_entries * sizeof(int)); vector2 = (int *)malloc(n_entries * sizeof(int)); sum = (int *)malloc(n_entries * sizeof(int)); if (!vector1 || !vector2 || !sum) { fprintf(stderr, "Memory allocation failed\n"); return 1; } for (i = 0; i < n_ops; i++) { // Read pairs of vectors for (j = 0; j < n_entries; j++) { scanf("%d", &vector1[j]); } for (j = 0; j < n_entries; j++) { scanf("%d", &vector2[j]); } // Add vectors and write output for (j = 0; j < n_entries; j++) { sum[j] = vector1[j] + vector2[j]; printf("%d ", sum[j]); } printf("\n\n"); } // Free allocated memory free(vector1); free(vector2); free(sum); return 0;} #!/bin/sh
Set the directory path
dir='prj2-sol/vector_addition.c $0'
Since there's no build process, we just echo a message
echo "No build done."
#!/bin/sh
Set the directory path
path=0") dir="prj2-sol"
Compile the C program
gcc "dir/vector_addition"
- Assistant
Certainly! Here's a sample README file template for your project. You should replace the placeholder text (like "Your Name" and "B-number") with your actual information.
# Vector Addition Project Readme ## Project Information - **Author's Name**: Your Name - **B-number**: BXXXXXXXX - **Email**: your.email@example.com ## Description This project consists of a C program designed to add two vectors of integers. The program reads pairs of vectors from the standard input, computes their sum, and prints the result to the standard output. The size of the vectors and the number of operations are taken as command-line arguments. ## Usage To run the vector addition program, compile the `vector_addition.c` file and execute it with two arguments: `<N_OPS>` and `<N_ENTRIES>` representing the number of operations and the size of the vectors, respectively. The following steps should be followed to compile and execute the program: 1. Compile the program: ```bash gcc path_to_vector_addition.c -o vector_addition ``` 2. Execute the program: ```bash ./vector_addition <N_OPS> <N_ENTRIES> ``` Replace `<N_OPS>` and `<N_ENTRIES>` with the desired number of operations and entry sizes. 3. The program expects input in the following format: ```bash vector1[0] vector1[1] ... vector1[N_ENTRIES-1] vector2[0] vector2[1] ... vector2[N_ENTRIES-1] ``` This input format repeats `<N_OPS>` times. ## Build Script The included build scripts automate the process of compiling and running the program. The `build script` is intended for easy compilation, and the `run script` is used to run the program with arguments taken from the command line. ## Additional Information Please feel free to contact me at the email address provided above if you have any questions regarding the project, encounter issues, or require further assistance. ## Acknowledgements I would like to thank everyone who provided feedback and support throughout the development of this project. ## License [INSERT LICENSE HERE IF APPLICABLE]
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.