- 博客(125)
- 收藏
- 关注
转载 c语言尾递归示例
尾递归函数定义: 1.一个函数中所有递归形式的调用都出现在函数的; 2.当递归调用是整个函数体中最后执行的语句且它的返回值不属于表达式的一部分; 尾递归函数优点: 1.占用内存空间少,运行效率更高。运行结果:1 + 1/2 + 1/3 + 1/4 + 1/5 = 2.28Program ended with exit code: 0main.c#include <stdio.h>doubl
2015-10-13 22:59:24
622
转载 C语言void泛型指针
x = 7, y = 10a = 1.33, b = 2.55x = 10, y = 7a = 2.55, b = 1.331 2 3 4 9 10 11 12 Program ended with exit code: 0main.c#include <stdio.h>#include <stdlib.h> // malloc#include <string.h> // memcp
2015-10-13 19:49:18
799
原创 C++ How to program 9E<10.9 hugeInt Class 函数运算符重载>
运行结果:a = 9000a + 100 = 9100a + 834 = 9834100 + a = 9100bye = 9000Overflow, Product is over than 4-digits.main.cpp#include <iostream>#include <stdexcept>#include "Huge.hpp"#include <string>int m
2015-10-09 16:21:01
1760
原创 Introduction to Java Programming编程题12.11<Remove text>
运行结果:brown:javacode br$ javac Where.javabrown:javacode br$ java Where miyu.txt xiyu.txt [(粉丝群)]-bash: syntax error near unexpected token `(' brown:javacode br$ java Where miyu.txt xiyu.txt 粉丝群brow
2015-09-29 13:32:44
583
原创 Introduction to Java Programming编程题12.3<ArrayIndexOutBoundsException>
运行结果:Enter the array's index less than 100: -5 q 111 9Out of bounds.Enter the array's index less than 100: qqIndex must be digital.Enter the array's index less than 100: 5Index 5: 144ArrayIndexOut
2015-09-28 19:58:09
686
原创 Introduction to Java Programming编程题12.2<InputMismatchException>
运行结果:Enter two digital number: tr ru hdInvalid digital number.Enter two digital number: 45 qaInvalid digital number.Enter two digital number: 12 1112 + 11 = 23InputException.javaimport java.util.I
2015-09-28 19:14:32
615
原创 Introduction to Java Programming编程题12.1<NumberFormatException>
运行结果:br:javacode br$ javac NumberFormatException.javabr:javacode br$ java NumberFormatException 45 34Please use java NumberFormatException operand1 operator operand2java NumberFormatException 45x +
2015-09-28 17:29:05
681
原创 Introduction to Java Programming编程题11.1<The triangle class>
运行结果:Triangle: side1 = 1.0 side2 = 1.0 side3 = 1.0color: greenfilled: falseTriangle: side1 = 1.0 side2 = 1.5 side3 = 1.0color: yellowfilled: trueGeometricObject.javapackage Uber;public class Geom
2015-09-26 12:57:26
915
原创 Introduction to Java Programming编程题8.37<Guess the capitals>
运行结果:What is the capital of Alabama? MontogomeryThe correct answer should be Montgomery.What is the capital of Alaska? JuneauYour answer is correct.What is the capital of Arizona? PhoEnixThe corre
2015-09-24 12:08:33
780
原创 Introduction to Java Programming编程题8.36<Latin square>
运行结果:Enter number n: 4Enter 4 rows of letters separated by spaces:A B C DB A D CC D B AD C A BThe input array is a Latin square.Enter number n: 3Enter 3 rows of letters separated by spaces:A F
2015-09-24 11:19:21
575
原创 c++ <输入数字n打印n行n列的矩形>
运行结果: Enter the number between 1 and 20: 5 ***** * * * * * * *****main.cpp#include <iostream>using namespace std;int main() { unsigned int row; cout << "Enter the number between 1 and
2015-09-22 18:22:51
4816
原创 C++ <ADT:单链表追加、选择排序、删除>
input.txtDoe John 555555555 333-333-3333 65000 Doe Jan 444444444 333-333-3333
2015-09-20 14:24:31
366
原创 C++ <类C:单链表的插入、查找、删除>
运行结果: Rolls 10 Jam 3 Tea 2 Enter you want to insert after the item: Tea Enter the insert item: Lisa Enter the insert count: 33 Rolls 10 Jam 3 Tea 2 Lisa 33 Do you want to continue <y/n
2015-09-17 22:19:44
613
原创 C++ <二分查找法>
注:二分查找法有个问题,一组数字中有多个一样的数值时,其返回的下标位置不一样是数组中第一次出现的线标位置。 运行结果: Enter digit numbers less than 10: -5 5 -5 33 -10 4 1 33 5 After sort: -10 -5 -5 1 4 5 5 33 33 Enter you want to find number: -5 Found it
2015-09-16 14:37:42
384
原创 C++ <递归求一个数的N次方(仅限一个数的正数次方)>
注:如果要计算double类型的数据,只需将int改为double即可,如果只是计算整数值的N次方不建议用double类型, 因为double类型只能存储一个数的近似值,所以计算的结果部分时候会有误差。运行结果:Enter a number to the power of another such as (x n): 2 0The number 2 power of 0 is:
2015-09-14 16:53:12
4059
原创 C++ <利用指针翻转字符串>
运行结果:Enter a string: The new operator takes a type for its argument..tnemugra sti rof epyt a sekat rotarepo wen ehTreverseString.cpp#include <iostream>#include <string>using namespace std;void revers
2015-09-12 13:56:40
771
原创 C++ <文本文件的加密与解密>
未加密文本.txtalmost loverYour fingertips against my skin The palm trees swaying in the wind in my chase You sang me Spanish lullabies The sweetest sadness in your eyes Clever trickI never wanna see you
2015-09-12 00:37:54
3681
原创 C++ <替换字符串中的数字>
运行结果: Enter a string: My userID is john17 and my 4 digit pin is 1234 which is secret. My userID is john17 and my x digit pin is xxxx which is secret.replaceDigits.cpp#include <iostream>#include <stri
2015-09-11 14:34:20
1369
原创 C++ <统计单词数及单个字母出现次数>
运行结果: Enter a string: For example, the input 4 words 1 a 3 e 1 f 1 h 1 i 1 l 1 m 1 n 1 o 2 p 1 r 2 t 1 u 1 xcountWords.cpp#include <iostream>#include <string>#include <cstring>using na
2015-09-11 14:15:53
1929
原创 C++ <读入字符串并过滤掉不合格的字符>
程序说明:读入一个字符串,当字符串以.结尾且后面无任何数据时,停止读入。 读入后的字符串第一个字母必须是大写,且其余字母均为小写并过滤掉字符之间多余的空格。 运行结果: Enter a string: the Answer to life, the Universe, and everything IS 42. The answer to life, the universe, an
2015-09-11 00:18:19
2384
转载 C++ <getline及atoi>
#include <iostream>#include <string> // 用于C++ string类的操作#include <cctype> // 用于C字符串的拷贝、比较、追加 等,strcpy(), strcmp(), strcat()#include <cstdlib> // 用于exit(EXIT_FAILURE)及atoi即:alpha to interge 的缩写int m
2015-09-10 00:35:17
304
转载 C++ <使用函数运算符重载执行类对象加法>
运行结果: Enter the first money (dollars): 12.123 Invalid dollars and cents, negative values Enter the first money (dollars): 33.99 Enter the second money (dollars): 35.33 The sum is: $69.32AltMoney.h#i
2015-09-09 22:16:19
392
转载 C++ <使用友元函数的类对象加法>
运行结果: Enter the first money (dollars): 12.123 Invalid dollars and cents, negative values Enter the first money (dollars): 12.21 Enter the second money (dollars): 99.99 The sum is: $112.20altMoney.h#
2015-09-09 22:09:19
774
原创 C++ <字符串转int类型并求和>
运行结果: Enter the first of 19 or fewer digits number: 8837899188361066012 Enter the second of 19 or fewer digits number: 6832629488379649259 Integer overflow. Enter the first of 19 or fewer digits numb
2015-09-09 06:40:01
495
转载 C++ <int、long、long long 最大及最小值>
运行结果:int 最大值:2147483647int 最小值:-2147483648long 最大值:9223372036854775807long 最小值:-9223372036854775808long long 最大值:9223372036854775807long long 最小值:-9223372036854775808unsigned long long 最大值:184467
2015-09-08 23:52:39
13128
原创 C++ 插入排序并统计数值出现的次数
运行结果:-12 -12 -12 -12 0 0 1 1 1 2 2 3 3 3 4 4 4 4 3 3 3 2 2 1 1 1 0 0 -12 -12 -12 -12 insertionSort.cpp#include <iostream>using namespace std;void ascendingSort(int ar[]
2015-09-08 18:05:58
962
原创 输入名字显示其电话号码
运行结果: Enter a name to find the corresponding phone number. Ash Williams The number is: 333-2323 Look up another name? (y/n) y Enter a name to find the corresponding phone number. lenove Name not
2015-09-07 16:35:26
2320
原创 实现动态自增数组并使用选择排序法排序
Enter numbers: 0 -3.45 -1 -66 100 32.32 54.12 9.99 8.09 -6.66 -3.44 -1 1.99 -1 0 9 p Ascending sort: -66 -6.66 -3.45 -3.44 -1 -1 -1 0 0 1.99 8.09
2015-09-07 12:20:00
434
原创 I/O Stream <傻瓜机器人对话>
程序说明:如果 kingLear.txt 行与行之间有单个或多个空行,则忽略空行内容,继续向下读取文件内容并显示。 不论文件末尾最后一行有无换行符程序均可正常运行。 kingLear.txtIs not this your son, my lord?I cannot conceive you.I cannot wish the fault undone
2015-09-05 18:57:18
427
原创 I/O Stream<文件格式化输入输出>
score.txtscore.txtXu Lisa 60 70 80 90 50 40 30 20 10 0Cheng Kevin 1 2 3 4 5 6 7 8 9 10Coco Li 11 22 33 44 55 66 77 88 99 100scoreAvg.txtXu Lisa 60 70 80 90 50 40 30 20 10 0 average: 45Cheng Kev
2015-09-05 13:07:23
472
原创 I/O Stream<找出文件中最大与最小的整数>
/* The maximum value is: 99 The mininum value is: -13 */#include <iostream>#include <fstream>#include <cctype>using namespace std;int main() { ifstream inStream; inStream.open("/Users/br/
2015-09-05 10:01:42
445
转载 I/O Stream与cin处理行尾'\n'的函数重载
fin.txt#include <iostream>#include <fstream>using namespace std;void newLine(istream& in_stream);int main() { ifstream fin; cout << "Enter a number:\n"; int number; cin >> number;
2015-09-04 21:56:39
335
转载 C++ I/0 Stream <setf and Manipulators>
/* 77.6669okwari7.6669 0okwarisunsfa6+5+788 7 hello!*/#include <iostream>#include <fstream>#include <iomanip>using namespace std;int main() { cout.width(3); cout << 7 << endl; c
2015-09-04 16:37:34
278
转载 C++ I/O Stream 控制小数点位数
manhattan.txt15.33 21.11 3.00 10.32mami.txt11.33 91.11 13.00 20.32#include <iostream>#include <fstream>using namespace std;int main() { ofstream mia;
2015-09-04 14:43:05
3339
转载 C++ I/O流文件处理(整型,字符,字符串)
getString.cpp#include <iostream>#include <fstream>void getInputStream(std::ifstream& outFile);int main() { using std::cout; using std::string; std::ifstream outFile; string s; getIn
2015-09-03 15:08:17
385
原创 求一个数的N次方
/* Enter 2 values for X and Y separated by space, The press <enter>: 2.4 4.85 2.4 to the power of 4.85 is = 69.8272 Enter 2 values for X and Y separated by space, The press <enter>: 3 4 3 to th
2015-08-31 01:55:16
889
原创 Introduction to Java Programming编程题10.7<ATM>
/*Enter an id: 4Invalid value.Enter an id: 978Main menu1: check balance2: withdraw3: deposit4: exitEnter a choice: 1The balance is: 100.0Main menu1: check balance2: withdraw3: deposit4: exi
2015-08-30 00:52:54
599
原创 Introduction to Java Programming编程题9.32<检测ISBN>
/*Enter the ISBN numbers of the book: 0136012670136012671*/import java.util.Scanner;public class CheckISBN1 { public static void main(String[] args) { Scanner input = new Scanner(System
2015-08-29 00:50:57
371
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人