Simple coversion program hanging on input
Dear All,
I have written this programme that reads a set of n digits and converts them into a single decimal integer. For example if the input is an array of integers 2,3,4,12,4 then the output should be 234124. My program is hanging when I input a digit. Below is my code, please tell me the error:
Code:
#include<stdio.h>
int main()
{
int *a,sum=0,i,n;
printf("enter the number of digits");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
for(i=1;i<=n;i++)
{
printf("%d",a[i]);
}
system("pause");
return 0;
}
Thank you for your reply.
you can make it yourself ,here is my help for you
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
long int num[10],i,a,sum=0;
printf("enter the number of terms::");
scanf("%ld",&a);
for(i=0;i<a;i++)
{
printf("\nenter the %d element::",i+1);
scanf("%ld",&num[i]);
}
for(i=0;i<a;i++)
{
if(num[i]<10)
sum=sum*10+num[i];
else
sum=sum*100+num[i];
}
printf("\n the output is = %ld",sum);
getch();
}