Struggling with Introductory C Programming Homework?

In summary, for an introductory computer science class, the homework includes a written section with short answer questions about the standard C libraries, big-O notation, and the * and & operators. The second part involves writing a program to count the number of bits set in an integer, and the third part requires writing a program to print the memory addresses of arrays and discussing how C stores arrays. The final part of the homework is to write a sorting function, with BubbleSort being the recommended algorithm for beginners. Additional resources such as programming books and websites are suggested for further understanding.
  • #1
wideris
1
0
This is my homework for an introductory computer science class, and I am really not very good at this.

If you can be of any help on ANY of these questions, I would greatly appreciate it. I don't even know where to start on almost any of them! Thank you!


HW:

1. Written Section (Short answers). Write these electronically in a text file
that you will include in the homework submission.
********************************************************************************

a) Describe in your own words why the standard C libraries help improve
portability of the C programming language.

b) In big-O notation, what is the running time of the arrayMax() function
from the homework 2 solutions?

c) Describe in your own words what the * and & operators in C are and how they
are different.

********************************************************************************
2. Bit counter. Submit your .c code file
********************************************************************************

(Exercise 11-4 from Practical C Programming, Steve Oualline)
"Write a program that counts the number of bits set in an integer. For example,
the number 5 (decimal), which is 0000000000000101 (binary), has two bits set."

More specifically, write a function, countBits() that takes an int as an
argument and returns an integer count of the number of set bits. Then write a
main function that reads an integer from the command line and outputs the
return value of countBits() to the screen.

********************************************************************************
3. Array addresses. Submit your .c code file
********************************************************************************

In this programming assignment we will do a small experiment to see how C
organizes arrays in memory.

Write a program that initializes three arrays:

- an array of 10 ints
- an array of 10 floats
- an array of 10 chars

Now, for each array, write a program that prints the memory addresses of all 10
entries of the array. It will be useful to use the printf conversion for
unsigned integer, "%u".

Finally, in your writeup, include some brief discussion about the numbers
that you printed out and what they tell you about how C stores the array.

********************************************************************************
4. Sorting. Submit your .c code file
********************************************************************************

Write a sorting function to complete the code below. The code below creates
a random array and passes it to the sort function you will write. Your code
should put the entries in order from least to greatest.

Feel free to use any sorting algorithm you like, as long as it works. Example
output is shown below the code:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

/********************Write your code here********************/


/*****************End of your code***************************/

int main()
{
float A[10], answer;
int i;

srand (time(NULL)); /* Seed the random number generator with the time */

printf("The input array is:\n");
for (i=0; i<10; i++) {
/* rand() returns a random int. We want a random float, so divide by
32767 */
A = (float)rand()/32767.0;
printf("%f ", A);
}
printf("\n"); /* finish the line */

mySort(A,10);

printf("After sorting, the array is:\n");

for (i=0; i<10; i++) {
printf("%d ", A);
}
printf("\n");

return 0;
}



/* End of code
Example output:
The input array is :
0.943724 0.928800 0.752251 0.662069 0.194739 0.544939 0.824610 0.118503 0.070070 0.335917
After sorting, the array is:
0.070070 0.118503 0.194739 0.335917 0.544939 0.662069 0.752251 0.824610 0.928800 0.943724
*/
 
Physics news on Phys.org
  • #2
Last edited by a moderator:
  • #3



my best advice for tackling programming homework is to break it down into smaller, manageable tasks. Start by carefully reading and understanding the instructions and then make a plan for how you will approach each question. If you are having trouble understanding a concept or completing a specific task, don't hesitate to reach out for help from your classmates, teacher, or online resources. It's also important to practice and review regularly to improve your programming skills. With determination and effort, you can overcome any challenges and successfully complete your homework. Good luck!
 

1. How do I start working on my programming homework?

To start working on your programming homework, make sure you have a clear understanding of the assignment instructions and the programming language you will be using. Familiarize yourself with the necessary tools and resources, such as a compiler or IDE, and create a plan or outline for completing the homework.

2. What should I do if I get stuck on a specific problem or concept?

If you get stuck on a problem or concept while working on your programming homework, try breaking it down into smaller, manageable parts. You can also consult your class notes, textbook, or online resources for additional explanations or examples. If you are still having trouble, consider reaching out to a classmate, teaching assistant, or instructor for help.

3. How can I avoid plagiarism when completing my programming homework?

To avoid plagiarism, make sure to properly cite any sources you use in your programming homework. This includes code snippets, algorithms, or ideas from textbooks, online resources, or other classmates. It is also important to write your code in your own words and avoid copying and pasting code directly from other sources.

4. Is it okay to ask for help with my programming homework?

Yes, it is okay to ask for help with your programming homework. However, it is important to make sure you understand the concepts and code you are using. Asking for help should not involve simply copying someone else's work without understanding it. It is also important to acknowledge any assistance you receive in completing your homework.

5. How can I check my programming homework for errors?

To check your programming homework for errors, you can use a compiler or IDE to test your code. This will help identify any syntax or logical errors. You can also manually review your code for any mistakes or ask a classmate or instructor to review it for you. It is important to thoroughly test and debug your code before submitting your homework.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
4
Views
929
  • Engineering and Comp Sci Homework Help
Replies
5
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
9
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
8K
  • Engineering and Comp Sci Homework Help
Replies
12
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
9
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
893
  • Engineering and Comp Sci Homework Help
Replies
17
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
21
Views
3K
Back
Top