[1] 完成 Input n; Output : 1 + 2 + ... + n
#include <stdio.h>
#include <stdlib.h>
int main(){
int n,r;
scanf("%d",&n);
r=0;
for(int i=1;i<=n;i++){
r = r + i;
}
printf("%d\n",r);
system("pause");
return 1;
}
1. 求1 + 3 + 5 + …+ n 的值,其中 n 由使用者指定的奇數
2. 求2 + 4 + 6 + …+ n 的值,其中 n 由使用者指定的偶數
3. 印出ASCII碼中41~64的字元
4. 印出 1~100中可被6整除的數值
5. 印出12 + 22 + 32 + 42 + …+ 502的值
[2] 將 0 放到A[0],將 1 放到A[1], ...將 size-1 放到A[size-1],並印出A的內容#include <stdio.h>
#include <stdlib.h>
#define size 10
int main(){
int r;
int A[size];
for(int a=0; a<size ;a++){
A[a]=a;
}
for(int a=0; a<size ;a++){
printf("%d\n",A[a]); //A[a]=a;
}
system("pause");
return 1;
}
Array 中指定下列數值並印出
- 0, 1, 2, 3, …,
- 1,2,3,….
- 0,2,4,6,…
- 1,3,5,7,9,…
- 1,-1,1,-1,1,-1
- 1,-2,3,-4,5,-6,
- 0,1,2,-3,4,5,6,-7,8,9,10,-11...