标签:else printf color tchar while dex style put lag
1.方阵
#include<stdio.h> int main(void) { int i,j,n,temp; int a[6][6]; printf("Enter n:"); scanf("%d",&n); for(i=0;i<n;i++) for(j=0;j<n;j++) a[i][j]=i*n+j+1; for(i=0;i<n;i++) for(j=0;j<n;j++) if(i<=j){ temp=a[i][j]; a[i][j]=a[j][i]; a[j][i]=temp; } for(i=0;i<n;i++){ for(j=0;j<n;j++) printf("%4d",a[i][j]); printf("\n"); } return 0; }
2 99乘法表
#include<stdio.h> int main(void) { int i,j; int a[10][10]; for(i=1;i<10;i++){ for(j=1;j<=i;j++){ a[i][j]=i*j; printf("%d*%d=%d\t",i,j,a[i][j]); } printf("\n"); } return 0; }
3 字符串
#include<stdio.h> int main(void) { int i,k,temp; char str [80]; int n; printf("enter a str:"); i=0; while((str[i]=getchar())!=‘\n‘)i++; str[i]=‘\0‘; k=i-1; for(i=0;i<k;i++) { temp=str[i]; str[i]=str[k]; str[k]=temp; k--; } for(i=0;str[i]!=‘\0‘;i++) putchar(str[i]); return 0; }
4 not found
#include<stdio.h> int main(void) { int i=0,k=0,flag=0; char str[80],m; printf("input a character:"); scanf("%c",&m); printf("input a string:"); getchar(); while((str[i]=getchar())!=‘\n‘) i++; str[i]=‘\0‘; for(i=0;str[i]!=‘\0‘;i++){ if(str[i]==m)k=i; flag=1; } if(flag==1) printf("index=%d\n",k); else printf("not found!\n"); return 0; }
标签:else printf color tchar while dex style put lag
原文地址:http://www.cnblogs.com/moyansameal/p/6081582.html