Thursday, October 15, 2009

digit vice addition

#include"stdio.h"
#include"conio.h"
//increment digit vice
int main()
{
int td,i;
printf("enter the total digit to be entered (1-9)\n");
scanf("%d",&td);
int ch[10];
printf("Enter the %d digit value :\n",td);
for(i=0;i<td;i++)
{
scanf("%d",&ch[i]);
}
printf("enter the value to be add with number\n");
int k;
scanf("%d",&k);
int j=ch[0]+k;
for(i=td-1;i>=0;i--)
{
ch[i]=ch[i]+k;
if(ch[i]>9)
{
ch[i]=ch[i]-10;
ch[i-1]=ch[i-1]+1;
}
}
//msb bit
if(j>9)
{
j=j-10;
printf("%d",j);
}
for(i=0;i<td;i++)
{
printf("%d",ch[i]);
}
getch();
return 0;

}

No comments:

Post a Comment