① 這道題C語言編程題我有一個測試點總是通不過,請問我錯在哪
程序沒問題啊,能正常輸出:
② 編程測試題
include ;stdio.h;define NUM 10void main(){ int number[NUM]; int i; //輸入 for(i=0;iNUM;i++) { printf(;請輸入第%d個元素的值!\n;,i+1); scanf(;%d;,amp;number[i]); } //輸出 printf(;輸出:\n;); for(i=NUM-1;i;=0;i--) { printf(;%d ;,number[i]); }}//可以拉
③ java編程題,檢查錯誤。並作出測試。
Employee構造方法工齡為int類型,無參數的addSal()方法因構造方法的問題會一直報
"Lenght of service is more than 12 months! Please choose another way to add salary."也就是說工作年限半年體現不了
其餘沒什麼問題,測試的話你寫個main方法測試下就好了
④ C語言編程題
當n=20時,20.5就有19個,30.5就有18個,這樣不算其他的就有900多了,題目是怎麼得到s=534的
#include <stdio.h>
int main() {
double s = 1, t = 1;
int n;
scanf("%d", &n);
for (int i = n-2; i >= 0; i--) {
t += (n - i) * 10 + 0.5;
s += t;
}
printf("s=%f",s);
return 0;
}
⑤ c語言編程題急求
「3位水仙花數」是指一個三位整數,其各位數字的3次方和等於該數本身。例如:ABC是一個「3位水仙花數」,則:A的3次方+B的3次方+C的3次方=ABC。
請按照從小到大的順序輸出所有的3位水仙花數,請用一個「逗號+空格」分隔輸出結果。
注意:這是一個OJ題目,輸出格式要嚴格一致,最後一位水仙花數後沒有逗號。
⑥ C語言編程題
要輸入的分數太多,我懶得手數,用2位隨機數代替手輸入,輸入函數我單獨寫了,你需要調用就行了,詳細看備注。
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#definestuNum15//學生人數
#definescNum7//模塊數
typedefstructstu//定義學生數據結構
{
intsid;//學生ID
intsc[scNum];//對應7個模塊成績
intsum;//總成績
}STU;
voidinsertSTU(STU*stu);//輸入15個學生的信息
voidinsertTest(STU*stu);//測試,用隨機數代替輸入,我懶得輸入那麼多成績,你要手輸,調用insertSTU替換該函數
voidprintfSTU(STU*stu);//按輸入順序列印15名學生7模塊成績及每個模塊前三名的成績
intmain()
{
STUstu[stuNum];//定義15個學生
//inti,j,sc;
srand(time(NULL));
insertTest(stu);//想手動輸入這里改成insertSTU(stu)
printfSTU(stu);
return0;
}
voidprintfSTU(STU*stu)//按輸入順序列印15名學生7模塊成績及每個模塊前三名信息及總分前三名信息
{
inti,j,k,sc;
STU*max[3],*sum[3],newstu;//max對應7個模塊前3的學生結構指針sum對應總分前3學生結構指針
for(i=0;i<stuNum;i++)
{
printf("編號%02d的學生7模塊成績及總分分別為:",stu[i].sid);
for(j=0;j<scNum;j++)
{
sc=stu[i].sc[j];
printf("%02d",sc);
}
printf("%d
",stu[i].sum);
}
for(j=0;j<scNum;j++)
{
for(k=0;k<scNum;k++)
{
newstu.sc[k]=0;
newstu.sum=0;
}
max[0]=max[1]=max[2]=&newstu;
for(i=0;i<stuNum;i++)
{
if(stu[i].sc[j]>max[0]->sc[j])
max[0]=&(stu[i]);
elseif(stu[i].sc[j]>max[1]->sc[j])
max[1]=&(stu[i]);
elseif(stu[i].sc[j]>max[2]->sc[j])
max[2]=&(stu[i]);
}
printf("模塊%02d前3名分別為:編號:%02d分數:%02d編號:%02d分數:%02d編號:%02d分數:%02d
",j+1,max[0]->sid,max[0]->sc[j],max[1]->sid,max[1]->sc[j],max[2]->sid,max[2]->sc[j]);
}
sum[0]=sum[1]=sum[2]=&newstu;
for(i=0;i<stuNum;i++)
{
if(stu[i].sum>sum[0]->sum)
sum[0]=&(stu[i]);
elseif(stu[i].sum>sum[1]->sum)
sum[1]=&(stu[i]);
elseif(stu[i].sum>sum[2]->sum)
sum[2]=&(stu[i]);
}
printf("總分前3名分別為:編號:%02d總分:%02d編號:%02d總分:%02d編號:%02d總分:%02d
",sum[0]->sid,sum[0]->sum,sum[1]->sid,sum[1]->sum,sum[2]->sid,sum[2]->sum);
}
voidinsertSTU(STU*stu)//輸入15個學生的信息
{
inti,j,sc;
for(i=0;i<stuNum;i++)
{
stu[i].sid=i+1;
stu[i].sum=0;
printf("輸入編號%d的學生的7個模塊成績:",i+1);
for(j=0;j<scNum;j++)
{
//scanf("%d",&sc);//我懶得輸入那麼多成績,就用隨機數代替,你要輸入把這句恢復
sc=(int)(rand()%100);//用隨即2位數代替輸入,不需要就注釋掉
stu[i].sc[j]=sc;
stu[i].sum=stu[i].sum+sc;
}
}
}
voidinsertTest(STU*stu)//測試用代替輸入
{
inti,j,sc;
for(i=0;i<stuNum;i++)
{
stu[i].sid=i+1;
stu[i].sum=0;
for(j=0;j<scNum;j++)
{
sc=(int)(rand()%100);
stu[i].sc[j]=sc;
stu[i].sum=stu[i].sum+sc;
}
}
}
⑦ 這是一道c語言編程題,我測試的時候都是對的,可是提交的時候卻錯了。大家幫我看看吧,謝謝
我認為你解決問題的思路就錯了,下面是我的想法:設頁數為page_cnt,敲擊鍵盤次數為n,在1<=page_cnt<=9時,n = page_cnt, 此時1<=n<=9;在10<=page_cnt<=99時, page_cnt = (n - 9) / 2 + 9, 此時10<=n<=189; 在100<=page_cnt<=999時,page_cnt = (n - 189) / 3 + 99, 此時190<=n<=2889.根據以上推算可以按你的思路編寫程序為:
#include <stdio.h>
int main(void)
{
int T, n;
printf("Please input how many groups of data you want to check, it may between 1 and 100: ");
do {
scanf("%d", &T);
if ((T < 1) || (T > 100)) {
printf("You can only check 1 to 100 times\n");
continue;
} else
break;
} while(1);
do {
printf("Please input how many times Michael has hit the keyboard, it may between 1 and 1000: ");
do {
scanf("%d", &n);
if ((n < 1) || (n > 1000)) {
printf("Michael can hit keyboard 1 to 1000 times\n");
continue;
} else
break;
} while (1);
if ((n >= 1) && (n <= 9))
printf("hit keyboard times: %d\tpage numbers: %d\n", n, n);
else if (n <= 189)
printf("hit keyboard times: %d\tpage numbers: %d\n", n, ((n - 9) % 2) ? -1 : (n - 9) / 2 + 9);
else if (n <= 2889)
printf("hit keyboard times: %d\tpage numbers: %d\n", n, ((n - 189) % 3) ? -1 : (n - 189) / 3 + 99);
else
printf("This can't happen\n");
} while(--T);
return 0;
}
⑧ Java編程題
第二個:
package test;
import java.util.Arrays;
import java.util.List;
public class TestArray {
public static void main(String[] args) {
Integer arr[] = { 10,7,6,9,8,2};
System.out.println(arrayContains(arr, 1));
System.out.println(arrayContains1(arr, 2));
}
public static boolean arrayContains(Integer[] arr,int targetValue){
List<Integer> list = Arrays.asList(arr);
return list.contains(targetValue);
}
public static int arrayContains1(Integer[] arr,int targetValue){
List<Integer> list = Arrays.asList(arr);
if(!list.contains(targetValue)){
return -1;
}else{
for (int index = 0; index < list.size(); index++) {
Integer val = list.get(index);
if(val==targetValue){
return index;
}
}
}
return -1;
}
}
⑨ 火星探測器編程測試題,
網路文庫里有,搜MARS ROVERS
http://wenku..com/view/6490e7116edb6f1aff001fa0.html
⑩ C語言 程序測試題
一:
1 a
2 a
3 a
4 b
5 a
6 b
7 d
8 a
9 c
10 b
二:
1 3 //考察逗號表達式
2 3
3 10 9
4 4213 13
5 1
三:
1 10,5,9
2 741
3 沒有題目
四:
1
#include <stdio.h>
void main()
{
int scores[5]={0},i;
double average;
printf("Input the scores: ");
scanf("%d %d %d %d",&scores[0],&scores[1],&scores[2],&scores[3]);
for(i=0;i<4;i++)
{
printf("%d %d\n",scores[i],scores[4]);
scores[4]+=scores[i];
}
average = double(scores[4]/4.0);
printf("sum of the scores: %d\n",scores[4]);
printf("average of the scores: %2.1f\n",average);
}
2
#include <stdio.h>
void main()
{
int r,h;
double volume;
printf("Input radius and h :");
scanf("%d %d",&r,&h);
printf("%d,%d\n",r,h);
printf("volume is: %.2f\n",3.1415*r*r*h/3);
}