
编程:(c语言) ,请编写一个函数proc,它的功能是:求出1----m之间(含m)能被7或11整除的所有整数
3个回答
展开全部
#include<stdio.h>
int proc(int m,int a[ ])
{
int i,n=0;
for(i=1;i<=m;i++)
if(i%7==0 || i%11==0) a[n++]=i; printf("%d\n",n);
return n;
}
int main()
{
int m,n,i,s[100]={0};
scanf("%d",&m);
n=proc(m,s);
for(i=0;i<n;i++)
printf("%d,",s[i]);
return 0;
}
int proc(int m,int a[ ])
{
int i,n=0;
for(i=1;i<=m;i++)
if(i%7==0 || i%11==0) a[n++]=i; printf("%d\n",n);
return n;
}
int main()
{
int m,n,i,s[100]={0};
scanf("%d",&m);
n=proc(m,s);
for(i=0;i<n;i++)
printf("%d,",s[i]);
return 0;
}
展开全部
int proc(m)
{
int i=1;
int *p=alloc(round(m/7)*sizeof(int)*2);
if(p==NULL) {perror(''Out of memory."); return -1;}
int count=0;
bool stop=false;
while(stop==false)
{
if((i+1)*7>=m&&i*11>m) stop=true;
else
{
p[count++]=i*7;
p[count++]=(i++)*11;
}
}
printf("We found [%d] numbers which can be divided by 7 or 11, they are.\n[", count);
for(i=0;i<count;i++)
{
printf("%d ", p[i]);
}
printf("]\n");
}
{
int i=1;
int *p=alloc(round(m/7)*sizeof(int)*2);
if(p==NULL) {perror(''Out of memory."); return -1;}
int count=0;
bool stop=false;
while(stop==false)
{
if((i+1)*7>=m&&i*11>m) stop=true;
else
{
p[count++]=i*7;
p[count++]=(i++)*11;
}
}
printf("We found [%d] numbers which can be divided by 7 or 11, they are.\n[", count);
for(i=0;i<count;i++)
{
printf("%d ", p[i]);
}
printf("]\n");
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
又是要考试了吧?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询