13-week machine operation--to find the factorial of odd numbers--using recursion

Source: Internet
Author: User
* * Copyright (c) 2011, Computer College of Yantai University
* All rights reserved.
* File name: Test.cpp
*:    Li Xinpeng
* Completion date: November 22, 2013
* Version number: v1.0
* Description of task and solution method:
* Input Description: input factorial
* problem Description: Factorial
* Program output: Numerical
* Problem analysis:
* Algorithm Design: Recursive */

#include <iostream>

using namespace std;
int f (int);
int main ()
{
   int n,m;
   cout << "Please input a few factorial" <<endl;
   cin>>n;
    M=f (n);
    cout<<m;
    return 0;
}
int f (int num)
{
  int y;
  if (num==1)
  {y=1;
  }
  else
  {
      y=num*f (num-1);
      }
  return y;
}

Run Result:

Experience: Recursive very magical, with it can solve a number of repetitive work, haha suitable for my lazy people ~~~~~~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.