Implement the function rotate. This function is to be passed two arrays, the number of elements in those arrays (assumed to be the same), and a number of elements to rotate. Here's an example:
Array A before function call: A[0] A[1] A[2] A[3] A[4] A[5] A[6]
+----------------------------------+
| 10 | 13 | 7 | 18 | 20 | 26 | 31 |
+----------------------------------+
Array B before function call: B[0] B[1] B[2] B[3] B[4] B[5] B[6]
+----------------------------------+
| ? | ? | ? | ? | ? | ? | ? |
+----------------------------------+
Array B after rotate(A, B, 7, 3): B[0] B[1] B[2] B[3] B[4] B[5] B[6]
+----------------------------------+
| 20 | 26 | 31 | 10 | 13 | 7 | 18 |
+----------------------------------+
What this call to rotate did is place A's first four values
3 elements later in B (that is, B[3] is A[0], B[4] is A[1], and so on),
and it placed A's last 3 values as the first 3 elements of B (that
is, B[0] is A[4], B[1] is A[5], and so on). This effectively
makes B the equivalent of rotating A 3 items to the right.
Your job is to fill in rotate's body below. HINT: The problem can be solved in 5 lines, which includes a variable declaration.
void rotate(int x[], int y[], int n, int k)
{
}
Unfortunately, you've written a program that doesn't work. Your program is supposed to read a single integer from the user and draw a triangle with that height. For example, if the user's input is 4, your program's output should be:
Below is the program you wrote. It uses a function writeN, which takes a character and a number and writes that character that number of times (you are sure this function works, as you have thoroughly tested it and used it on the last midterm).* *** ***** *******
#include <stdio.h>
main()
{
void writeN(char c, int n);
int i, height;
scanf("%i", &height);
for (i = 1; i < height; i++)
{
writeN(' ', height - 1);
writeN('*', i);
writeN('\n', 1);
}
What does this program produce as output if the user inputs a 4?
It's just not your day. You've written another program that doesn't seem to work. The program below is supposed to print the number of 0's, 1's, and other characters in a string.
main()
{
void countem(char *s, int *p0, int *p1, int *po);
int zeros = 0, ones = 0, others = 0;
countem("001x01", &zeros, &ones, &others);
printf("zeros=%i ones=%i others=%i\n", zeros, ones, others);
return 0;
}
void countem(char *s, int *p0, int *p1, int *po)
{
int i;
int cnt0 = 0, cnt1 = 0, cnto = 0;
for (i = 0; s[i] != '\0'; i++)
if (s[i] == 0)
cnt0++;
else if (s[i] == 1)
cnt1++;
else
cnt0++;
}
You expected this program to produce this output:
zeros=3 ones=2 others=1
Show us what this program actually produces as output.
Show us how to fix the program. Do this by marking up the program above (showing us where we delete, add, or change lines). HINT: There is more than one change that you need to make! After making any fix, trace through the program to make sure it produces the correct output.
This problem is to write a program (in stages) that uses two-dimensional arrays to read the input and print it so that the last line is printed first, the first line last, and each line is printed last character first, first character last. Here's an example. For the input:
the output should be:alex was here
Assume no more than 10 input lines and that each input line contains 20 characters or less.ereh saw xela
Draw a picture of the two-dimensional array after the sample input has been read in.
Fill in the body of the function fillTwoD, whose job it is to read the input into the two-dimensional array. It returns the number of lines read. Assume the input will fit in the array. HINT: Feel free to use getline or getchar to read the input.
int fillTwoD(char table[][21])
{
}
Write the function, printRevLine, whose job it is to output a single line stored in the two-dimensional array in reverse order.
void printRevLine(char table[][21], int lineno)
{
}
void printRevTwoD(char table [][21], int lines)
{
}
Write the main program that uses all the functions written in the previous parts to actually solve the problem.
This problem is to write a variety of functions that manipulate a table of structures. Assume you have the following structure type defined for you:
#define MAX_NAME 50
struct CD
{
char artist[MAX_NAME + 1];
char title[MAX_NAME + 1];
double price;
int quantityInStock;
};
The function is passed an empty table and returns the number of entries it successfully read. Assume there are no input errors. Hint: Free free to use getline.Gin Blossoms Congratulations, I'm Sorry 12.95 10 TLC CrazySexyCool 11.95 20 ...
int readTable(struct CD table[])
{
}
void printArtist(struct CD table[], int n, char artistName[])
{
}
int outOfStock(struct CD table[], int n, struct CD newtable[])
{
}
[Top Of Page | EE150 Exam Information Page | EE150 Home Page]