DIGIT-ARC read-only archive · snapshot: July 23, 2026

Help need for a C program! SOS

4 posts · originally from https://geek.digit.in/community/threads/help-need-for-a-c-program-sos.66289/

Gigacore
Gigacore Original post #1
Aug 22, 2007 at 10:30 PM
Hi guys i'm new to C programming. I've a small assignment program,

Write a Program to accept 10 numbers using one dimensional array and display them.

here how i tried, but haven't executed.

int a[10],i,n;
printf(Enter the number of elements");
scanf("%d", &n);
printf("Enter the elements");
for (i=0;i<n;i++)
scanf("%d", &a)

and the print statement
Garbage
Garbage #2
Aug 22, 2007 at 10:40 PM
Then what is the problem ???
All the statements can work.

Only problem can arise is that if I enter number of elements as >10, then it will overwrite to some other memory area.
Gigacore
Aug 22, 2007 at 10:47 PM
EXECUTED, its working.


+++ RESOLVED +++
arunks
arunks #4
Aug 22, 2007 at 10:54 PM
after ur last statement i.e.scanf statement there will be a ; semicolon


and ya when value is n is less than 10 then it will work surely but if input value of n greater than 10 then it will produce errors as that will be on garbage addresses