### number devision

Here m would be the first part of decimal point and n would be the second part of decimal point,how can i do that?

 ``12345678910111213`` ``````#include using namespace std; int main() { int a,b,m,n; double s; cin>>a; cin>>b; s=a/b; cout<<"you get " << m <<"500 dollars and"<

Last edited on

http://www.cplusplus.com/articles/jEywvCM9/

 ``12345678910111213141516171819202122232425262728`` ``````#include #include int main() { std::cout << "Enter a decimal number: " ; double num ; std::cin >> num ; std::cout << "Whole part: " << static_cast(num) << "\nDecimal part: " << num - static_cast(num) << '\n' ; std::string s ; std::cout << "Enter another decimal number: " ; std::cin >> s ; std::cout << "Whole part: " ; unsigned i=0; while ( i < s.length() && s[i] != '.' ) std::cout << s[i++] ; std::cout << "\nDecimal part: " ; while( ++i < s.length() ) std::cout << s[i] ; std::cout << '\n' ; }``````
you can take the input as a string and use the logic given by cire
#include<iostream.h>
int main()
{
char s[10];
cout<<"enter the decimal number";
cin>>s;
cout<<"whole part is:";
for(int i=0;s[i]!='.';i++)
cout<<s[i];
cout<<"decimal part is:";
while(s[i]!='\0')
{
cout<<s[i];
i++;
}
return 0;
}
Thanks both of You :)
Last edited on
Topic archived. No new replies allowed.