Question

My code is giving me errors output enter numbers ending with 0: 1 2 4 3...

My code is giving me errors

output

enter numbers ending with 0: 1 2 4 3 0
numbers entered by user are: 1 2 4 3
the max(largest) number is: 4

Use pointers. Arrays cannot be used except on the main function.

#include
#define N 10
void main()
{
int max,a[N]={0};
int getseries(*&a[N]);
findmax(&a,N);
}
void getseries(int *p,int P)
{
int *q;
printf("enter numbers ending with 0: ");
for(q=p;q<=p+P;q++)
{
scanf("%d",q);
if (*q=0)
break;
}
}
printf("numbers entered by user are: ");
for(q=p+N+1;q<=a;q++)
printf(" %d", *q);
printf("\n");
printf("the max number is: ",max);
{
int findmax()
{
int q, max;
max=*q
for(q=p;q<=p+P;q++)
if(*q>max);
max=*q
return max;
}




0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>
#define N 10
void getseries(int *p,int P)
{
int q, count = 0;
printf("enter numbers ending with 0: ");
for(q=0;q<P;q++)
{
scanf("%d",&p[q]);
++count;
if(p[q]==0){
--count;
break;
}
}
printf("numbers entered by user are: ");
for(q=0;q<count;q++)
{
printf("%d ", p[q]);
}

printf("\n");
}

void findmax(int *p,int P)
{
int max = -1 , q;
for(q=0;q<P;q++)
{
if(p[q] > max)
max = p[q];
}
printf("Max is: %d", max);

}
int main()
{
int max,a[10]={0};
getseries(a, N);
findmax(a,N);
}

===
SEE OUTPUT

New Project-20170331 +Compile I Execute Share Code main.cx E- root 21 22 printfC\n; 23 24 25 void findmax(int *p,int P) 26

Thanks, let me know if there is any concern.

Add a comment
Know the answer?
Add Answer to:
My code is giving me errors output enter numbers ending with 0: 1 2 4 3...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • **how can I make my program break if 0 is entered by user as last number...

    **how can I make my program break if 0 is entered by user as last number not always 10 numbers output should be enter 10 numbers:1 2 0 numbers entered by user are: 1 2 Largest number: 2 **arrays can ONLY be used in the main function, other than the main function pointers should be used #include #define N 10 void max(int a[], int n, int *max); int main (void) { int a [N], i , big; printf("enter %d numbers:",N);...

  • C program help: Write a C program that uses three functions to perform the following tasks:...

    C program help: Write a C program that uses three functions to perform the following tasks: – The first function should read the price of an item sold at a grocery store together with the quantity from the user and return all the values to main(). example: #include void getInput(int *pNum1, int *pNum2); // note: *pNum1 & *pNum2 are pointers to ints int main () {    int numDucks,numCats;    getInput(&numDucks, &numCats); // passing addresses of num1 & num2 to...

  • /* •   The following code consists of 5 parts. •   Find the errors for each part...

    /* •   The following code consists of 5 parts. •   Find the errors for each part and fix them. •   Explain the errors using comments on top of each part. */ #include <stdio.h> #include <string.h> int main( ) { ////////////////////////////////////////////////////////////////////////// //////////////        Part A. (5 points)                ////////////////// int g(void) { printf("%s", Inside function g\ n " ); int h(void) {       printf(" % s ", Inside function h\ n "); } } printf("Part A: \n "); g(); printf(" \n"); ////////////////////////////////////////////////////////////////////////// //////////////       ...

  • Fix the errors in C code #include <stdio.h> #include <stdlib.h> void insertAt(int *, int); void Delete(int...

    Fix the errors in C code #include <stdio.h> #include <stdlib.h> void insertAt(int *, int); void Delete(int *); void replaceAt(int *, int, int); int isEmpty(int *, int); int isFull(int *, int); void removeAt(int *, int); void printList(int *, int); int main() { int *a; int arraySize=0,l=0,loc=0; int choice; while(1) { printf("\n Main Menu"); printf("\n 1.Create list\n 2.Insert element at particular position\n 3.Delete list.\n4. Remove an element at given position \n 5.Replace an element at given position\n 6. Check the size of...

  • The following program sorts the array of numbers entered by the user and prints out the...

    The following program sorts the array of numbers entered by the user and prints out the elements in descending order. It has many errors. Debug the code and show the output. #include <stdio.h> #define N 4 void desc(float *a, float *b) float tp; tp=a; a=b; b=tp; int main() int i, j, ii, mark[N] ; for (ii==0;ii<N;ii++) printf("Enter the %d th element of your array: \n",ii); scanf("%d", mark[ii]); printf("You have entered the following array: \n"); for (ii=0,ii<N,ii++) printf("%d ", mark[ii]); printf("\n...

  • answer two question,each question has 3syntax errors,find it. 1(a) The following segment of code contains at...

    answer two question,each question has 3syntax errors,find it. 1(a) The following segment of code contains at least three (3) syntax errors that will compilation to fail with errors. Identify each of these errors and specify the solution. [2 marks each, 6 marks in total] cause #include <stdio.h> void main (void) float height; float area; printf "input height of the rectangle: ") scanf( "%f", &height) printf"input length of the rectangle: scanf"", &length); height length; area printf( area of rectangle %f high...

  • Trace the following code and enter correct information into the working memory box. Code Memory Working...

    Trace the following code and enter correct information into the working memory box. Code Memory Working Memory #include <stdio.h> // Prototypes double factorial(int); void main() 1 int num; // Number from user double fact; // Get value from user do { printf ("Give an integer greater or equal to zero : "); scanf("%d", &num); if (num < 0) printf ("Value must be larger or equal to zero.\n"); } while (num < 0); fact = factorial (num); printf ("The factorial of...

  • Solve using C programming 3. lf you are given this code. #include <stdio.h> int main() int...

    Solve using C programming 3. lf you are given this code. #include <stdio.h> int main() int var1, var2; int sum; printf("Enter number 1:\n "); scanf("%d",&var1); printf("Enter number 2:In ); scanf("%d",&var2); sum-var1+var2; printf ("Vnsum of two entered numbers : %d", //printf ("Output: %d", res); sum); return e; Modify this code by creating a function called "addition". Make the arguments of the functions numberl and number 2. Add the two values in the function. Return a value called "result". Print "result" in...

  • i'm having trouble making an else statement that will allow the program to add and output...

    i'm having trouble making an else statement that will allow the program to add and output the average the valid numbers inputed into the program. Here's my output: Enter Score 1:36 Enter Score 2:-1 Invalid Input Enter Score 2:89.5 Enter Score 3:42 Enter Score 4:66.3 Enter Score 5:93 You entered: 36.000000, 89.500000, 42.000000, 66.300000, 93.000000 Total Score: 362.800000 Average Score: 72.560000 Max Score: 93.000000 Min Score: 36.000000 Here's my code: #include <stdio.h> int main(void) { double score[5]; double min; double...

  • Hi there! I need to fix the errors that this code is giving me and also...

    Hi there! I need to fix the errors that this code is giving me and also I neet to make it look better. thank you! #include <iostream> #include <windows.h> #include <ctime> #include <cstdio> #include <fstream> // file stream #include <string> #include <cstring> using namespace std; const int N=10000; int *freq =new int [N]; int *duration=new int [N]; char const*filename="filename.txt"; int songLength(140); char MENU(); // SHOWS USER CHOICE void execute(const char command); void About(); void Save( int freq[],int duration[],int songLength); void...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT