#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main() {
unsigned long pulArray[] = { 6,7,8,9,10 };
unsigned long* pulPtr;
pulPtr = pulArray;
//pulPtr - 元素6的地址
*(pulPtr + 3) += 3;
//pulPtr+3 - 元素9的地址
printf("%d,%d\n", *pulPtr, *(pulPtr + 3));//6,12
return 0;
}
字符串逆序输出
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
//字符串逆序输出
void Reverse(char* str) {
int len = strlen(str);
char* left = str;
char* right = str + len - 1;
while (left<right) {
char tmp = *left;
*left = *right;
*right = tmp;
left++;
right--;
}
}
int main() {
char arr[256] = { 0 };
//scanf("%s", arr);
gets(arr);
Reverse(arr);
printf("%s\n", arr);
return 0;
}
hello world!
!dlrow olleh
输入a和项数,求Sn=a+aa+aaa+aaaa+…的前n项之和
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
//输入a,求Sn=a+aa+aaa+aaaa+......的前n项之和
int main() {
int a = 0;
int n = 0;
scanf("%d%d", &a, &n);
int sum = 0;
int i = 0;
int ret = 0;
for (i = 0; i < n; i++) {
ret = ret * 10 + a;
sum += ret;
}
printf("%d\n", sum);
return 0;
}
2 5
24690