C
#include
int main()
{
int i;
double e, t;
i = 1, e = 1, t = 1;
while (t >= 1e-7)
{
t = t / i;
i += 1;
e += t;
}
printf("%5lf",e);
}
C++
#include
using namespace std;
int main()
{
int i;
double e,t;
i = 1, e = 1, t = 1;
while (t>=1e-7)
{
t = t / i;
i += 1;
e += t;
}
cout << e;
}
C
#include
int main()
{
double i=1;
int j = 1;
double PI, t;
PI = 1.00;
t = 1.00;
while (t>1e-7)
{
i += 2;
t = 1 / i;
if (j%2==1)
PI -= t;
else
PI += t;
j += 1;
}
printf("PI的值为%5lf", 4*PI);
return 0;
}
C++
#include
using namespace std;
int main()
{
double i=1;
int j = 1;
double PI, t;
PI = 1.00;
t = 1.00;
while (t>1e-7)
{
i += 2;
t = 1 / i;
if (j%2==1)
PI -= t;
else
PI += t;
j += 1;
}
cout << "PI的值为" << 4 * PI;
return 0;
}
C
#include
int main()
{
double PI = 1.0;
double i = 1.0, j = 1.0;
double t = 1.0;
while (t > 1e-17)
{
i += 2;
t = t * j / i;
PI += t;
j = j + 1;
}
printf("PI的值是%If", 2*PI);
}
C++
#include
using namespace std;
int main()
{
double PI = 1.0;
double i = 1.0,j=1.0;
double t = 1.0;
while(t>1e-17)
{
i += 2;
t = t * j / i;
PI += t;
j = j + 1;
}
cout << "PI的值是" << PI*2;
}
C
#include
int main()
{
int a;
int count1 = 0, count2 = 0, count3 = 0;
printf("请输入20个数");
for (int i = 0; i < 20; i++)
{
scanf_s("%d", &a);
if (a > 0) count1++;
else if (a == 0) count2++;
else count3++;
}
printf("正数的个数是:%d\n", count1);
printf("零的个数是:%d\n", count2);
printf("负数的个数是:%d\n", count3);
return 0;
}
C++
#include
using namespace std;
int main()
{
int a;
int count1=0, count2=0, count3=0;
cout << "请输入20个数" << endl;
for(int i=0;i<20;i++)
{
cin >> a;
if (a > 0) count1++;
else if (a == 0) count2++;
else count3++;
}
cout << "正数的个数是:" << count1<<endl;
cout << "零的个数是:" << count2 << endl;
cout << "负数的个数是:" << count3 << endl;
}
C
#include
int main()
{
int a, n = 0, m = 0;
printf("输入若干个整数,输入0表示结束\n");
scanf_s("%d",&a);
while (a != 0)
{
if (a % 2 == 0) n += a;
else m += a;
scanf_s("%d", &a);
}
printf("奇数的和为%d\n",m);
printf("偶数的和为%d", n);
}
C++
#include
using namespace std;
int main()
{
int a, n = 0, m = 0;
cout<<"输入若干个整数,输入0表示结束"<<endl;
cin >> a;
while (a != 0)
{
if (a % 2 == 0) n += a;
else m += a;
cin >> a;
}
cout << n << " " << m;
}
C
#include
int pownew(int, int);
int main()
{
int x = 4, y = 3;
int z;
z = pownew(x, y);
printf("%d",z);
return 0;
}
int pownew(int x, int y)
{
int z = 1;
for (int i = 0; i < y; i++)
z = z * x;
return z;
}
C++
#include
using namespace std;
int pownew(int,int);
int main()
{
int x = 4, y = 5;
int z;
z = pownew(x, y);
cout << z;
}
int pownew(int x, int y)
{
int z=1;
for (int i = 0; i < y; i++)
z = z * x;
return z;
}
C
#include
int main()
{
int i = 1, j = 0, k = 0, a = 0;
for (int i = 1; i < 10; i++)
for (int j = 0; j < 10; j++)
for (int k = 0; k < 10; k++)
if ((i * i * i + j * j * j + k * k * k) == (100 * i + 10 * j + k))
a = a + 1;
printf("%d",a) ;
}
C++
#include
using namespace std;
int main()
{
int i = 1 ,j = 0, k = 0,a=0;
for (int i=1;i<10;i++)
for (int j=0;j<10;j++)
for (int k=0;k<10;k++)
{
if((i*i*i+j*j*j+k*k*k)==(100*i+10*j+k))
{
a = a + 1;
cout << i<<j<< k<<endl;
}
}
cout << a;
}
C
#include
int perfect();
int perfect(int n)
{
int i, s = 1;
for (i = 2; i <= n / 2; i++)
if (n % i == 0) s = s + i;
if (s == n) return 1;
else return 0;
}
int main()
{
int n;
for (n = 2; n <= 1000; n++)
if (perfect(n))
printf("%d\n",n);
return 0;
}
C++
#include
using namespace std;
int perfect();
int perfect(int n)
{
int i, s = 1;
for (i = 2; i <= n / 2; i++)
if (n % i == 0) s = s + i;
if (s == n) return 1;
else return 0;
}
int main()
{
int n;
for (n = 2; n <= 1000; n++)
if (perfect(n))
cout << n << endl;
}
C
#include
int fib(int);
int main()
{
int n = 6;
int k;
k = fib(n);
printf("%d", k);
return 0;
}
int fib(int n)
{
if (n == 1 || n == 2)
return 1;
int f1 = 1; int f2 = 1;
int fn = 0;
for (int i = 3; i <= n; i++) {
fn = f1 + f2;
f1 = f2;
f2 = fn;
}
return fn;
}
C++
#include
using namespace std;
int f(int);
int main()
{
int k;
int n=6;
k = f(n);
cout << k;
}
int f(int n)
{
if (n == 1) return 1;
if (n == 2) return 1;
else
return f(n - 1) + f(n - 2);
}
C
#include
int revese(int);
int main()
{
int k = 345;
int z;
z = revese(k);
printf("%d",z);
}
int revese(int k)
{
int s = 0;
int temp = 0;
while (k > 0)
{
temp = k % 10;
k = k / 10;
s = s * 10 + temp;
}
return s;
}
C++
#include
using namespace std;
int revese(int);
int main()
{
int k = 345;
int z;
z = revese(k);
cout << z;
}
int revese(int k)
{
int s = 0;
int temp = 0;
while(k>0)
{
temp = k % 10;
k = k / 10;
s = s * 10 + temp;
}
return s;
}