求解C语言编程题

来源:百度知道 编辑:UC知道 时间:2024/05/12 05:58:14
1. 从键盘上输入一个字符串,在将其中的大写字母转换为小写字母后,输出到磁盘文件“abc.txt”中保存。
2. 若一维整型数组a中的数据已经按由小到大的顺序存放,请编写程序把a中每组相同的数据删得只剩一个(例如,a原为2,2,2,3,3,5,删除后变为2,3,5),然后按每行3个数据的格式输出数组a。

#include <stdio.h>

void main()
{
int a[]={1,1,2,2,2,3,3,4,5,5};
/*i遍历整个数组;length数组的长度;temp临时变量;pos输出位置控制变量*/
int i=1,length=0,temp,pos=1;

length=(sizeof(a)/sizeof(int));

temp=a[0];

/*输出第一个数,因为第一个数一定要输出*/
printf(" %d ",a[0]);
while(i<length)
{
if (a[i]!=temp)
{
if (pos%3==0)
{
printf("\n");
pos=1;
}

printf(" %d ",a[i]);
temp=a[i];
pos++;

}
i++;
}
getch();
}
数组是假设已知的。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char **argv)
{
FILE * fd;
char str[1024];
int i;
memset(str,0,1024);
printf("请输入字符串:\n");
scanf("%s",str);
for (i=0;i<strlen(st