永发信息网

急!请C++高手帮忙编程。100分送上。

答案:6  悬赏:10  手机版
解决时间 2021-11-11 16:45
急!请C++高手帮忙编程。100分送上。
最佳答案
全部VC6.0下运行通过的
一(1)
// zd_42.cpp : Defines the entry point for the console application.
//

#include
#include

int count(int a[],int n);

int main(int argc, char* argv[])
{
int n;
int b[]={15,16,-23,7,-5,19,-2,0,28,11};
n=count(b,10);
printf("大于0的数有 %d 个\n",n);
return 0;
}

int count(int a[],int n)
{
int sum=0;
for(int i=0;i if(a[i]>0)
sum++;
return sum;
}

运行结果:
大于0的数有 6 个
Press any key to continue
(2)
// zd_43.cpp : Defines the entry point for the console application.
//

#include

int hcf(int u,int v)
{
int t,r;
if(v>u)
{t=u;u=v;v=t;}
while((r=u%v)!=0)
{
u=v;
v=r;
}
return v;
}

int lcd(int u,int v,int h)
{
return u*v/h;
}

int main(int argc, char* argv[])
{
int u,v,h,l;
printf("输入两个整数:u,v\n");
scanf("%d,%d",&u,&v);
h=hcf(u,v);
printf("H.C.F=%d\n",h);
l=lcd(u,v,h);
printf("L.C.D=%d\n",l);
return 0;
}

运行结果:
输入两个整数:u,v
4,6
H.C.F=2
L.C.D=12
Press any key to continue
(3)
// zd_44.cpp : Defines the entry point for the console application.
//

#include
#include

float x1,x2,disc,p,q;

greater_than_zero(float a,float b)
{
x1=(-b+sqrt(disc))/(2*a);
x2=(-b-sqrt(disc))/(2*a);
}

equal_to_zero(float a,float b)
{
x1=x2=(-b)/(2*a);
}

smaller_than_zero(float a,float b)
{
p=-b/(2*a);
q=sqrt(abs(disc))/(2*a);
}

int main(int argc, char* argv[])
{
float a,b,c;
printf("Input a,b,c:");
scanf("%f,%f,%f",&a,&b,&c);
printf("\nequation:%5.2f*x*x+%5.2f*x+%5.2f=0\n",a,b,c);
disc=b*b-4*a*c;
printf("root:\n");
if(disc>0)
{
greater_than_zero(a,b);
printf("x1=%5.2f\tx2=%5.2f\n\n",x1,x2);
}
else if(disc==0)
{
equal_to_zero(a,b);
printf("x1=%5.2f\tx2=%5.2f\n\n",x1,x2);
}
else
{
smaller_than_zero(a,b);
printf("x1=%5.2f+%5.2fi\tx2=%5.2f-%f5.2i\n",p,q,p,q);
}
printf("Hello World!\n");
return 0;
}

运行结果:
Input a,b,c:7,4,3

equation: 7.00*x*x+ 4.00*x+ 3.00=0
root:
x1=-0.29+ 0.59i x2=-0.29-0.5890155.2i
Hello World!
Press any key to continue
(4)
// zd_45.cpp : Defines the entry point for the console application.
//

#include

int main(int argc, char* argv[])
{
int prime(int);
int n;
printf("\ninput an integer:");
scanf("%d",&n);
if(prime(n))
printf("\n%d is a prime.",n);
else
printf("\n %d is not a prime.",n);
return 0;
}

int prime(int n)
{
int flag=1,i;
for(i =2;i if(n%i==0)
flag=0;
return flag;
}

运行结果:

input an integer:96

96 is not a prime.Press any key to continue

(1)

// zd_46.cpp : Defines the entry point for the console application.
//

#include

void swap(int &a,int &b)
{
int t;
t=a;
a=b;
b=t;
}

int main(int argc, char* argv[])
{
int a,b;
printf("input a,b:\n");
scanf("%d,%d",&a,&b);
printf("before swap\n");
printf("a=%d\tb=%d\n",a,b);
swap(a,b);
printf("after swap\n");
printf("a=%d\tb=%d\n",a,b);
return 0;
}

运行结果:
input a,b:
7,4
before swap
a=7 b=4
after swap
a=4 b=7
Press any key to continue

(2)
// zd_47.cpp : Defines the entry point for the console application.
//

#include

void swap(char **a,char **b)
{
char *temp;
temp=*a;
*a=*b;
*b=temp;
}

int main(int argc, char* argv[])
{
char *p1="hello";
char *p2="good";
printf("before swap\n");
printf("p1=%s\tp2=%s\n",p1,p2);
swap(&p1,&p2);
printf("after swap\n");
printf("p1=%s\tp2=%s\n",p1,p2);
return 0;
}

运行结果:
before swap
p1=hello p2=good
after swap
p1=good p2=hello
Press any key to continue
全部回答


#include "iostream.h"

int z=0;//零的个数

int count(int a[],int n)
{
int dl=0; //大于0的个数
int i;
for(i=0;i {
if(a[i]>0)
dl++;
else if(a[i]==0)
z++;
}
return dl;
}

void main()
{

int n,x;
int b[]={15,16,-23,7,-5,19,-2,0,28,11};
n=10;
x=n-count(b,n);
x=x-z;
cout<<"less than zero number="<}



#include "iostream.h"

int gys,gbs;

int gy(int a,int b)
{
int r;
r=a%b;
if(r!=0)
{
a=b;
b=r;
r=a%b;
}
return b;
}

int gb(int a,int b)
{
int r;
r=a*b/gys;
return r;
}

int main()
{
int a,b,t;
cout<<"Input a"< cin>>a;
cout<<"Input b"< cin>>b;

if(a==0 || b==0)
{
cout<<"Input Error"< return 0;
}

if(a {
t=a;a=b;b=t;
}
gys=gy(a,b);
gbs=gb(a,b);

cout<<"gys="< cout<<"gbs="<
}



#include "iostream.h"
#include

void dy(double a,double b,double c,double derta)
{
double d;
double x1,x2;
if(a==0)
{
x1=-c/b;
x2=-c/b;
}
else
{
d=pow(derta,0.5);
x1=(-b+d)/2/a;
x2=(-b-d)/2/a;
}
cout<<"x1="< cout<<"x2="<}

void deng(double a,double b,double c, double derta)
{
dy(a,b,c,derta);
}

void xiao(void)
{
cout<<"no answer!"<}

int main()
{
double a,b,c;
double derta;
cout<<"Input a"< cin>>a;
cout<<"Input b"< cin>>b;
cout<<"Input c"< cin>>c;

derta=b*b-4*a*c;
if( derta>0)
{
dy(a,b,c,derta);
}
else if(derta==0)
{
deng(a,b,c,derta);
}
else // derta<0
{
xiao();
}

}



#include "iostream.h"
#include

int compare(int n)
{
int b=1;
int i;
if(n==2 || n==1)
{
}
else
{
for(i=2;i<=n;i++)
{
if(n%i==0)
{
b=0;
break;
}
}
}

return b;
}

int main()
{
int n;
cout<<"Input n"< cin>>n;
if(compare(n)==1)
{
cout<<"this number is prime number!"< }
else
{
cout<<"this number is not prime number!"< }
}



#include "iostream.h"
void change(int &a,int &b)
{
int t;
t=a;
a=b;
b=t;
}

void main()
{
int a=10;
int b=20;
change(a,b);
cout<<"a="<}



#include "iostream.h"
#include "stdio.h"
#include "string.h"

void change(char *&p1,char *&p2)
{
char *t1;
t1=p1;
p1=p2;
p2=t1;
}

void main()
{
char *p1="hello";
char *p2="good";
change(p1,p2);
cout<<"p1="<}

参考资料:用了一下午编出来了。下班前正好弄出来。编译在VC6下通过。

1
(1)题:
#include
int Count(int a[],int n){
int count=0;
for(int i=0;i0)count++;
return count;
}
int main(){
int b[10]={15,16,-23,7,-5,19,-2,0,28,11};
std::cout<<"输出数组中大于0的个数:"< system("pause");
return 0;
}

这是用Dev-C++编的.

(2)
#include
int Gongyue(int a,int b){
while(a!=b){
if(a>b)a-=b;
else b-=a;
return b;
}

int Gongbei(int a,int b){
return a>b?(b/Gongyue(a,b)*a):(a/Gongyue(a,b)*b);
}

int main(){
int a,b;
std::cout<<"请输入两个数:"< std::cin>>a;
std::cin>>b;
std::cout<<"最大公约数为:"< std::cout<<"最小公倍数为:"< system("pause");
return 0;
}
你给上1000分,我可能会帮你解决掉问题
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
全国最大的打火机撒件生产基地在哪多少钱一套
一个月用电1000度正常吗
某农场为了鼓励小学生集体到农场去劳动,承诺
带舒字的词语
古典舞蹈给节目取个名字,
有两个线性无关的解,不应该等于2吗,为什么
java中quartz定时任务的执行如何避免并发
我33岁的大叔了,你们觉得我看着老吗?
161身高 58公斤的体重 算是微胖吗
kate与cup中的k与c的发音是否相同
手机怎么添加wifi网络
37.56除0.24的竖式
石门山墓园地址在哪,我要去那里办事,
求杨丞琳歌曲《左边》,《匿名的好友》,酷狗
is sound great是什么意思
推荐资讯
全球一年发电量是多少?
银行秋招招聘买什么书比较好啊 买东吴版本的
请说像张骞一样的人
C6H12的二氯代物有几种?它们的结构简式分别
DNF +12的增幅卷可以直接用到 非红字的装备上
显卡矿难还要多久,唉现在显卡贵得要屎,都怪
2X-3=X十3这个方程怎么解
适马100400镜头多长
我从家里到学校要什么过三条马路
开心读短文。  一棵树长得很茂(mào)盛(
建筑工程的土方合同如何签订?
夫妻共同财产要转移需要哪些手续?
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?