1) Write a program that takes in 2 integers from the user, and computes their gcd (greatest
common divisor).
The gcd of two integers is the largest integer that divides both numbers. For instance,
the gcd of 15 and 25 is 5.
Implement the followng method to compute the gcd. Let the two numbers be x, y. Take the
larger of the two numbers (let that be x), and divide x by the smaller number (y).
Let there be a remainder of z. Now you divide y by z, compute the remainder and so on.
Keep doing this until you get a remainder of 0. The smaller number when we get the
remainder of 0 is the gcd.
For example, let us find the gcd of 735 and 252.
You divide 735 by 252. You get a remainder of 231.
Now you divide 252 by 231. You get a remainder of 21.
Now you divide 231 by 21. You get a remainder of 0.
Therefore the gcd is 21.
2) Write a simple arithmetic expression translator that reads in expressions such as
25.5 + 34.2, and displays their value. Each expression consists of a number (type: float)
followed by a space followed by an operator (type: char) followed by
another number
(type: float)
. The operator you support must include + - * / You must keep evaluating
the expressions until the user enters an expression such as 0 + 0
3)
Drivers are concerned with the mileage obtained by their cars. One driver has kept track
of several tankful of gasoline by recording miles driven and gallons used for each tankful.
Develop a c++ program that uses a while statement to input the miles driven and gallons
used for each tankful. The program should calculate and display the miles per gallon
obtained for each tankful and print the combined miles per gallon obtained for all tankfuls up
to that point. If the mileage is -1, the program quits.
4) Input an integer containing only 0s and 1s (i.e. binary integer) and prints its decimal
equivalent. Use the modulus and division operators to pick off the binary digits as before.
You only need to handle a fixed-length, 5-digit binary integer for this question. Assume that the
user will always enter a 5-digit integer.
5) The process of finding the largest and smallest numbers is used frequently in computer applications. Write a C++ program that uses a while statement to determine and print the
largest and the second largest number of x integers entered by the user, where x should
also be input by the user.
Data set Largest1 Largest2
======== ======== ========
9,9 9 9
9,9,7 9 9
9,9,9,9,9,7,8 9 9
1,1,1,1,8,6 8 6
(求高手帮帮忙,谢谢)
谁可以帮我做一下这个C++C语言的作业
因为我对C语言的输入输出不太熟悉,对输入输出的错误不予判断!我按C++的方式给予判断。一、 基础题(15%)1.定义int n=5,a=12;写出a*=(n%=3);执行后变量n与a的值。【答案】n%=3 取余结果n=2 执行后:n=2;a=24 2.设a=b=5;分别判断表达式的真假:6>a>2与++b==6。【答案】...
关于C++的六个问题,,想请高手帮我看看 加分..
你的第一个问题没看懂。如果想要了解数组,那么应该去看内存。你给个你看不懂的例子,我帮你看看吧。2.C++最难的,最核心的,最重要的是继承和虚函数。而C++比C好用的地方是STL。3.你先了解下new吧,其他的几个你在使用过程中会慢慢体会出来的。4.区分还是要看内存... ...5.隐式类型转换,...
C语言编程的几道题?我是初学者,谁帮我把步骤写下~
int main(){ printf("***\\n");printf("* LANGUAGE *\\n");printf("* BEGINE *\\n");printf("***\\n");return 0;} 第二题 include "stdafx.h"include "stdio.h"define P 3.14 \/\/用宏定义圆周率的值 int main(){ float r=1.5,h=3,s,v;s=P*r*r; \/\/圆的...
谁帮我做下C++语言的选择题 谢谢了
1. 可以在类的构造函数中对静态数据成员进行初始化。错误。2. 友元关系可以继承。错误。3. 析构函数是在对象的生存期即将结束的时刻被自动调用的。错误。4. 使用关键字class定义的类中默认的访问权限是私有的。正确。5. delete用来删除由new建立的对象,释放指针所指向的内存空间。正确。6. ...
用C++做的黑色星期五,谁来帮我看看哪错了啊??NOCOW上就是不过!_百度知 ...
黑色星期五:#include <stdio.h>void main(), b[13]=,i,j,k,m,n,p,q,c[13]=; for(i=1990;i<2000;i++) else if(j<=5) p=1+5-j; else p=7-j+5+1; for(;p<=k;p+=7) } }} 如果帮助到您,请记得采纳为满意答案哈,谢谢!祝您生活愉快! vae.la ...
关于C++的一道编程题,请高手帮忙阿
百度网友1d6c0ad66 2006-03-21 知道答主 回答量:18 采纳率:0% 帮助的人:5.1万 我也去答题访问个人页 关注 展开全部 不要老是高手高手的,真正的高手才不愿意来帮你这种小问题,问问题可以随便问,至于谁来回答你就不要做这个主了,会的愿意的当然会回答你了,不会的,就算是高手也不会回答你 ...
谁能解决一道C++编程题
谁能帮我用c++语言帮我做一个通讯录系统啊,要求是必须用文件的输入输出做,每条记录里包括学生的姓名,编号和电话号码... 谁能帮我用c++语言帮我做一个通讯录系统啊,要求是必须用文件的输入输出做,每条记录里包括学生的姓名,编号和电话号码 展开 我来答 ...
求一个整数任意次方的最后三位数.用C++来编的,有谁能帮帮我?
每次都如此,就不会出现溢出,因为千位以上对最后三位没影响,程序如下 int lastthr(int num,int n) \/\/num的n次方 { int thr,tmp;tmp=num%1000; \/\/对1000取余,得最后三位 thr=tmp;while(--n){ thr*=tmp;thr%=1000;} return thr;} 对于num,n均为正情况,以上程序在Dev-C++通过。
求一个整数任意次方的最后三位数.用C++来编的,有谁能帮帮我?谢谢!
include<iostream> using namespace std;void main(){ const int N=10; \/\/N次方 int i=0;int num=25; \/\/整数num int sum=1;for(i=0;i<N;i++){ sum*=num;} printf("%d\\n",sum%1000); \/\/输出最后三位数 }
c++谁来帮我注释一下这段程序,看不懂
{ public:static int number;\/\/静态变量 声明 静态变量属于类不属于对象 point(){number++;}\/\/构造函数 ~point(){number--;}\/\/析构函数 };int point::number=0;\/\/静态变量类外初始化 void main(){ point *ptr;\/\/定义一个指向point的指针 point a,b;\/\/定义 对象 { point *ptr_...