C/C++考题收集大全
简单的也好,难的也好,老掉牙也好,创新的也好,觉得有意思的就收集起来。
1、输入一个整数.如552.计算其各位的和,直到结果为一位数. 比如552过程为 552-->12-->3
intf(inti)
{
intsum;
while(i>9)
{
sum=0;
while(i>0)
{
sum+=i%10;
i/=10;
}
i=sum;
}
returni;
}
{
intsum;
while(i>9)
{
sum=0;
while(i>0)
{
sum+=i%10;
i/=10;
}
i=sum;
}
returni;
}
2、写一个swap()函数,传入两个整型参数a和b,交换它们的值。不得使用辅助空间,即不得在swap()函数内定义其它变量。或者题目改成:用宏定义写出来。















3、已知一个已经从小到大排序的数组,这个数组中的一个平台(Plateau)就连续的一串值相同的元素,并且这一串元素不能再延伸。例如:1,2,2,3,3,3,4,5,5,6中,最长的平台就是3。试编写一个程序,接收一个数组,把这个数组的最长平台找出来。













4、
本文地址:http://www.45fan.com/a/question/71567.html