Quantcast

A community for students. Sign up today!

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

lgbasallote

  • 2 years ago

C array help

  • This Question is Closed
  1. lgbasallote
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    i have this code ``` #include <conio.h> #include <stdio.h> main() { int a[100]; int b, c, d; printf("How many numbers do you want? "); scanf("%d", &c); for (b=1; b<=c; b++) { printf("\nEnter number %d: ", b); scanf("%d", d); } getch(); } ``` how can i make the program print the inputted numbers in a form of a list?

  2. thangeram
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    #include <conio.h> #include <stdio.h> main() { int a[100]; int b, c, d[c]; printf("How many numbers do you want? "); scanf("%d", &c); for (b=1; b<=c; b++) { printf("\nEnter number %d: ", b); scanf("%d", d[b]); } getch(); } may be this can be helpful

  3. nidhie.raichura
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    #include <conio.h> #include <stdio.h> main() { int a[100]; int b, c; printf("How many numbers do you want? "); scanf("%d", &c); for (b=1; b<=c; b++) { printf("\nEnter number"); scanf("%d", &a[c]); } getch(); }

  4. nidhie.raichura
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    The &a[c] lets you give an input of c numbers If you want to display it again then you can add up the following code for (b=1; b<=c; b++) { printf("\nThe numbers are\n"); printf("%d", a[c]); }

  5. thangeram
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    it will give you array out of bound error ? dont you noticed?

  6. Vellas
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    In C an array always starts at index 0, not 1. You can ask the user for the first number but the first position in the array is zero. And the highest index is the size of the array minus 1. 99 in this case. So you should use < instead of <= and starting at 0. Otherwise you could get an index out of range error when accessing index 100. #include <conio.h> #include <stdio.h> main() { int a[100]; int b = 0; int c = 0; // c mustn't be higher than 100 // if c is greater 100, ask the user again do { printf("How many numbers do you want (max. 100)? "); scanf("%d", &c); } while(c > 100); // input for (b=0; b<c; b++) { printf("Enter number %d: ", b+1); scanf("%d", a[b]); } // output for (b=0; b<c; b++) { printf("Number %d: %d\n", b+1, a[b]); } getch(); }

  7. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Ask a Question
Find more explanations on OpenStudy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.