Algorithmic Getting Started note------------Day3

Source: Internet
Author: User

The main part is to review the basic contents of the previous, and the concept of function

Number of combinations

#include <stdio.h>int f (int n) {        int m=1;        for (int i=1;i<=n;i++)            m*=i;        return m;} int main (void) {        int n,m;        scanf ("%d%d", &n,&m);        printf ("%d\n", f (N)/(f (M) *f (n-m)));        return 0;}

Prime number of twins

 #include <stdio.h>int isprime (int n) {int i;        for (i=2;i*i<=n;i++) if (n%i==0) return 0; return 1;}        int main (void) {int m;        scanf ("%d", &m);                    for (int i=m-2;i>=3;i--) {if (IsPrime (i) &&isprime (i+2)) {                    printf ("%d%d\n", i,i+2);                Break }} return 0;}        #include <stdio.h> #include <math.h> #include <assert.h>int isprime (int x) {int i,m;        ASSERT (x>=0);        M=floor (sqrt (x) +0.5);        for (i=2;i<=m;i++) if (x%i==0) return 0; return 1;}        int main (void) {int i,m;        scanf ("%d", &m);                        for (i=m-2;i>=3;i--) {if (IsPrime (i) &&isprime (i+2)) {                        printf ("%d%d\n", i,i+2);                    Break }} return 0;} 

Exchange function pointers are used, multiple values are returned

int swap (int *a,int *b) {    t=*a;*a=*b;*b=t;}

Note the use of GDB

GCC test.c-g

GDB a.out (gdb a.exe)

Definition of recursion

  

Algorithmic Getting Started note------------Day3

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.