當前位置:首頁 » 招生排名 » 石油大學c語言上機答案

石油大學c語言上機答案

發布時間: 2024-01-17 10:28:39

⑴ c語言關於strlen函數的

設有定義語句:char str[][20]={"Beijing","123456"},*p=str; /*把逗號去掉,把中文變數字*/
則printf("%d\n",strlen(p+20)); 輸出結果是
A)10 B) 6 C) 0 D) 20

選擇B

希望回答對你有幫助

⑵ 求C語言上機實驗題答案!!!

//1.將字元串中ASCII碼最小的字元放在第一個字元位置,其餘字元依次往後移
void func(char *str)
{
int loc=0,cloc=0;
char c;

c = *str;

while(*(str+loc) !='\0')
{
if( c>*(str+loc))
{
c = *(str+loc);
cloc = loc;
}
loc++;
}

while(cloc !=0) //移到最前
{
//左移
loc =0;
while(*(str+loc+1) !='\0')
{
c = *(str+loc);
*(str+loc) = *(str+loc+1);
*(str+loc+1) = c;
loc++;
}
cloc--;
}

}
//2.略去非數字字元,將字元串s轉換為一個整數
long func(char *s);
{

int loc=0;
char c;
long ret=0L;

......
......
//假設現在已經略去非數字字元,並取得+-,放於*str
while(*(str+loc) !='\0')
{
ret = ret*10 + (*(str+loc)-'0');
loc++;
}
if( c=='-')
ret *= -1;
return ret;
}
//3.返回在s中相鄰三個數的和中的最小值
int min3adj(int s[], int n)
{
int i,j;
long sum;

sum = s[0] + s[1] + s[2];
for( i=0; i <n-2 ;i++)
{
if( s[i] + s[i+1] + s[i+2] < sum )
sum = s[i] + s[i+1] + s[i+2];
}
return sum;
}

⑶ 求:中國石油大學(華東)現代遠程教育 C語言 在線考試答案

1.從鍵盤輸入10個整數,求其和。
#include <stdio.h>
main()
{
int i,x,s=0;
printf("請輸入10個整數:");
for(i=0;i<10;i++)
{
scanf("%d",&x);
s=s+x;
}
printf("s=%d\n",s);
}
2.計算s=1!+2!+…+10!
方法1:
#include <stdio.h>
main()
{
int i,j;
long s=0,t;
for(i=1;i<=10;i++)
{
t=1;
for(j=1;j<=i;j++)
t=t*j;
s=s+t;
}
printf("1!+2!+...+10!=%ld\n",s);
}
方法2:
#include <stdio.h>
main()
{
int i;
long s=0,t=1;
for(i=1;i<=10;i++)
{
t=t*i;
s=s+t;
}
printf("1!+2!+...+10!=%ld\n",s);
}
3.求100-999中的水仙花數。所謂水仙花數是指一個數的各位數字的立方和等於該數自身的數。如:153=1*1*1+5*5*5+3*3*3 。
方法1:
#include <stdio.h>
main()
{
int n,g,s,b;
for(n=100;n<1000;n++)
{
g=n%10;
s=n/10%10;
b=n/100;
if(n==b*b*b+s*s*s+g*g*g)
printf("%d=%d%d%d\n",n,b,s,g);
}
printf("\n");
}
方法2:
#include <stdio.h>
main()
{
int n,g,s,b;
for(b=1;b<=9;b++)
for(s=0;s<=9;s++)
for(g=0;g<=9;g++)
{
n=100*b+10*s+g;
if(n==b*b*b+s*s*s+g*g*g)
printf("%d%d%d=%d\n",b,s,g,n);
}
printf("\n");
}

熱點內容
女大學生應急艙門 發布:2025-05-01 01:44:43 瀏覽:403
想砍死博士導師怎麼辦 發布:2025-05-01 01:18:57 瀏覽:755
西南政法大學徐教授 發布:2025-05-01 00:20:29 瀏覽:285
大連外國語大學俄語復試名單 發布:2025-05-01 00:05:50 瀏覽:464
大學生離省 發布:2025-04-30 23:36:15 瀏覽:78
東南大學研究生院薪酬 發布:2025-04-30 23:32:24 瀏覽:138
大學生嚴進嚴出 發布:2025-04-30 22:52:20 瀏覽:527
2015年遼寧大學研究生專業目錄 發布:2025-04-30 22:17:55 瀏覽:461
大學生有必要遷戶口嗎 發布:2025-04-30 22:15:42 瀏覽:579
貴陽醫學院研究生部導師 發布:2025-04-30 22:14:22 瀏覽:490