#include <stdio.h>int secureNum(int n)
{
int x = n, tmp = 0, step = 0;
while(tmp < n)//只要计算的差值小于n,继续寻找xfor(tmp = ++x, step = 1; tmp >= n && x / step; step *= 10)
tmp -= x / step % 10;
return x;
}
int main(void)
{
intvalue = 0;
scanf("%d", &value);
printf("加密后的数字为%d\n", secureNum(value));
return0;
}
给定非负整数a, b, m,利用基本算数运算符(+-*/%)即位运算符,计算a^b mod m. 输入:一行三个非负整数, 分别为a,b,m的值,m不为0 输出:a^b mod m的结果 例:输入 2,10,5 输出 4
#include <stdio.h>int calculate(int a, int b, intm)
{
int sum = 0;
if(0 == b)
return1 % m;
if(0 == a)
return0;
sum = a;
while(--b)
sum *= a;
return sum % m;
}
int main(void)
{
int a = 0, b = 0, m = 0;
printf("请输入a,b,m的值:");
scanf("%d%d%d", &a, &b, &m);
printf("a^b mod m = %d\n", calculate(a, b, m));
return0;
}
#define H 100
void func1(int n)
{
int i = 0;
float sum = 0, step = 0;
step = H;
for(i = 0; i < n; i++)
{
sum += step + step / 2; //每次返回最高点所经过的距离step /= 2;
}
printf("第%d次落地共经过%f米,反弹%f米高\n", n, sum - step, step);
}
编写一个函数,要求输入年月日时分秒,输出该年月日时分秒的下一秒。如输入2004年12月31日23时59分59秒,则输出2005年1月1日0时0分0秒。 函数原型:PS:故意这么写的,别给乱换 void show_time(int *year, int *month, int *date, int *hour, int *minute, int *second)
void competitionList(void)
{
char a = 0, b = 0, c = 0;
if(c != 'X' && c != 'Z')
c = 'Y';
if(a != 'X' && c == 'Y')
a = 'Z';
if(a == 'Z' && c == 'Y')
b = 'X';
printf("aVS%c, bVS%c, cVS%c\n", a, b, c);
}
用C语言实现字符串中子字符串的替换, 成功返回0,失败返回-1.例如:“ABCDEFG”这个字符串,把其中”BCD”替换成“9527”这个子串,结果变成:“A9527EFG” 函数原型: int str_replace(char str, char replaced_str, char *new_str)
int str_replace(char *str, char *replaced_str, char *new_str)
{
unsigned int i = 0, j = 0, k = 0, m = 0, l = 0;
//在原字符串中找要替换的字符串while(str[i]){
if(str[i] == replaced_str[j]){
k = i;
while(str[++i] == replaced_str[++j] && str[i])
;
}
else
i++;
if(0 == replaced_str[j]) //j == strlen(replaced_str)break;
else
j = 0;
}
if(replaced_str[j])
return -1;
//复制
l = strlen(str);
for(i = 0; new_str[i] && i < j; i++)
str[k++] = new_str[i];
if(0 == new_str[i]) //新字符串长度小于所替换的字符串while(str[k++] = str[k + j - i])
;
/* do{
str[k] = str[k + j - i]; //k+j-i表示str中所替换字符串的下一个字符的下标
}while(str[(k++)+j-i]);
*/else//假设str数组空间足够大for(m = l - k + 1; i < strlen(new_str); i++, l++){ //加上'\0',m = l - k + 1for(k = 0, j = l + 1; k < m; k++, j--) //加上'\0',j = l + 1str[j] = str[j-1];
str[j] = new_str[i];
}
return0;
}
int main(void)
{
charstr[100] = "aabbcdefg";
printf("%d, %s\n", str_replace(str, "bc", "12345"), str);
return0;
}