Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

arrays and functions

Status
Not open for further replies.

anerchy

Programmer
Apr 19, 2008
1
0
0
TR
#include <stdio.h>




void fun1(void)
{
int a=0,b=5,c=0;
int d[5];
for(a=0;a<b;a++)

{


printf("%d\n",d[a]);
}






}
int main()

{
printf("enter 5 numbers");
int a,b=5,c=0;

int d[5];
for(a=0;a<b;a++)
{
scanf("%d",&d[a]);

}

fun1();
return 0;
}





i just wanted to make the program read 5 numbers then read them. help me please
 
1. You should work on your code indenting. Once you start writing larger programs, it will be very confusing if it isn't indented properly.

2. a, b, c, d don't really mean anything to anyone. Variables & functions should have useful names that tell the reader what it does. For example, I probably would have used maxNumbers instead of b, and you don't seem to be using c at all. A lot of people use i or n for loop counters, but count would be good too. As for fun1() I would have used printNums() instead.

3. Since this seems to be C code, there is a C forum here, otherwise if it's supposed to be C++ you should use <cstdio> instead of <stdio.h>

4. To print the numbers in another function, pass the array and the number of elements to the function:
Code:
void printNums( int* nums, int arraySize )
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top