急急急急。。C语言或者C++高手进!下面三道程序编程,做出来的话可以额外加分!急用,要速度。。

1、 add

[问题描述]

从键盘输入两个正整数,在屏幕上输出这两个数的和, 当输入两个的数字都 为 0 时,结束程序。

[样例输入]

1 1
1 2
2 3
25 25
0 0

[样例输出]

2
3
5
50

2、dec2hex

[问题描述]

从键盘输入一个10进制数,在屏幕上输出这个数的16进制形式, 当输入的数 字为-1时,结束程序。

[样例输入]

8 10 12 90 -1

[样例输出]

8
a
c
5a

3、count

[问题描述]

从键盘输入最多100个整数,统计出其中的负数个数, 当输入的数字为 0 时 结束程序。

[样例输入]

1 -1 -2 2 -3 3 4 -4 -5 5 6 0

[样例输出]

5

1:
#include<stdio.h>
int main()
{
int a;
int ar[100];
int b;
int br[100];
int i=0;
while(1)
{
scanf("%d",&a);
scanf("%d",&b);
if(a==0 && b==0)
{
break;
}
else
{
ar[i]=a;
br[i]=b;
i++;
}
}
int j;
for(j=0;j<i;j++)
{
printf("%d\n",ar[j]+br[j]);
}
getchar();
return 0;
}
2:
#include<stdio.h>
int main()
{
int a;
int ar[100];
int i=0;
while(1)
{
scanf("%d",&a);
if(a==-1)
{
break;
}
else
{
ar[i]=a;
i++;
}
}
int j;
for(j=0;j<i;j++)
{
printf("%x\n",ar[j]);
}
getchar();
return 0;
}
3:
#include<stdio.h>
int main()
{
int a;
int count=0;
while(1)
{
scanf("%d",&a);
if(a==0)
{
break;
}
else
{
if(a<0)
{
count++;
}
}
}
printf("%d",count);
getchar();
return 0;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-07-04
1、

#include <stdio.h>

void main()
{
int a, b;

while (scanf("%d %d", &a, &b) && (a != 0 || b != 0))
printf("%d\n", a + b);
}

2、

#include <stdio.h>

void main()
{
int a;

while (scanf("%d", &a) && a != -1)
printf("%x\n", a);
}

3、

#include <stdio.h>

void main()
{
int a;
int sum = 0;

while (scanf("%d", &a) && a != 0)
if (a < 0) sum++;
printf("%d\n", sum);
}
第2个回答  2011-07-04
1.
#include"stdio.h"

void main()
{
int a,b;
scanf("%d %d",&a,&b);
while(!(!a&&!b))
{
printf("%d\n",a+b);
scanf("%d %d",&a,&b);
}
}

2.
#include"stdio.h"

void fun(int a,char b[])
{
int i,j;
char temp,t[17]="#123456789ABCDEF";
i=0;
while(a)
{
b[i++]=t[a%16];
a/=16;
}
b[i]='\0';
for(j=0;j<i/2;j++)
{
temp=b[j];
b[j]=b[i-j-1];
b[i-j-1]=temp;
}
}

void main()
{
int a[100];
char b[20];
int i,j;
for(i=0;;i++)
{
scanf("%d",&a[i]);
if(a[i]==-1)break;
}
for(j=0;j<i;j++)
{
fun(a[j],b);
printf("%s\n",b);
}
}
3.
#include"stdio.h"

void main()
{
int a[100],n;
int i,count;
for(i=count=0;;i++)
{
scanf("%d",&a[i]);
if(a[i]<0)count++;
else if(a[i]==0)break;
}
printf("%d\n",count);
}
第3个回答  2011-07-04
#include<iostream>
using namespace std;
void main()
{
int x,y;
cout<<"从键盘输入两个正整数,当输入两个的数字都 为 0 时,结束程序"<<endl;
while(x!=0 && y!=0)
{
cin>>x>>y;
cout<<(x+y)<<endl;

}
}
输入1 1 1 2 2 3 25 25
输出2 3 5 50

下面这个程序是一个进制转换的 你删两个就可以了
#include<iostream>
using namespace std;
const int MaxSize=10;
typedef int DataType;
class SeqStack {
public:
SeqStack(void);
~SeqStack();
void ClearStack(void);
void Push(const DataType& x);
DataType Pop(void);
DataType GetTop(void);
bool IsFull(void);
bool IsEmpty(void);
private:
int top;
DataType s[MaxSize];
};

SeqStack::SeqStack(void){
top=-1;
}
SeqStack::~SeqStack(void){
}
void SeqStack::Push(const DataType& x) {
if (top==MaxSize-1){
cout<<"堆栈已满,不能压栈!!!"<<endl;
exit(0);
}
top++;
s[top]=x;
}

DataType SeqStack::Pop(void){
DataType temp;
if (top==-1){
cout<<"堆栈已空,不能出栈!!!"<<endl;
exit(0) ;
}
temp=s[top];
top--;
return temp;
}

DataType SeqStack::GetTop(void){
DataType temp;
if (top==-1){
cout<<"堆栈已空!!!"<<endl;
exit(0);
}
temp=s[top];
return temp;
}
bool SeqStack::IsEmpty(void){
return (top==-1?true:false);
}

bool SeqStack::IsFull(void) {
return (top==MaxSize-1?true:false);
}
void SeqStack::ClearStack(void){
top=-1;
}
void conversion(const int n, const int m)
{
SeqStack stack;
DataType temp1;
int a,b,count=0;
char temp2;

b=n;
if(m==10)
{
cout<<n<<"转换成"<<m<<"进制的数为"<<n;
cout<<endl;
}

else if(m==2||m==8||m==16)
{
cout<<n<<"转换成"<<m<<"进制的数为";
if(b==0)
cout<<b;
if(b<0)
{
b=-b;
cout<<"-";
}
while(b>0)
{
a=b%m;
b=b/m;
stack.Push(a),count++;
}
for(int i=0;i<count;i++)
{
temp1=stack.Pop();
if( temp1>9 )
{
temp2=temp1+55;
cout<<temp2;
}
else
cout<<temp1;
}
cout<<endl;
}
else
{
cout<<n<<"不能转换,";
cout<<"转换的进制必须为2,8,16"<<endl;
}
}
int main()
{
SeqStack aa;int i,choice,q=1;

printf("\n ****************************************\n");
printf("\n ******** 093软件工程 *********\n");
printf("\n ******** 左自强 *********\n");
printf("\n ******** 09033335 *********\n");
printf("\n ******** 数据结构数值转换问题 *********\n");
printf("\n ****************************************\n");
printf("\n ------------ 3: 十六进制转换 -----------\n");
printf("\n ------------ 4: 退出 ---------\n");
printf("\n ****************************************\n");
while(q){
cout<<"请选择:";
cin>>choice;
switch(choice )
{

case 3:
cout<<"请输入任意数:"<<endl;
cin>>i;
if(i!=-1){aa.Push(i);
conversion(aa.GetTop(), 16);
aa.ClearStack();
break;return 1;}
else{break; return 0;}
case 4: return 0;
break;
default:;
}
}
return 0;
}

#include<iostream>
#define LIN 100
using namespace std;
void main()
{

int x;
int count=0;
cout<<"从键盘输入小于100的个整数,当输入 为 0 时,结束程序"<<endl;
while(x!=0)
{
cin>>x;
if(x<0)
count++;
}
cout<<count<<endl;
}
第4个回答  2011-07-04
这么简单。。。留下邮箱,我拍下我写的东西,发给你吧~手机打代码不方便
相似回答