当前位置:首页 » 编程语言 » 求助急需答案要具体的c语言程序
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

求助急需答案要具体的c语言程序

发布时间: 2022-07-03 06:14:18

⑴ 急需一个c语言程序题的答案,谢谢

这是个魔方矩阵问题,给你个答案:
把里面需要输入的地方改成你的宏定义就行了

#include <stdio.h>
void main()
{ int a[15][15],i,j,k,m,n,p;
p=1;
while(p==1)
{
printf("Enter n (n is a odd number from 3 to 15):> ");
scanf("%d",&n);
if((n>=3)&&(n<=15)&&(n%2==1))
p=0;
}
for(i=0;i<n;i++)
for(j=0;j<n;j++)
a[i][j]=0;
j=n/2;
a[0][j]=1;
for(k=2;k<=n*n;k++)
{ i=i-1;
j=j+1;
if((i<0)&&(j>n-1))
{ i=i+2;
j=j-1;
}
else
{ if(i<0)
i=n-1;
if(j>n-1)
j=0;
}
if(a[i][j]==0)
a[i][j]=k;
else
{ i=i+2;
j=j-1;
a[i][j]=k;
}
}
printf("\n");
for(i=0;i<n;i++)
{ for(j=0;j<n;j++)
printf("%4d",a[i][j]);
printf("\n");
}
}

⑵ C语言编程,急需答案,请求好心人的帮助!

#define LENGTH 30
#define COUNT 5
#include "stdio.h"
int main()
{
char string[COUNT][LENGTH];
char temp[LENGTH],t;
int count[COUNT]={0};
int n,i;
FILE* fp;
int status = 0;
fp = fopen("a.txt","r");
if(!fp) printf("文件打开文件!");
for(n=0;n<COUNT;n++){
printf("请输入你要统计的单词:");
scanf("%s",string[n]);
if(strcmp("#over",string[n])==0)
break;
printf("您输入了:%s\n",string[n]);
}
while( !feof(fp) )
{
t = fgetc(fp);
if(status==0){
if(t ==' ' || t == '\t' || t=='\n')
{ //nothing
}else
{ i = 0;
status=1;
}
}
if(status==1){
if(t !=' ' && t != '\t' && t!='\n')
{
temp[i++] = t;
}else{
temp[i] = 0;
for(i=0;i<n;i++)
if(strcmp(string[i],temp)==0)
count[i]++;
status = 0;
}
}
}
fclose(fp);
for(i=0;i<n;i++)
{
printf("单词%s出现了%d次\n",string[i],count[i]);
}
system("pause");
}

⑶ 我急需一个c语言编程题的答案,请给出完整的程序,谢谢

# include <stdio.h>

void change (char *str)
{
while (*str && *str!='#')
{
if (*str>='A' && *str<='Z')
{
*str+='a'-'A';
}
++str;
}
}

int main ()
{
char str[10000];
gets (str);
change (str);
puts (str);
return 0;
}

⑷ [急求助]C语言程序编程题,请高手帮忙解答下。!

只要输入一行就行了:
#include<stdio.h>
#include<math.h>
void fun(int a,int b,long *c)
{
*c=a%10*100+a/10+b/10*1000+b%10*10;
/*解释:a%10的意思是a除以10剩下的余数,即a的个位数,若a是45,a%10就是5,再乘以100即是500;a/10就是十位数,即4,原因是它是向下取整,45/10虽是4.5,但向下取整就将小数点后的都等于零;b/10和上面的a一样是取b的十位数,若b为12,b/10就是1,b/10*1000就是1000;b%10就是2,再乘以2就是20。最后将500+4+1000+20=1524*/
}
void main()
{
int a,b;long c;
printf("Input a,b:");
scanf("%d%d",&a,&b);
fun(a,b,&c);
printf("The result is:%ld\n",c);
getch();
return;
}

⑸ 求助,一道c语言程序,星期五前急需答案,万分感谢

double pi(int n)
{int i;
double s=0.0;
for (i=1;i<=n;i++)
s+=1.0/(i*i);
s*=6;
s=sqrt(s);
return s;
}

⑹ 求助大神C语言编程作业…… 求详细具体的程序答案

