急!请C++高手帮忙编程。100分送上。
答案:6 悬赏:10 手机版
解决时间 2021-11-11 16:45
- 提问者网友:鼻尖触碰
- 2021-11-10 22:18
急!请C++高手帮忙编程。100分送上。
最佳答案
- 五星知识达人网友:妄饮晩冬酒
- 2021-11-10 22:38
全部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
一(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
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
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
全部回答
- 1楼网友:举杯邀酒敬孤独
- 2021-11-11 00:30
#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"<
cout<<"Input b"<
if(a==0 || b==0)
{
cout<<"Input Error"<
}
if(a {
t=a;a=b;b=t;
}
gys=gy(a,b);
gbs=gb(a,b);
cout<<"gys="<
}
#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="<
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"<
cout<<"Input b"<
cout<<"Input 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"<
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下通过。
- 2楼网友:千夜
- 2021-11-11 00:00
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;
}
(1)题:
#include
int Count(int a[],int n){
int count=0;
for(int i=0;i
return count;
}
int main(){
int b[10]={15,16,-23,7,-5,19,-2,0,28,11};
std::cout<<"输出数组中大于0的个数:"<
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>>b;
std::cout<<"最大公约数为:"<
return 0;
}
- 3楼网友:动情书生
- 2021-11-10 23:52
你给上1000分,我可能会帮你解决掉问题
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