C language implementation of the monkey peach like algorithm
- 2020-04-02 03:00:55
- OfStack
C basic algorithm problem for many years did not touch C very depressed ~
//
// main.c
//Algorithm problem
//
// Created by mac on 14-8-9.
//Copyright (c) 2014 mac.all rights reserved.
//
#include <stdio.h>
#include <math.h>
//10.
int questionN(int n)
{
int a = 2,num = 0; //N is the number of he bits, and a is the base
int sum = 0;
for (int i = 0 ; i++ < n; ) {
if(i==0)
{
num = a;
continue;
}
num = num*10 + a; //2+10^i
printf("%d+",num);
sum += num;
}
return sum;
}
//11.
int peank(int n)
{
if (n == 1 ) return 1;
return (peank(n-1)+1)*2;
}
int my_peank()
{
int pean = 1,day = 9;
for (;day-->0; ) pean = (pean+1)*2;
return pean;
}
int main(int argc, const char * argv[])
{
printf(" A total of picked [%d] A peach ...( My algorithm )n",my_peank());
printf(" A total of picked [%d] A peach ...( Teacher's algorithm )n",peank(10));
printf("=[%d]",questionN(3));
return 0;
}
The above is the entire content of this article, I hope you can like, and then encounter this kind of retarded interview questions can directly spray dead interviewers.