#include <stdio.h>
#include <stdlib.h>
//用户信息
struct User
{
int win,lose;
int counters,countersInUse;
}User;
//初始化用户信息
structUser initUser()
{
structUser me;
me.win=0;
me.lose=0;
me.counters=300;
return me;
};
//显示用户信息
void displayUser(structUser me)
{
printf("You have win:%d\n",me.win);
printf("You have lose:%d\n",me.lose);
printf("You still have counters:%d\n",me.counters);
}
//掷色子的信息
struct Game
{
int one,two,three;
int sum;
}Game;
//初始化掷色子的信息
structGame initGame()
{
structGame game;
game.one=0;
game.two=0;
game.three=0;
game.sum=0;
return game;
}
//显示所掷色子的信息
void displayGame(structGame game)
{
printf("The first toss of dice is %d\n",game.one);
printf("The second toss of dice is %d\n",game.two);
printf("The third toss of dice is %d\n",game.three);
printf("The sum toss of dice is %d\n",game.sum);
}
//如果赌博成功,并且出现三个数字相同的情况,出现Congratulation信息
void displayCongratulations(structGame game)
{
printf("**************************************\n");
printf("Congratulations For Your Good Luck!\n");
printf("You have toss the number:%d%d%d\n",game.one,game.two,game.three);
printf("You have the ten times reward!\n");
printf("**************************************\n");

}
//输入用户的赌博筹码,该数据X50为真正的筹码
//注意,该筹码不能小与等于0,并且不能大于你所拥有的筹码
structUser inputYourCounters(structUser me)
{
int theCounters;
printf("Please input your counters(the value * 50):");
scanf("%d",&theCounters);
while (theCounters<=0||theCounters*50>me.counters) {
printf("The counters you input is illegal!");
printf("Please input your counters again:");
scanf("%d",&theCounters);
}
me.countersInUse=theCounters*50;
me.counters=me.counters-me.countersInUse;
return me;
}
//输入你对色子的期望值:大或小
int inputYourExpected()
{
int expected;
printf("Please input 0 or 1 to stand for your expected value(0:small 1:big):");
scanf("%d",&expected);
while (expected!=0 && expected!=1) {
printf("expected value is illegal!\n");
printf("Please input 0 or 1 to stand for your expected value again(0:small 1:big):");
scanf("%d",&expected);
}
return expected;
}
//掷色子
int tossOneDice()
{
returnrandom()%6+1;
}
//处理三次掷色子的结果
structUser HandleTossingDice(structUser me,structGame game,int expected)
{
game.one=tossOneDice();
game.two=tossOneDice();
game.three=tossOneDice();

game.sum=game.one+game.two+game.three;

displayGame(game);

if (expected==0) {
if (game.sum<10) {
if (game.one==game.two&&game.one==game.three) {
me.counters=me.counters+10*me.countersInUse;
displayCongratulations(game);
}
else
{
me.counters=me.counters+2*me.countersInUse;
}
me.win++;
return me;
}
else{
me.countersInUse=0;
me.lose++;
return me;
}
}
else
{
if (game.sum>9) {
if (game.one==game.two&&game.one==game.three) {
me.counters=me.counters+10*me.countersInUse;
displayCongratulations(game);
}
else
{
me.counters=me.counters+2*me.countersInUse;
}
me.win++;
return me;
}
else{
me.countersInUse=0;
me.lose++;
return me;
}
}
}
//本局结束,是否还要再来一局;小赌怡情,大赌养家......
int isGoOn()
{
char goOn;
while(1)
{
printf("go on(yes:y, no:n):");
scanf("%c",&goOn);
if (goOn=='y') {
return1;
}
elseif(goOn=='n')
{
return0;
}
}
}
//程序入口
int main(int argc, constchar * argv[])
{
structUser me=initUser();
displayUser(me);
structGame game=initGame();
displayGame(game);

while (1) {
me=inputYourCounters(me);
int expected=inputYourExpected();
me=HandleTossingDice(me, game, expected);
displayUser(me);
if (isGoOn()==0) {
return0;
}
}
return0;
}

⑺ c语言 编程 谢谢啊现在急需答案

参考代码:

#include<stdio.h>
intmain()
{
charstr[1000];
intword=0,blank=0,num=0,other=0;
inti=0;
gets(str);
while(str[i]!='')
{
if((str[i]>='a'&&str[i]<='z')||(str[i]>='A'&&str[i]<='Z'))
{
word++;
}
elseif((str[i]>='0'&&str[i]<='9'))
{
num++;
}
elseif(str[i]=='')
{
blank++;
}
else
{
other++;
}
i++;
}
printf("word:%d blank:%d num:%d other:%d ",word,blank,num,other);
return0;
}

运行效果如下:

⑻ c语言程序设计题求助,加急呀,拜托大家帮忙,我要标准答案

第二题
#include<stdio.h>
#include<math.h>
void main()
{
int a,b,c;
float dt,x1,x2;
scanf("%d%d%d",&a,&b,&c);
dt=b*b-4*a*c;
if(dt>0)
{
x1=(-b+sqrt(dt))/(2*a);
x2=(-b-sqrt(dt))/(2*a);
printf("方程有俩实根,x1=%f、x2=%f",x1,x2);
}
else if(dt=0)
{
x1=(-b+sqrt(dt))/(2*a);
printf("方程有一实根,x1=%f",x1);
}
else
printf("方程无实根");
}

⑼ C语言 急需答案

3

x=1,所以最终运行的是:y=x+2; 即y=3

⑽ C语言20题求助,希望有详细过程,答案是B,有图

这题调用之后返回值是5,while里面y判断完成是x+5,之后执行y++,执行完以后y=6,返回值是5,所以选b。如果打印a[返回值]就是0,因为a[5]=''。还好楼主给了答案,这题容易看错。