C语言程序设计题目十六
计算一个数的n次方
#include <stdio.h>
#include <stdlib.h>
int main()
{
int base, exponent;
long long result = 1;
printf("基数:");
scanf("%d", &base);
printf("指数:");
scanf("%d", &exponent);
while (exponent != 0)
{
result *= base;
exponent--;
}
printf("结果:%lld\n", result);
system("pause");
return 0;
}
C语言程序设计题目十七
判断回文数
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n, reversedInterger = 0, remainder, originalInteger;
printf("输入一个整数:");
scanf("%d", &n);
originalInteger = n;
//翻转
while (n != 0)
{
remainder = n % 10;
reversedInterger = reversedInterger * 10 + remainder;
n /= 10;
}
//判断
if (reversedInterger != originalInteger)
{
printf("%d不是回文数\n", originalInteger);
}
else
{
printf("%d是回文数\n", originalInteger);
}
system("pause");
return 0;
}
C语言程序设计题目十八
判断素数
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n, i, flag = 0;
printf("请输入一个正整数:");
scanf("%d", &n);
for (i = 2; i <= n / 2; i++)
{
if (n%i == 0)
{
flag = 1;
break;
}
}
if (flag == 0)
{
printf("%d是素数\n", n);
}
else
{
printf("%d不是素数\n", n);
}
system("pause");
return 0;
}
C语言程序设计题目十九
判断阿姆斯壮数
#include <stdio.h>
#include <stdlib.h>
int main()
{
int number, originalNumber, remainder, result = 0;
printf("请输入三位数:");
scanf("%d", &number);
originalNumber = number;
while (originalNumber != 0)
{
remainder = originalNumber % 10;
result += remainder * remainder * remainder;
originalNumber /= 10;
}
if (result == number)
{
printf("%d是阿姆斯壮数\n", number);
}
else
{
printf("%d不是阿姆斯壮数\n", number);
}
system("pause");
return 0;
}
C语言程序设计题目二十
求一个整数的所有因数
#include <stdio.h>
#include <stdlib.h>
int main()
{
int number, i;
printf("请输入一个整数:");
scanf("%d", &number);
printf("%d的因数有:",number);
for (i = 1; i <= number / 2; i++)
{
if (number%i == 0)
{
printf("%d ", i);
}
}
system("pause");
return 0;
}
谢谢观看