跪求c语言作业

来源:百度知道 编辑:UC知道 时间:2024/06/21 22:55:07
1. Write a program that reads input until encountering character “#” and then reports the number of spaces read, the number of newline characters read, and the number of all other characters read.
2. Write a program that will print out all whole numbers can be exactly divided by either 7 or 11 but never be exactly divided by both 7 and 11 between 50 and 100.

#include <stdio.h>
#define MAX_LENGTH 10000
void main()
{
char c[MAX_LENGTH];
int i=0;
int spaceCount=0, newlineCount=0, restCount=0;

while(1)
{
scanf("%c", &(c[i]));
if(c[i]=='#')
c[i] = 0; // or c[i] = '\0';
break;
i++;
}
for(i=0; i<strlen(c); i++)
{
if(c[i]==' ')
spaceCount++;
else if(c[i]==0x0D) // 0x0D is newline in ASCII
newlineCount++;
else
restCount++;
}
printf("%d space, %d newline, %d restchar", spaceCount, newlineCount, restCount);

}

2
2.

void main()
{
int i
for(i=50;i<=100;i++)
{
if((i%7==0 || i%11 ==0) && (i%77 != 0))
printf("%d, ",i);
}
}

2. int i
for(i=50;i<=100;i++)
{
if((i%7==0 || i%1