C
#include
int rev(int k);
int main()
{
int k = 234;
rev(k);
}
int rev(int k)
{
int z;
while (k > 0)
{
z = k % 10;
printf(" %d",z);
k = k / 10;
}
return 0;
}
C++
#include
using namespace std;
int rev(int k);
int main()
{
int k = 234;
rev(k);
}
int rev(int k)
{
int z;
while(k>0)
{
z = k % 10;
cout << z << " ";
k = k / 10;
}
return 0;
}
C
#include
int show(int);
int main()
{
int n = 7990;
show(n);
}
int show(int n)
{
int m = n;
int i = 0;
int k = 1;
int s;
while (m > 0)
{
i = i + 1;
m = m / 10;
//cout << "i==" << i;
}
for (int j = 1; j < i; j++)
k = k * 10; //从最大值开始除
while (k > 0)
{
s = n / k;
printf(" %d",s);
n = n % k;
k = k / 10;
}
return 0;
}
C++
#include
using namespace std;
int show(int);
int main()
{
int n = 7990;
show(n);
}
int show(int n)
{
int m = n;
int i = 0;
int k = 1;
int s;
while (m>0)
{
i = i + 1;
m = m / 10;
//cout << "i==" << i;
}
for (int j = 1; j < i; j++)
k = k * 10; //从最大值开始除
//cout << " k==" << k<
while(k>0)
{
s = n / k;
cout << " "<<s;
n = n %k;
k = k / 10;
}
return 0;
}
C
#include
int sum(int);
int main()
{
int z;
int n = 345;
z = sum(n);
printf("%d",z);
}
int sum(int n)
{
int s = 0;
while (n)
{
s += n % 10;
n /= 10;
};
return s;
}
C++
#include
using namespace std;
int sum(int);
int main()
{
int z;
int n = 345;
z = sum(n);
cout<<z;
}
int sum(int n)
{
int s = 0;
while (n)
{
s += n % 10;
n /= 10;
};
return s;
}
C
#include
#include
bool isprime(int);
int main()
{
for (int i = 2; i <= 1000; i++)
{
if (isprime(i))
printf(" %d",i);
}
return 0;
}
bool isprime(int k)
{
float m;
m = sqrt(float(k));
for (int i = 2; i <= m; i++)
{
if (k % i == 0)
return false;
}
return true;
}
C++
#include
#include
using namespace std;
bool isprime(int);
int main()
{
for(int i=2;i<=1000;i++)
{
if (isprime(i))
cout << " " << i;
}
}
bool isprime(int k)
{
float m;
m = sqrt(float(k));
for (int i = 2; i <= m; i++)
{
if (k % i == 0)
return false;
}
return true;
}
#include
#include
#include
#include
using namespace std;
int main()
{
int i, k, a[1001];
for (i = 2; i <= 1000; i++) a[i] = 1;
float s = sqrt(float(1000));
for (i = 2; i <= s; i++)
if (a[i] == 1)
{
k = 2 * i;
while (k <= 1000)
{
a[k] = 0;
k = k + i;
}
}
for (i = 2; i <= 1000; i++)
if (a[i] == 1) cout << setw(5) << i;
}
C
#include
bool IsLeapYear(int);
int main()
{
int y = 2008;
bool z = IsLeapYear(y);
printf("%d",z);
}
bool IsLeapYear(int y)
{
return (y % 4 == 0 && y % 100 != 0) || (y % 400 == 0);
}
C++
#include
using namespace std;
bool IsLeapYear(int);
int main()
{
int y = 2008;
bool z = IsLeapYear(y);
cout << z;
}
bool IsLeapYear(int y)
{
return (y % 4 == 0 && y % 100 != 0) || (y % 400 == 0);
}
C
#include
void swap(int*, int*);
void swap(int& a, int& b)
{
int t;
t = a; a = b; b = t;
}
int main()
{
int a = 3, b = 5;
swap(a, b);
printf("%d %d",a,b);
}
C++
#include
using namespace std;
void swap(int*, int*);
void swap(int& a, int& b)
{
int t;
t = a; a = b; b = t;
}
int main()
{
int a = 3, b = 5;
swap(a, b);
cout << a <<" "<< b;
}
C
#include
int gcd(int, int);
int main()
{
int a = 45, b = 90;
int z;
a > b ? z = gcd(a, b) : z = gcd(b, a);
printf("%d",z);
}
int gcd(int a, int b)
{
int r = a % b;
if (r == 0) return b;
else
return gcd(b, r);
}
C++
#include
using namespace std;
int gcd(int, int);
int main()
{
int a = 45, b = 90;
int z;
a > b ? z=gcd(a, b) : z=gcd(b, a);
cout << z;
}
int gcd(int a,int b)
{
int r = a % b;
if (r == 0) return b;
else
return gcd(b, r);
}
C
#include
int gcd(int, int);
int main()
{
int a = 45, b = 25;
int z;
a > b ? z = gcd(a, b) : z = gcd(b, a);
printf("%d", a*b/z);
}
int gcd(int a, int b)
{
int r = a % b;
if (r == 0) return b;
else
return gcd(b, r);
}
C++
#include
using namespace std;
int gcd(int, int);
int main()
{
int a = 45, b = 25;
int z;
a > b ? z=gcd(a, b) : z=gcd(b, a);
cout << a*b/z;
}
int gcd(int a,int b)
{
int r = a % b;
if (r == 0) return b;
else
return gcd(b, r);
}
C
#include
using namespace std;
int main()
{
for (int a = 0; a <= 20; a++)
for (int b = 0; b <= 33; b++)
for (int c = 0; c <= 100 - a - b; c = c + 3)
if ((a + b + c == 100) and (5 * a + 3 * b + c / 3 == 100))
printf("%d %d %d \n",a,b,c);
}
C++
#include
using namespace std;
int main()
{
for (int a = 0; a <= 20; a++)
for (int b = 0; b <= 33; b++)
for (int c = 0; c <= 100 - a - b; c = c + 3)
if ((a + b + c == 100) and (5 * a + 3 * b + c / 3 == 100))
cout << a << " "<<b<<" " << c<<endl;
}