tesla-1i / c-program Goto Github PK
View Code? Open in Web Editor NEWc or cpp
c or cpp
#include <stdio.h>//打印1到n的阶乘
#define size 10
int fact(int n)//打印n的阶乘,
{
if (n>0)//函数递归
{
return n*fact(n-1);
}
else
return 1;
}
int calnumber(int nums[],int n)
{
int i;
if (n>0 && n<size+1)
{
for ( i = 0; i < n; ++i)
{
nums[i]=fact(i+1);//调用fact 函数,将阶乘存在数组中
}
return 1;
}
else
return 0;
}
int main(int argc, char const *argv[])
{
int nums[size];
int i,n;
scanf("%d",&n);
if(!calnumber(nums,n))
{
printf("illegal number!\n");
return 1;
}
else
{
for ( i = 0; i < n; ++i)
{
printf("%d\n",nums[i] );
}
}
return 0;
}
//十进制数转换成二进制数输出
#include <stdio.h>
void d2b(unsigned int n)
{
if (n==0 || n==1)
{
putchar('\n');
}
else
{
d2b(n/2);//除以二
printf("%d\n",n%2 );//除以二取余
}
}
int main()
{
int n;
printf("input number:\n");
scanf("%d",&n);
d2b(n);
return 0;
}
//编程输出fibonaci数列前n项
#include <stdio.h>
void fib(int n,int i,int i1,int i2)
{
if (i==2)
{
printf("1,\t1");
}
if (i<n)
{
printf(",\t%d",i1+i2 );
fib(n,i+1,i1+i2,i1);
}
else
printf("\n");
}
int main(int argc, char const *argv[])
{
int n;
printf("input numner:\n");
scanf("%d",&n);
fib(n,2,1,1);
return 0;
}
#include <stdio.h>//#include <stdio.h>用递归方法,求数组元素的加和
int sum(int nums[],int n)
{
int sum2;
if(n>1)
sum2 = nums[n-1]+sum(nums,n-1);//n-1号值加到sum2,
else
sum2 = nums[0];
return sum2;
}
int main()
{
int nums[3]={1,2,3};
int sum1;
sum1 = sum(nums,3);//3指的是个数,不是标号!!!!!!!!
printf("%d\n",sum1 );
return 0;
}
int sum(int nums[],int n)
{
int sum2;
if(n>1)
sum2 = nums[n-1]+sum(nums,n-1);//n-1号值加到sum2,
else
sum2 = nums[0];
return sum2;
}
int main()
{
int nums[3]={1,2,3};
int sum1;
sum1 = sum(nums,3);//3指的是个数,不是标号!!!!!!!!
printf("%d\n",sum1 );
return 0;
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.