hi

first i am using tc3 compiler
which gives error for cstdlib

second

i want display a eng multiplication
method

i have done every thing but

how can i shift one left or right each line like


123
11
---------
123
123
--------
1353

thanx
but
i donot have info about its syntax(change)
isit same

cstdlib is the up to date version of stdlib. The older C header files like stdlib and stdio have been replace with versions prefixing the older version with a c, so stdlib became cstdlib and stdio became cstdio.

If the compiler you are using won't accept cstdlib then try stdlib. But, given the quality of the free DevC++ IDE (and bundled compiler) and the (for now) free version of VC++ both available on line for the taking, you should give serious thought to changing your compiler unless you are required (for example your instructor/school/employer require you to use your current compiler. After all three posters all recommending the same thing should carry some degree of reliability that you are getting good advice!

If you are trying to learn how to drive a car, would you start out by learning how to drive horse & buggy as people did 200 years ago? They why try to learn programming with a very very old and outdated compiler?

There are probably several ways to solve your problem. One way is to use printf() with the width specier. For example, printf("%5d", 12) will print the number 12 right-justified in a field of 5 characters -- it will be padded on the left with spaces. Replace the 5 with * and you can specify the with in the first paremter to printf. for example, printf("%*d", 5, 12);

You can use that little bit of information to format the lines like you want them. First determine the maximum width of the output -- say 123 * 11 == a 4 digit number.

printf("%*d\n",4,123);
printf("%*d\n",4,11);
printf("--------------\n");
printf('%*d\n",4,123);  // 123 * 1 = 123
printf('%*d\n",3,123);  // 123 * 1 = 123
printf("--------------\n");
printf("%d", 123 * 11);

Now, instead of hard-coding the numbers as I did above, you will want to replace the with program variables.

I know that can also be done with c++ cout, but I'm pretty lousy with that so I won't even try to show you. I prefer printf() for anything more than triviel output because to me printf() is easier to use.

i have to submite it after day tomarrow
so i cant change right now
and in c++

i already made the code:

char val2[256];
long int val1,i,k,ndiv1,x=20,y=53;
long int final,ln[16],j;
cleardevice();
setbkcolor(BLUE);
cout<<"**********************************************************************"<<endl<<endl<<endl;
cout<<"English Multiplication Method"<<endl<<endl;
cout<<"**********************************************************************"<<endl<<endl<<endl;
cout<<"enter 1st Value"<<endl;
cin>>val1;
cout<<"enter 2nd Value"<<endl;
cin>>val2;
ndiv1=strlen(val2);
clrscr();


for (i=0; i<ndiv1; ++i)
{
k=val2[i]-48;
ln[i]=k*val1;
}
j=atoi(val2);
final=j*val1;
cleardevice();
cout<<"*****************************************************************************"<<endl<<endl<<endl;
cout<<"                  "<<val1<<endl;
cout<<"                  "<<val2<<endl;
printf("              ------------n");
for (i=0; i<ndiv1; ++i) printf("                %dn",ln[i],"b");
printf("n            ------------n");
cout<<"    Result       "<<final<<endl;
cout<<"*****************************************************************************"<<endl<<endl<<endl;
getch();

but the problem is to disply
like in

               1234
               111
               --------
               1234
                 1234
                   1234
                ---------

each
time it shift the line one space

Edited 3 Years Ago by pritaeas: Fixed formatting

i now istalled borland c++ 5.02
is it
ok
but it gives graphic.h
library error

can i concate two integers
like
int a=12
int b=41
c=1241

int c = (a*100) + b;

as a general rule you would not want to do that because if a or b are large enough it will cause data overflow and provide the wrong answer. If you are certain the values are small enough then it would be ok.

This article has been dead for over six months. Start a new discussion instead.