急救,c语言编程题。 编写程序,将1—100间不能被3整除的数输出。

求救额,编写程序,将1—100间不能被3整除的数输出。看了这么多答案不知道哪个比较好,我们选修课是c语言,真的一点不懂啊,这个是考试题,忘亲们给个详细点的啊。 写在试卷上的。。。 么么么么
2026年09月22日 07:05
有5个网友回答
网友(1):


void sort(int *p1,int *p2)
{
int temp;
if(*p1 > *p2)
{
temp = *p1;
*p1 = *p2;
*p2 = temp;
}
}

void chars_num(char * str,int * upcase,int *lowcase,int * number,int *others)
{
char * p = str;
*upcase = *lowcase = *number = *others = 0;
if(str == 0)
return;

while (*p != '\0')
{
if('A' <= *p && *p <= 'Z')
(*upcase)++;
else if('a' <= *p && *p <= 'z')
(*lowcase)++;
else if('0'<= *p && *p <= '9')
(*number)++;
else
(*others)++;
p++;
}
}

int strcmp (char * p1, char * p2)
{
while ((*p1 != '\0') && (*p2 !='\0') && (*p1 == *p2) )
{
p1++;
p2++;
}
if((*p1 != '\0') && (*p2 =='\0'))
return *p1;
else if ((*p1 == '\0') && (*p2 !='\0'))
return -*p2;
else if((*p1 != '\0') && (*p2 !='\0'))
return *p1 - *p2;
else
return 0;
}
void main()
{
int a,b,c;
int temp;
char str[100];
int upcase,lowcase,number,others;
char cmp1[100],cmp2[100];
int result;

printf("\n1.输入3个整数,按由小到大的顺序输出. \n请输入三个整数:");
scanf("%d %d %d",&a,&b,&c);

sort(&a,&c);
sort(&b,&c);
sort(&a,&b);
printf("排序以后的值:%d,%d,%d\n",a,b,c);

printf("\n2.编程统计一个字符串中大写字母、小写字母、数字和其他字符的个数。 \n请输入一个字符串:");
scanf("%s",str);
chars_num(str,&upcase,&lowcase,&number,&others);
printf("上面字符串中大写字母个数为:%d,小写字母个数为:%d,数字个数为:%d,其它字符个数为:%d\n",upcase,lowcase,number,others);

fflush(stdin);
printf("\n用一个函数实现两个字符串的比较,即自己写一个strcmp函数,函数原型为:int strcmp (char * p1, char * p2);\n");
printf("请输入要比较的字符串:");
scanf("%s",cmp1);
printf("请输入要比较的另一个字符串:");
scanf("%s",cmp2);
result = strcmp(cmp1,cmp2);
printf("%s - %s = %d\n",cmp1,cmp2,result);

}

分太少了~加分吧

网友(2):

void main()
{
int i,j;
j=0;
for(int i=1;i<101;i++)
{
if(i%3!=0)
{ j++;
printf("%d ",i);
if(j=10)
printf("\n");
}
}
}

网友(3):

#include
void main()
{
int i;
for(i=1;i<=100;i++)
if( (i %3) != 0 )
printf(" %d ", i);
}

网友(4):

main()
{
int i;
for(i=0;i<=100;i++)
{
if(i%3!=0)
printf("1-100不能被3整除的数:%d",i);
println("\n");
}
}

网友(5):

void main(){
int i=1;
for(i;i<=100;i++){
if(i%3!=0){
printf("%d\n",i);
}
}
scanf();
}