Tuesday, July 14, 2009

What is the dev c++ formula that declares an array of 20 integers. Accept a number to determine the.........?

what is the dev c++ formula that declares an array of 20 integers. Accept a number to determine the number of 0 or 1 inputs(binary digits). Display decimal value using the output format:





Enter size: 4


1


0


1


1


Equivalent: 11


1x8=8


0x4=0


1x2=2


1x1=1

What is the dev c++ formula that declares an array of 20 integers. Accept a number to determine the.........?
Hello Edrew !!





Here is your solution:








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


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


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





void main()


{


int num[20]={0};


int total,i;


double sum=0;


clrscr();


cout%26lt;%26lt;"How many digits do you wish to Enter : ";


cin%26gt;%26gt;total;





if(total%26gt;0 %26amp;%26amp; total%26lt;=20)


{


cout%26lt;%26lt;endl%26lt;%26lt;"Please Enter "%26lt;%26lt;total%26lt;%26lt;" digits : "%26lt;%26lt;endl;


for(i=0;i%26lt;total;i++)


{


cin%26gt;%26gt;num[i];


}








for(i=0;i%26lt;total;i++)


{


sum=sum + num[i]*pow(2,total-i-1);


cout%26lt;%26lt;endl%26lt;%26lt;num[i] %26lt;%26lt;"*"%26lt;%26lt;pow(2,total-i-1)%26lt;%26lt;"="%26lt;%26lt;num[i]*pow...


}


cout%26lt;%26lt;endl%26lt;%26lt;endl%26lt;%26lt;"Equivalent is : "%26lt;%26lt;sum;


}


else


cout%26lt;%26lt;"Please Enter value between 0 and 20..";





getch();


}
Reply:Try searching the net for C++ tutorials and resources
Reply:Try searching the net for C++ tutorials and resources. It's worth bearing in mind that Dev C++ is an editor, not a language - the languages it edits are C or C++.

floral centerpieces

No comments:

Post a Comment