Tuesday, July 14, 2009

What is the dev c++ solution, that has an array max of 40 elements......?

what is the dev c++ solution, that has an array max of 40 elements..the input should be from 0 to 9 only....and output the number according to its place value,, it shoud have a comma for each of the proper place value, the input should be outputed from up to down,,,,





here is the output:





Enter size: 4


4


0


9


6


Result: 4,096 (it should contain the comma (","),if it is greater than hundreds that pertains to its proper place value)





another example:


Enter size: 3


1


2


3


result: 123





another ex. hehehe:


Enter size:7


1


2


3


4


5


6


7


result: 1,234,567

What is the dev c++ solution, that has an array max of 40 elements......?
Hi Edrew,


Here is the MORE ACCURATE SOLUTION to your problem.


It will remove the shortcomings of the solution given by dear "iyiogrenci" just above my answer..








main()


{


int a[40];


int i,r,c,n;





printf("Enter total elements to be entered (1-40) : ");


scanf("%d",%26amp;n);





for(i=1;i%26lt;=n;i++)


{


printf("Enter element a[ %d ]=",i);


scanf("%d",%26amp;a[i]);


}





printf("\n\n");





if(n%26lt;=3)


for(i=1;i%26lt;=n;i++)


printf("%d",a[i]);


else


{


r=n % 3;


if (r != 0)


{


for (i=1;i%26lt;=r;i++)


{


printf("%d",a[i]);


}


printf(",");


}





c=n/3;





for(i=1;i%26lt;=c;i++)


{printf("%d%d%d",a[r+1],a[r+2],a[r+3])...


r=r+3;


if(i!=c)


printf(",");


}


}


}





.


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


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





main() {


int a[40];


int x,k,i,r,c,n;





printf("n=%",n);


scanf("%d",%26amp;n);





for(x=1;x%26lt;=n;x++) {


printf("a[ %d ]=",x);


scanf("%d",%26amp;a[x]);





}





printf("\n\n");


r=n % 3;


if (r != 0) {





for (i=1;i%26lt;=r;i++)


{printf("%d",a[i]);


}


printf(",");


}





c=n/3;





for(k=1;k%26lt;=c;k++)


{printf("%d%d%d",a[r+1],a[r+2],a[r+3]);


r=r+3;


printf(",");


}





printf("\n\n");


system("pause");





}








The output is in the form for n=5


12,345,





how can we delete the last character in the output


using backspace character?
Reply:How many times.... DEV C++ IS NOT A LANGUAGE!!!


C++ is the language you are coding in. Dev C++ is just an editor - you might as well ask "what is the Notepad C++ program for...". To my knowledge this will be the third time I have informed you of this fundamental fact.


No comments:

Post a Comment