| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 616 人关注过本帖
标题:麻烦哪位大师帮我做一下这三个题目吧、、、、、我是新手
只看楼主 加入收藏
lurrass
Rank: 1
等 级:新手上路
帖 子:17
专家分:1
注 册:2010-9-13
结帖率:42.86%
收藏
已结贴  问题点数:20 回复次数:3 
麻烦哪位大师帮我做一下这三个题目吧、、、、、我是新手
1)编程实现求解一元二次方程 ax^2+bx+c=0,作为一个健壮的程序,应根据方程系数的不同取值判断方程根的情况。如:
当a=0 且b=0 且c≠0 时,方程无根;

当a=0 且b≠0 时,方程有一个根;

当a≠0 且b≠0 时,根据 delta=b^2-4ac 判断方程根:

delta>0,有两个不同实根;

delta=0,有两个相同实根;

delta<0,有两个不同复根。

根据以上分析,编写源程序,要求输出方程的根。


2)编写程序打印出所有的水仙花数。所谓水仙花数是指一个三位数,其各位数字的立方和等于该数本身。例如:153=1^3+5^3+3^3,所以153是一个水仙花数。


3)编写一个交换两个整数次序的函数,如输入a=1和b=2后,输出结果为a=2和b=1 。提示可考虑swap(int *,int*)。

搜索更多相关主题的帖子: 大师 麻烦 
2010-09-13 22:10
windyfzz
Rank: 2
等 级:禁止访问
帖 子:90
专家分:12
注 册:2010-7-25
收藏
得分:7 
1.
#include <iostream>
using namespace std;
#include <cmath>
#include <stdlib.h>

int main()
{
  int a,b,c;
  cout<<"请输入方程的系数:";
  cin>>a>>b>>c;
  if (b*b-4*a*c < 0)
  {
     cout<<"该方程无解!"<<endl;
  }
  else
  {
    cout<<"x1 ="<<(-b+sqrt(b*b-4*a*c))/2*a<<endl;
    cout<<"x2 ="<<(-b-sqrt(b*b-4*a*c))/2*a<<endl;
  }
  system("PAUSE");
  return 0;
}

2.

#include <iostream>
using namespace std;
#include <cmath>
#include <stdlib.h>

int main()
{
  int a,b,c,i;
  for (i=100;i<=999;i++)
  {
    a=i/100;
    b=(i-100*a)/10;
    c=i-100*a-10*b;
    if (i == a*a*a+b*b*b+c*c*c)
     {
        
        cout<<i<<'\t';
        
     }
  }

system("PAUSE");
return 0;
}

3

#include <iostream>
using namespace std;
#include <cmath>
#include <stdlib.h>
int main()
{
  void swap(int *p1,int *p2);
  int a,b;
  int *p1,*p2;
  cin>>a>>b;
  p1=&a;
  p2=&b;
  swap(p1,p2);
  system("PAUSE");
  return 0;
}

void swap(int *p1,int *p2)
{
    int c;
    c=*p1;
    *p1=*p2;
    *p2=c;
    cout<<"排序后: "<<*p1<<'\t'<<*p2<<endl;
}
  
  
   

  

   
   

  
2010-09-13 22:47
x_wangyue
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:34
专家分:144
注 册:2010-8-30
收藏
得分:7 
1。//1。一元二次方程求解
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
    double a,b,c;
    double x1,x2;
    cout<<"please input the a,b,c:"<<endl;
    cin>>a>>b>>c;
    if(a==0&&b==0)
        cout<<"该方程没有解!"<<endl;
    else if(a==0&&b!=0)
    {
        cout<<"x="<<-c/b<<endl;
    }
   
    else
    {
        long double delta=b*b-4.0*a*c;
        if(delta>0)
        {
            cout<<"该方程有两个实数根:"<<endl;
            x1=(-b)/(2.0*a)+sqrt(delta)/(2.0*a);
            x2=(-b)/(2.0*a)-sqrt(delta)/(2.0*a);
            cout<<"x1= "<<x1<<endl;
            cout<<"x2= "<<x2<<endl;         
       }
       else if(delta==0)
       {
           cout<<"该方程有两个相等的根:"<<endl;
           x1=x2=-(2.0*a/b);
           cout<<"x1=x2="<<x1<<endl;
       }
       else
       {
           cout<<"该方程有两个虚根:"<<endl;
         
           cout<<"x1="<<(-b)/(2*a)<<+sqrt(delta)/(2*a)<<"i"<<endl;//这里有点问题
           cout<<"x2="<<(-b)/(2*a)<<-sqrt(delta)/(2*a)<<"i"<<endl;
           cout<<sqrt(delta)/(2.0*a);
       }

        
    }
    return 0;
}
第二题:
#include <iostream>

using namespace std;

int main()
{
    int a,b,c,n,s;
    for(n=100;n<1000;n++)
    {
        a=n/100;
        b=(n%100)/10;
        c=n%10;
        s=a*a*a+b*b*b+c*c*c;
        if(n==s)
            cout<<n<<" ";   
        
    }
    return 0;
}
第三题:
#include <iostream>

using namespace std;

int main()
{
    void exchange(int*,int*);
    int a,b;

    cout<<"please input a and b:"<<endl;
    cin>>a>>b;
    int *p1=&a,*p2=&b;
    cout<<a<<b<<endl;

    exchange(p1,p2);
    cout<<a<<b<<endl;
    return 0;
   
}
void exchange(int *p1,int *p2)
{
    int temp;
    temp=*p1;
    *p1=*p2;
    *p2=temp;
}
第一题有点问题,还请高手指教
2010-09-14 00:22
lurrass
Rank: 1
等 级:新手上路
帖 子:17
专家分:1
注 册:2010-9-13
收藏
得分:0 
thank you
2010-09-14 12:04
快速回复:麻烦哪位大师帮我做一下这三个题目吧、、、、、我是新手
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011304 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved