ahmed0saber

Factorial of the smallest of first and last digits of a number in C++

Nov 8th, 2020
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. using namespace std;
  4. int main()
  5. {
  6.     string x , m;
  7.     int s , result=1 , n;
  8.     cout<<"Enter the number : ";
  9.     cin>>x;
  10.     s=x.size();
  11.     if(x[0]>x[s-1])
  12.     {
  13.         m=x[s-1];
  14.         stringstream a(m);
  15.         a>>n;
  16.     }
  17.     else if(x[0]<x[s-1])
  18.     {
  19.         m=x[0];
  20.         stringstream a(m);
  21.         a>>n;
  22.     }
  23.     while(n>0)
  24.     {
  25.         result=result*n;
  26.         n=n-1;
  27.     }
  28.     cout<<result;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment