|
|

楼主 |
发表于 6-11-2009 09:03 PM
|
显示全部楼层
|
我不知道我的stpm会出怎样的question。因为这个sample是2003年的。现在2009。差很远。 |
|
|
|
|
|
|
|
|
|
|
发表于 6-11-2009 09:33 PM
|
显示全部楼层
回复 84# geekman 的帖子
|
go to 是 goto对吗? 书上的范例是没有空格的哦。 |
|
|
|
|
|
|
|
|
|
|
发表于 6-11-2009 09:37 PM
|
显示全部楼层
回复 100# spannar90^_^ 的帖子
就以你这题做例子
start wait reading one character code and two integer entered by a user.if the character code is I,diplay the sum of two integer.if the character code is B,display the difference betwwen the two integer.if the character is K.display message the end and stop.if others than above this type code.display wrong code..the algorithm will repeat as long as the user does not input the end character code
c programming version:- #include <stdio.h>
- #include <ctype.h>
- /*get user input */
- void getInput(int *arg1, int *arg2);
- int main()
- {
- char choice;
- int num1, num2;
-
- do
- {
- /*prompt user to enter his/her choice*/
- printf("Please enter a character :");
-
- /*store user input in choice*/
- scanf(" %c", &choice);
-
- /*perform action according user choice*/
- switch( toupper(choice)) /*convert the character to upper case letter*/
- {
- /*if user input 'l' or 'L'*/
- case 'L':
- /*get user input*/
- getInput(&num1, &num2);
-
- /*output the sum*/
- printf("sum is %d\n", num1 + num2);
-
- /*break the switch statement*/
- break;
-
- /*if user input 'b' or 'B'*/
- case 'B':
- /*get user input*/
- getInput(&num1 , &num2);
-
- /*output the different */
- printf("different is %d\n", num1 - num2);
-
- /*break switch statement*/
- break;
-
- /*if user input 'k' or 'K'*/
- case 'K':
- /*output program termination*/
- printf("Program terminated\n");
-
- /*break the switch statement*/
- break;
-
- /*all character except 'k' , 'l', 'b' OR 'K', 'L', 'B'*/
- default:
- /*output invalid prompt*/
- printf("invalid input, please try again\n");
- }
-
- } while( toupper(choice) != 'K'); /*program ended if user entered 'K' or 'k'*/
-
- return 0;
- }
-
- /*function*/
- void getInput(int *arg1, int *arg2)
- {
- printf("please enter two integer :");
- scanf(" %d %d", arg1, arg2);
- }
复制代码 c++ programming version:- #include <iostream>
- #include <cctype>
- using namespace std;
- //get user input
- void getInput(int &arg1, int &arg2);
- int main()
- {
- char choice;
- int num1, num2;
-
- do
- {
- //prompt user to enter his/her choice
- cout << "Please enter a character :";
-
- //store user input in choice
- cin >> choice;
-
- //perform action according user choice
- switch( toupper(choice)) //convert the character to upper case letter
- {
- //if user input 'l' or 'L'
- case 'L':
- //get user input
- getInput(num1, num2);
-
- //output the sum
- cout << "sum is " << num1 + num2 << endl;
-
- //break the switch statement
- break;
-
- //if user input 'b' or 'B'
- case 'B':
- //get user input
- getInput(num1 , num2);
-
- //output the different
- cout <<"different is " << num1 - num2 << endl;
-
- //break switch statement
- break;
-
- //if user input 'k' or 'K'
- case 'K':
- //output program termination
- cout << "program terminated" << endl;
-
- //break the switch statement
- break;
-
- //all other character besides 'k' , 'l', 'b' OR 'K', 'L', 'B'
- default:
- //output invalid prompt
- cout << "invalid input, please try agaon" << endl;
- }
-
- } while( toupper(choice) != 'K'); //program ended if user entered 'K' or 'k'
-
- return 0;
- }
-
- //function
- void getInput(int &arg1, int &arg2)
- {
- cout << "please enter two integer :";
- cin >> arg1 >> arg2;
- }
复制代码
[ 本帖最后由 onlylonly 于 6-11-2009 09:55 PM 编辑 ] |
|
|
|
|
|
|
|
|
|
|
发表于 6-11-2009 09:40 PM
|
显示全部楼层
回复 102# mash143 的帖子
psedurocode 并非真正的 langauge, 因此, syntax 是随意的。 没有一个真正的规格, 但是大部分人都倾向某些广为人用的 syntax。
因此在psesurecode 里
goto 对
go to 也对 |
|
|
|
|
|
|
|
|
|
|
发表于 6-11-2009 09:42 PM
|
显示全部楼层
回复 104# onlylonly 的帖子
|
哦。原来是这样的。那么使用toupper 就要include ctype.h 对吗 ? |
|
|
|
|
|
|
|
|
|
|
发表于 6-11-2009 09:43 PM
|
显示全部楼层
回复 101# spannar90^_^ 的帖子
我們都知道電腦擅長於各種數字的計算,可是,我們又知道各種程式語言的變數又都有上限,比如整數只有2^16 或 2^32 個。如果要計算更大的數字時又該如何計算呢? 就交給聰明的您來解決囉。
以 + 代表加法
以 - 代表減法
以 * 代表乘法
以 / 代表除法 (取商數)
Input :
兩個正整數的運算式,運算元及運算子之間以空格隔開
Output :
兩個正整數的運算結果,總長度不超過 500 個位數
Sample Input :help
2222222222222222222222222 + 1111111111111111111111111
2222222222222222222222222 - 1111111111111111111111111
2222222222222222222222222 * 1111111111111111111111111
2222222222222222222222222 / 1111111111111111111111111
Sample Output :
3333333333333333333333333
1111111111111111111111111
2469135802469135802469135308641975308641975308642
2
你可以试看这个题目。
[ 本帖最后由 mash143 于 6-11-2009 09:45 PM 编辑 ] |
|
|
|
|
|
|
|
|
|
|
发表于 6-11-2009 09:45 PM
|
显示全部楼层
回复 105# mash143 的帖子
对, 是 ctype.h 不是 stdlib.h
我搞错了 |
|
|
|
|
|
|
|
|
|
|
发表于 6-11-2009 09:46 PM
|
显示全部楼层
回复 107# onlylonly 的帖子
不要误会。不是针对哦。 |
|
|
|
|
|
|
|
|
|
|
发表于 6-11-2009 09:51 PM
|
显示全部楼层
回复 108# mash143 的帖子
没什么好误会的, 写程式是有人替你找到bug, 你高兴还来不及呢。  |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 6-11-2009 09:54 PM
|
显示全部楼层
回复 103# onlylonly 的帖子
|
哇。那么长@@果然很大分别。不过我该写哪一个output?因为它给的就是这养的。 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 6-11-2009 09:56 PM
|
显示全部楼层
原帖由 spannar90^_^ 于 6-11-2009 05:48 PM 发表 
啊,有一个问题要问你,
#include
main()
{ float y;
y=(float)20/3;
printf("%f\n",y);
printf("%.2f\n',y);
printf("S.2f\n",y);
printf("%-S.2f\n",y);
return 0;
}
当我去用C++时。他有出output。 ...
我该用哪一个output?
他给的已经是死板。 |
|
|
|
|
|
|
|
|
|
|
发表于 6-11-2009 09:59 PM
|
显示全部楼层
回复 110# spannar90^_^ 的帖子
其实这程式代码不很长, 是我在每一行加入了 comment, 好让你能够理解。
要那一种就看题目是 c, 还是 c++ 咯。
所以我建议你搞清楚你的课程, 教的是 c, 还是 c++ 。 因为这是两种不同的 language 来的。 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 6-11-2009 09:59 PM
|
显示全部楼层
#include<stdio>
void main[]
{int score[10], I, sum, num;
float ave;
sum=0
printf(“1: Please input number of student.=> “);
scanf(“%d”, &num);
for (i=0;i<num;i++)
{
printf(“1: input score here => “
scanf(“%d”, &score);
sum += score;
}
ave= (float)sum/(float)num;
printf(“The average is %6.2f \n”,ave);
}
然后这个题目,我只知道<stdio.>要加h.,void main()
其他就看不出来
[ 本帖最后由 spannar90^_^ 于 6-11-2009 10:04 PM 编辑 ] |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 6-11-2009 10:01 PM
|
显示全部楼层
回复 112# onlylonly 的帖子
|
那个题目是六年前题目。现在,我老师出的paper是比较low的。啊! |
|
|
|
|
|
|
|
|
|
|
发表于 6-11-2009 10:14 PM
|
显示全部楼层
回复 113# spannar90^_^ 的帖子
下次你在贴 code 是, 可以考虑[code]#include <stdio.h>
//blah ...................[/code]这样, 你的 code 会比较容易读, 而且[i] 也不会变成 italic |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 6-11-2009 10:18 PM
|
显示全部楼层
回复 115# onlylonly 的帖子
|
你所谓说的那个是马上可以检查的吗?还是比较方便读? |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 6-11-2009 10:19 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 6-11-2009 10:26 PM
|
显示全部楼层
|
我的paper exam1是programming和ict。ict是问普通的问题。不过某一些就和bio有关的问题,尤其是病装问题。好怕怕 |
|
|
|
|
|
|
|
|
|
|
发表于 6-11-2009 10:36 PM
|
显示全部楼层
答案如下
#include<stdio.h>
int main()
{
int score[10], i, sum, num;
float ave;
sum=0;
printf( "1: Please input number of student.=> ");
scanf("%d", &num);
for (i=0;i<num;i++)
{
printf("1: input score here => ");
scanf("%d", &score[ i ]);
sum += score[ i ];
}
ave= (float)sum/(float)num;
printf("The average is %6.2f \n",ave);
return 0;
} |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 6-11-2009 10:38 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|