Question

Hello. for one of my assignment, I need to create any program using the C language...

Hello.

for one of my assignment, I need to create any program using the C language and that must contain the following:

- Error Checking

- Use of Functions

- Menu system

- Array Processing

It can be about anything, nothing specified but must contain the features mentioned above

Thank you

Homework Answers

Answer #1

//Required c code:

#include <stdio.h>
#include <errno.h>
#include <string.h>

int add(int a, int b){
    return a+b;
}

int main ()
{
    //error handling
    FILE *fp;

    // If a file is opened which does not exist,
    // then it will be an error and corresponding
    // errno value will be set
    fp = fopen(" abc.txt ", "r");

    // opening a file which does
    // not exist.
    printf("Value of errno: %d\n ", errno);
    printf("The error message is : %s\n",
                       strerror(errno));
    perror("Message from perror");
  
    //Use of function
    int d = add(1,2);
    printf("Sum of 1 & 2 is: %d",d);

  
    //menu system
    int x;
    printf("\nSelect an item: ");
    printf("\n1. Add");
    printf("\n2. Subtract");
    printf("\n3. Multiply\n");
    scanf("%d",&x);
    switch (x) {
        case 1:
            printf("Add selected\n");
            break;
        case 2:
            printf("Subtarct selected\n");
            break;
        case 3:
            printf("Multiply selected\n");
            break;
          
        default:
            break;
    }
  
    //array processing
    int arr[3] = {1,2,3};
    for(int i = 0;i<3;i++){
        printf("%d ",arr[i]*3);
    }
  
    return 0;
}

Please refer to the screenshot of the code to understand the indentation of the code


Output:

Hope this helped. Please do upvote and if there are any queries please ask in comments section.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
How could I create a very basic assembly program that is able to use string literals,...
How could I create a very basic assembly program that is able to use string literals, reserved words, and identifiers? I also need to process some directives, instructions, and labels as well. Could someone generate a simple assembly program to do these things? Thank you! My apologies, x86 processors. It's also a 32-bit program! We are using Visual Studio, and writing 32-bit programs. This program can literally do anything, as long as it meets the following requirements as described above.
Hello, My name is Cierra and I'm a bit nervous on where I need to start...
Hello, My name is Cierra and I'm a bit nervous on where I need to start to complete my assignment. I would appreciate some tips on what formula's to use and what direction I should take to answer a few questions. I want to have a better understanding of what questions I am getting myself into. Thank you. Cryptography: What does this coded message say?? Matrix inverses can provide a simple and effective procedure for encoding and decoding messages. 40  ...
I am trying to write a program in C language but keep running into errors. Any...
I am trying to write a program in C language but keep running into errors. Any help would be awesome. here is my code I have so far. #include <stdio.h> #include <conio.h> #include <string.h> int main(){    int lenght, i = 0, state = 0;    char line[100];    printf("enter the string for checking of comment line: \n");    gets(line);    while(i < strline(line)){        switch(state){            case 0: if (line[i] == '/'){               ...
Please answer in JAVA IDS 401 Assignment 4 Deadline In order to receive full credit, this...
Please answer in JAVA IDS 401 Assignment 4 Deadline In order to receive full credit, this assignment must be submitted by the deadline on Blackboard. Submitting your assignment early is recommended, in case problems arise with the submission process. Late submissions will be accepted (but penalized 10pts for each day late) up to one week after the submission deadline. After that, assignments will not be accepted. Assignment The object of this assignment is to construct a mini-banking system that helps...
For this lab assignment you will need to write some code and create some graphs. You...
For this lab assignment you will need to write some code and create some graphs. You may use excel to create your graphs, or other language of your choice. Your data needs to demonstrate the experimental running time for Selection Sort (code in book), Merge Sort (code in book), and the Arrays.sort() method. Here is a basic outline of how you need to code this assignment. 1) Create several arrays of size 100, 1000, 10000, 100000, 1000000, … (you need...
My assignment is listed below. I already have the code complete, but I cannot figure out...
My assignment is listed below. I already have the code complete, but I cannot figure out how to complete this portion: You must create a makefile to compile and build your program. I can't figure out if I need to create a makefile, and if I do, what commands do I use for that? Create a  ContactInfo class that contains the following member variables: name age phoneNumber The ContactInfo class should have a default constructor that sets name = "", phoneNumber...
Please do it in Python Write the simplest program that will demonstrate iteration vs recursion using...
Please do it in Python Write the simplest program that will demonstrate iteration vs recursion using the following guidelines - Write two primary helper functions - one iterative (IsArrayPrimeIter) and one recursive (IsArrayPrimeRecur) - each of which Take the array and its size as input params and return a bool. Print out a message "Entering <function_name>" as the first statement of each function. Perform the code to test whether every element of the array is a Prime number. Print out...
For this assignment you need to write a parallel program in C++ using OpenMP for vector...
For this assignment you need to write a parallel program in C++ using OpenMP for vector addition. Assume A, B, C are three vectors of equal length. The program will add the corresponding elements of vectors A and B and will store the sum in the corresponding elements in vector C (in other words C[i] = A[i] + B[i]). Every thread should execute approximately equal number of loop iterations. The only OpenMP directive you are allowed to use is: #pragma...
For this assignment, you need to write a parallel program in C++ using OpenMP for vector...
For this assignment, you need to write a parallel program in C++ using OpenMP for vector addition. Assume A, B, C are three vectors of equal length. The program will add the corresponding elements of vectors A and B and will store the sum in the corresponding elements in vector C (in other words C[i] = A[i] + B[i]). Every thread should execute an approximately equal number of loop iterations. The only OpenMP directive you are allowed to use is:...
For this assignment, you need to write a parallel program in C++ using OpenMP for vector...
For this assignment, you need to write a parallel program in C++ using OpenMP for vector addition. Assume A, B, C are three vectors of equal length. The program will add the corresponding elements of vectors A and B and will store the sum in the corresponding elements in vector C (in other words C[i] = A[i] + B[i]). Every thread should execute an approximately equal number of loop iterations. The only OpenMP directive you are allowed to use is:...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT