Struggling with Introductory C Programming Homework?

Click For Summary
SUMMARY

This discussion focuses on an introductory C programming homework assignment that includes written questions and coding tasks. Key topics include the importance of standard C libraries for portability, the big-O notation for the arrayMax() function, and the usage of * and & operators in C. The coding tasks require writing functions to count bits in an integer, print memory addresses of arrays, and implement a sorting algorithm, with recommendations for resources like Practical C Programming by Steve Oualline and Wikipedia for sorting algorithms.

PREREQUISITES
  • Understanding of C programming syntax and structure
  • Familiarity with standard C libraries and their role in portability
  • Knowledge of big-O notation for analyzing algorithm efficiency
  • Basic concepts of memory management in C, including pointers and arrays
NEXT STEPS
  • Study the role of standard C libraries in enhancing portability
  • Learn about big-O notation and its application in algorithm analysis
  • Implement and experiment with the countBits() function in C
  • Research sorting algorithms, focusing on Bubble Sort and its implementation
USEFUL FOR

Students in introductory computer science courses, beginner C programmers, and anyone looking to strengthen their understanding of C programming concepts and coding practices.

wideris
Messages
1
Reaction score
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
Last edited by a moderator:

Similar threads

  • · Replies 3 ·
Replies
3
Views
1K
Replies
9
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 1 ·
Replies
1
Views
11K
  • · Replies 9 ·
Replies
9
Views
4K
Replies
7
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K