Hello, good day. :)
I got a problem here in displaying the items of array. In "Display Items", it should display the numbers that I inputted in the "Input Items". Is there lacking in my code?
Menu:
[IMG]http://i168.photobucket.com/albums/u162/SHENGTON/menu.png[/IMG]
Input Items:
[IMG]http://i168.photobucket.com/albums/u162/SHENGTON/input.png[/IMG]
Display Items:
[IMG]http://i168.photobucket.com/albums/u162/SHENGTON/result.png[/IMG]
Here's the code:
#include<stdio.h>
#include<conio.h>
int input(void);
void display(int n);
int main()
{
int cho, i, n;
do{
printf("\n\n\n [1] Input Items\n");
printf(" [2] Display Items\n");
printf(" [3] Exit\n\n");
printf(" Enter your choice:");
scanf("%i",&cho);
i = getchar();
if(cho==1)
{
n = input();
}
if(cho==2)
{
display(n);
}
}while(cho != 3);
printf("\n\n\t\t\t press enter when ready");
i = getchar();
++i;
//clrscr();
return 0;
}
int input()
{
int a[100],i,n;
//clrscr();
printf("\n\n Enter integer for total numbers to be sorted: ");
scanf("%i",&n);
printf("\n\n");
for(i=0;i<n;i++)
{
printf(" Enter integer for no.%i : ",i+1);
scanf("%i",&a[i]);
}
return n;
}
void display(int n)
{
int a[100],i;
//clrscr();
printf("\n\n The elements are: ");
for(i=0;i<=n-1;i++)
{
printf("%i", a[i]);
}
}