64,636
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>//用递归调用求阶乘
using namespace std;
int fac(int n)
{
int back;
if(n<0)
cout<<"wrong number"<<endl;
if(n==0)
back=1;
if(n>0)
back=n*fac(n-1);
return (back);
}
int main(void)
{
cout<<"input a number"<<endl;
int x;
cin>>x;
x=fac(x);
cout<<x;
}
#include<iostream>//输出乘法口诀表
using namespace std;
void main()
{
int x,y,i;
for(x=1;x<=9;x++)
{
for(y=1;y<=x;y++)
{
i=x*y;
cout<<x<<'*'<<y<<'='<<i<<'\t';
}
cout<<endl;
}
}
//输入二进制数变成十进制,自己编的,见笑,刚刚学
#include <stdio.h>
void main()
{
int getnumber, h, i, n=0, d=0;
long a[100];
printf("请输入一列二进制数");
scanf("%d",&getnumber);
for(i=0;d==0;i=i*10)
{
a[n]=getnumber%10;
getnumber=getnumber/10;
if(getnumber==0&&a[n]==0)
d=1;
n++;
}
n=n-1;
printf("这是%d位数\n",n);
for(h=0;h<n;h++)
{
for(d=1;d<=h;d++)
{
a[h]=a[h]*2;
}
}
for(i=n-1;i>=1;i--)
{a[i-1]=a[i]+a[i-1];}
printf("%ld\n",a[0]);
}
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
cout << "请输入延时时间(单位:秒):";
float secs;
cin >> secs;
clock_t delay = secs*CLOCKS_PER_SEC;
cout << "starting\a\n";
clock_t start = clock();
while(clock()-start <delay); //延时
cout << "done\a\n";
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#define STACK_INIT_SIZE 100//³õÊÔ·ÖÅä¿Õ¼ä´óС
typedef struct
{
char *base;
char *top;
char stacksize;
}SqStack;
bool InitStack(SqStack &S)
{
S.base = (char *)malloc(STACK_INIT_SIZE * sizeof(char));
if (!S.base)
{
return false;
}
S.top = S.base;
S.stacksize = STACK_INIT_SIZE;
return true;
}
char GetTop(SqStack S)
{
char e;
if (S.top == S.base)
{
return '@';
}
e = *(S.top - 1);
return e;
}
bool Push(SqStack &S, char e)
{
if (S.top - S.base >= S.stacksize)
{
return false;
}
*S.top++ = e;
return true;
}
bool Pop(SqStack &S, char&e)
{
if (S.base == S.top )
{
return false;
}
e = *--S.top;
return true;
}
int main()
{
char ch;
SqStack stack;
InitStack(stack);
while(cin>>ch)
{
Push(stack, ch);
}
while(stack.base != stack.top)
{
Pop(stack, ch);
cout<<ch<<endl;
}
getchar();
return 0;
}