Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

attached is the code that i have written. i need help printing the arrays using pointers 2. Write a C program, named last10.c, whose input

attached is the code that i have written. i need help printing the arrays using pointers image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
2. Write a C program, named last10.c, whose input is an unknown number of integers. The program stops reading when it encounters a zero. The program then prints the last ten numbers it read (not including the zero), in the order they were given. If less than 10 numbers were input, the program should print them all. For example: adminuseradminuser-VirtualBox -/Desktop/SP2020-HWS/HW2 5 last10 1 2 4 55 7 9 23 0 1 2 4 55 7 9 23 adminuser@adminuser-VirtualBox -/Desktop/SP2020. HUSA 1 2 3 4 5 6 7 8 9 10 11 12 0 astio 3 4 5 6 7 8 9 10 11 12 adminuser@adminuser-VirtualBox -/Desktop/SP2020-HWS/HW2 S Your program must not assume anything about the number of input values, which means that you can't declare an array to hold all of them. Instead, you should declare an array of 10 integers, and use it like a circular queue. (You do remember data structures, right?) In particular, keep a pointer to the next open slot of the array. Use scanf to read an integer. If it is not zero, write it to that slot and increment the pointer. If incrementing the pointer puts it! beyond the end of the array, set it back to the first slot. when you read a zero. print the contents of the array. Note that you need to begin with the number that was entered least recently, which is not necessarily the number at the beginning of the array. See the second example in the above screenshot. Some people will want to implement the queue like this: Once the array is full, you shift the values in the array one position to the left in order to make room the next input value, which you insert at the far right of the array. This is awkward and inefficient, and a bad idea. Please DON'T do it this way. 1 #include 3.//Main Function 4 int main() 5 { int number; int a[10]; int *ptr = a; int count = 0; scanf("%d", &number); //Initializing number //Initializing an array called a //Initializing a pointer //Initializing a count 12 //Determining the count of numbers while (number != 0) *ptr = number; if (count 0) me int *temp; if (count > 10 || count != 10) *temp = | else ptr++; printf("%d", *ptr); 47 49]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Programming Languages 12th International Symposium Dbpl 2009 Lyon France August 2009 Proceedings Lncs 5708

Authors: Philippa Gardner ,Floris Geerts

2009th Edition

3642037925, 978-3642037924

More Books

Students also viewed these Databases questions