PromptBase
Close icon
General
Home
Marketplace
Hire
Create
Login
Sell
Explore
πŸ€– GPT

C Programmer

C Programmer gpt prompt mini thumbnail
2Heart icon
Favorites
113Eye icon
Views
TestedTick icon
TipsTick icon
πŸŽ‰ Attention all coders! πŸŽ‰ Tired of spending hours trying to write the perfect C code for your tasks? Say hello to our amazing prompt for GPT that creates flawless C code in no time! πŸ’»πŸš€ With our prompt, you'll save countless hours of trial and error, and have more time to focus on what really matters. Imagine having the perfect code for your project without the hassle and frustration. 😍
...more
$3.99
Get prompt
After purchasing, you will gain access to the prompt file which you can use with GPT or the app builder. You'll receive 20 free generation credits with this purchase. By purchasing this prompt, you agree to our terms of service.
Over 1 month ago

Prompt Details

Model
Chat - GPT-3.5 (gpt-3.5-turbo)
Token size
374 ($0.00070 / call)
Example input
Make a program that is a simple calculator that allows you to operate with two numbers using functions. The program will read two integers entered from the keyboard and display the result of adding, subtracting, multiplying, and dividing those values. The prototypes of the functions will be the following: void ReadNumber (int *num); void WriteResult(int num1, int num2, char operator, float result); int add(int num1, int num2); int Subtract(int num1, int num2); int multiply(int num1, int num2); float Divide(int num1, int num2);
Example output
Sure, here's the C code for the calculator program that meets the requirements specified in the task: #include <stdio.h> void ReadNumber(int *num); void WriteResult(int num1, int num2, char operator, float result); int add(int num1, int num2); int Subtract(int num1, int num2); int multiply(int num1, int num2); float Divide(int num1, int num2); int main() { int num1, num2; char operator; float result; ReadNumber(&num1); ReadNumber(&num2); operator = '+'; result = add(num1, num2); WriteResult(num1, num2, operator, result); operator = '-'; result = Subtract(num1, num2); WriteResult(num1, num2, operator, result); operator = '*'; result = multiply(num1, num2); WriteResult(num1, num2, operator, result); operator = '/'; result = Divide(num1, num2); WriteResult(num1, num2, operator, result); return 0; } void ReadNumber(int *num) { printf("Enter a number: "); scanf("%d", num); } void WriteResult(int num1, int num2, char operator, float result) { printf("%d %c %d = %.2f\n", num1, operator, num2, result); } int add(int num1, int num2) { return num1 + num2; } int Subtract(int num1, int num2) { return num1 - num2; } int multiply(int num1, int num2) { return num1 * num2; } float Divide(int num1, int num2) { return (float)num1 / (float)num2; } The program starts by declaring the necessary variables, including two integers for the input values, a character for the operator, and a float for the result. It then calls the ReadNumber function twice to get the input values from the user. Next, the program performs each of the four arithmetic operations by calling the appropriate function and storing the result in the result variable. The operator character is also set to the appropriate value for each operation. Finally, the program calls the WriteResult function to display the result of each operation on the screen. This function takes four arguments: the two input values, the operator, and the result of the operation. The function uses printf to display the values in the desired format. The ReadNumber function simply prompts the user to enter a number and reads the value into the specified integer variable using scanf. The WriteResult function formats and displays the input values, operator, and result in the specified format using printf. The add, Subtract, multiply, and Divide functions perform the corresponding arithmetic operation on the two input values and return the result. Overall, this program meets the requirements specified in the task and should work correctly for most input values. However, it does not handle division by zero or other potential edge cases.
Browse Marketplace