2/24/00: Exercise 3 Cheat Sheet ------------------------------- /********************************************************* helloC.c Type in the following program into a file called helloC.c. To compile and run type the following commands. $ gcc helloC.c -o helloC $ ./helloC *********************************************************/ #include void main() { int num1, num2; printf("Hello World!\n"); printf("Enter a number and press return: "); scanf("%d",&num1); printf("Enter another number and press return: "); scanf("%d",&num2); printf("Result: %d + %d = %d\n", num1, num2, num1+num2); } ////////////////////////////////////////////////// // helloC++.cc // // Type in the following program into a file called // helloC++.cc. // // To compile and run type the following commands. // $ g++ helloC++.cc -o helloC++ // $ ./helloC++ ////////////////////////////////////////////////// #include void main() { int num1, num2; cout << "Hello World!" << endl; cout << "Enter a number and press return: "; cin >> num1; cout << "Enter another number and press return: "; cin >> num2; cout << "Result: " << num1 << " + " << num2 << " = "; cout << num1 + num2 << endl; } ################################################## # helloPy.py # # Type in the following program into a file called # helloPy.py. # # To run type the following commands. # $ python helloPy.py ################################################## import sys; print "Hello World!"; print "Enter a number and press return: "; num1 = sys.stdin.readline(); num1 = int(num1) print "Enter another number and press return: "; num2 = sys.stdin.readline(); num2 = int(num2) print num1, "+", num2, " = ", num1 + num2 ################################################## # hellosh # # Type in the following program into a file called # hellosh # # To run type the following commands. # $ csh hellosh ################################################## echo Hello World! echo Enter a number and press return: set num1 = $< echo Enter another number and press return: set num2 = $< echo $num1 + $num2 = `expr $num1 + $num2`