输出菱形和三角形
1. #include<stdio.h> #include<stdlib.h> int main () { int i=0; int j=0; int k=0; int l=0; char arr1[] = " * "; char arr2[] = "*************" ; int right = 14; int left = 1; int mid=0; mid = right/2 ; for(i=0;i<7;i++) { arr1[mid-i] = arr2[mid-i]; arr1[mid+i] = arr2[mid+i]; for(j=0;j<7;j++); printf("%s\n",arr1); } for(k=0;k<6;k++) { char arr3[] = " * "; right--; left++; arr1[right] = arr3[right]; arr1[left] = arr3[left]; for(l=0;l<6;l++); printf("%s\n",arr1); } system("pause"); return 0 ; } 2. #include<stdio.h> #include<stdlib.h> int main() { int i = 0; int j = 0; int k = 0; int l = 0; for(i=0;i<=999;i++) { int j = i%1000/100; int k = i%100/10; int l = i%10; if( j*j*j+k*k*k+l*l*l==i ) printf("%d\n",i); } system ("pause"); return 0 ; } 3. #include<stdio.h> #include<stdlib.h> int main() {int i = 0; int n = 0; int a = 0; int sum = 0; int add = 0; scanf("%d %d",&n,&a); for(i=0;i<n;i++) { add=add*10+a; sum+=add; } printf("%d",sum); system("pause"); return 0 ; }