1. 计算一个数的 n 次方,例如: 23,其中 2 为基数,3 为指数
#include<stdio.h>
#include<math.h>
int main(){
int a,b,result;
scanf("%d %d",&a,&b);
result=pow(a,b);
printf("%d",result);
return 0;
}
输出结果:8
2. 用户输入数字,判断该数字是几位数
#include <stdio.h>
int main()
{
int num,count=0;
scanf("%d",&num);
while(num){
num/=10;
count++;
}
printf("%d",count);
return 0;
}
例如 321 为3位数
3. 字符串的反转
#include <stdio.h>
void reverseSentence();
int main()
{
printf("输入一个字符串: ");
reverseSentence();
return 0;
}
void reverseSentence()
{
char c;
scanf("%c", &c);
if( c != '\n')
{
reverseSentence();
printf("%c",c);
}
}
sdf fds