字符数组练习12

人盡茶涼 提交于 2019-12-05 12:11:43

#include<stdio.h>
#include<stdlib.h>
int main(){
 static int a[2][3] = { { 1, 2, 3 }, { 4, 5, 6 } };
 static int b[3][2], i, j;
 printf("array a:\n");
 for (i = 0; i <= 1; i++){
  for (j = 0; j <= 2; j++)
  {
   printf("%4d", a[i][j]);
   b[j][i] = a[i][j];
  }
  printf("\n");
 }
 printf("array b:\n");
 for (i = 0; i <= 2; i++){
  for (j = 0; j <= 1; j++)
   printf("%4d", b[i][j]);
   printf("\n");
 }
system("pause");
return 0;
}

#include<stdio.h>
#include<stdlib.h>
int main(){
 char c[10] = { 'T', ' ', 'a', 'm', ' ', 'h', 'a', 'p', 'p', 'y' };
 int i;
 for (i = 0; i < 10; i++){
  printf("%c", c[i]);
 }
system("pause");
return 0;
}

#define   _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
void main(){
 printf("请输入一个字符串:");
 char str[11];
 scanf("%s",str);
 for (int i = 0; i < 11;i++)
  printf("%s", str[i]);
/*void main(){
 char c[10] = { "china" };
 printf("%s", c);
*/
system("pause");
return 0;
}

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void main(){
 char c, s[80];
 int i = 0;
 puts("输入字符串");
 while ((c = getchar()) != '\n')
  s[i++] = c;
 s[i] = '\0';
 puts("输出字符串");
 puts(s);
system("pause");
return 0;
}

/*#include<stdio.h>
#include<stdlib.h>
int main(){
 char str1[20], str2[] = "program";
 strcpy(str1, str2);
 printf("%s\n", str1);
system("pause");
return 0;
}*/
#include<stdio.h>
#include<stdlib.h>
int main(){
 char str1[30] = "Good ";
 char str2[] = "morning";
 strcat(str1, str2);
 printf("%s\n", str1);

#include<stdio.h>
#include<stdlib.h>
int main(){
 char str1[] = "good morning";
 char str2[] = "good afternoon";
 if (strcmp(str1, str2) == 0){
  printf("str1=str2\n");
 }
 else if (strcmp(str1, str2) < 0){
  printf("str1>str2\n");
 }
 else
  printf("str1<str2\n");
system("pause");
return 0;
}

#define  _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
int main(){
 int year=0;
 printf("%d", year);
 scanf("%d", &year);
 if (year % 400 == 0 || year % 4 == 0 && year % 100 != 0){
  printf("%d", 1);
 }
 else
  printf("%d", 0);
system("pause");
return 0;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!