Monday, May 24, 2010

If a string (say "1234") is entered thru the keyboard wap in c(NOT C++) to print the output 1234?

if this program is just to show the string as a number, then u can print it the way a string is printed...... there will be a different case if u need to perform mathematical operations on this string, then u need to typecast the string into int.


for simple way


#include%26lt;stdio.h%26gt;


void main()


{


char str[10];


printf("Enter any string\n"):


scanf("%s",%26amp;str);


printf("The string is %s",str);


}

If a string (say "1234") is entered thru the keyboard wap in c(NOT C++) to print the output 1234?
sum=0;


while((c=getch())!=EOF)


sum=sum*10+(c-'0');


printf(%d sum)


No comments:

Post a Comment