/*
1. 查找指定字符在字符串中第一次出现的位置,若找到则从该字符开始打印余下的字符串,找不到,
则打印“Not Found”。
#include <stdio.h>
#include <string.h>
#define MAXSIZE 100
int main(void)
{
char str[MAXSIZE];
char ch;
int length;
int i;
puts("please enter the string:");
gets(str);
puts("please enter the searching character:");
scanf("%c",&ch);
length=strlen(str);
for(i=0;i<length;i++)
{
if(str[i]==ch)
break;
}
if(i==length)
puts("Not Found!");
else
for(;i<length;i++)
printf("%c",str[i]);
printf("\n");
return 0;
}
*/
/*
2. 从键盘输入若干字符,以符号“@”结束。编一个C程序统计这些符号的个数(不包括@),
存入数组a[0],并将这些符号依次存入a[1]、a[2]、a[3]………中。接着利用a[0]中存放的字符个数,
输出这些字符。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAXSIZE 100
int main()
{
int length;
char str[MAXSIZE];
char *a;
int i;
printf("please enter the characters which end with '@'.\n");
gets(str);
length=strlen(str);
a=(char *)malloc((length+1)*sizeof(char));
if(!a)
exit(0);
a[0]=length-1;
for(i=1;i<length;i++)
a[i]=str[i-1];
a[i]='\0';
for(i=1;i<=a[0];i++)
printf("%c",a[i]);
printf("\n");
return 0;
}
*/
/*
3.编程实现从键盘为一个6×6 整型数组赋值,并将每一行的最小值和最大值显示出来。
#include <stdio.h>
int main()
{
int i;
int j;
int min;
int max;
int matr[6][6];
puts("please enter the maxtrix's number:");
for(i=0;i<6;i++)
for(j=0;j<6;j++)
scanf("%d",&matr[i][j]);
for(i=0;i<6;i++)
{
min=matr[i][0];
max=matr[i][0];
for(j=0;j<6;j++)
{
if(matr[i][j]<min)
min=matr[i][j];
if(matr[i][j]>max)
max=matr[i][j];
}
printf("The %d line's mininum and maxinum are %d and %d. \n",i+1,min,max);
}
return 0;
}
*/
/*
4. 编程实现将一个用户从键盘临时输入的数插入到一个已排好序的数组中,插入后仍然有序。
#include <stdio.h>
#include <stdlib.h>
int main()
{
int length;
int *ip;
int i;
printf("please enter the length which is the initation arry's size:\n");
scanf("%d",&length);
fflush(stdin);
ip=(int *)malloc((length+1)*sizeof(int));
if(!ip)
exit(0);
printf("please enter the arry's result:\n");
for(i=0;i<length;i++)
scanf("%d",ip+i);//不能对数组的名字进行运算
printf("the arry before sorting is as following:\n");
for(i=0;i<length;i++)
printf("%4d",*(ip+i));
printf("\n");
void Sort(int*,int);
Sort(ip,length);
printf("the arry after sorting is as following:\n");
for(i=0;i<length;i++)
printf("%4d",*(ip+i));
printf("\n");
printf("please enter the inserting number:\n");
scanf("%d",ip+length);
Sort(ip,length+1);
printf("the arry after sorting(with the inserted number) is as following:\n");
for(i=0;i<length+1;i++)
printf("%4d",*(ip+i));
printf("\n");
return 0;
}
void Sort(int * ip,int length)
{
int i;
int j;
int k;
int temp;
for(i=0;i<length;i++)
{
k=i;
for(j=i+1;j<length;j++)
if(*(ip+j)<*(ip+k))
k=j;
if(k!=i)
{
temp=*(ip+k);
*(ip+k)=*(ip+i);
*(ip+i)=temp;
}
}
}
*/