當前位置:首頁 » 編程軟體 » 編程實現

編程實現

發布時間: 2022-01-09 07:52:07

A. C語言編編程實現

整個代碼反映出,你對C語言變數沒有概念。基本都是類型不匹配。相對著修改下面的代碼
char*b;
scanf("%s",b);
scanf("%d",&x);
d=fu(b,x);
printf("%f",d);

B. 編程實現下列圖形: * ** *** **** *****

public static void main(String[] args)
{
PrintStars(5);
}

public static void PrintStars(int n)
{
for(int i = 0; i < n; i++)
{
for(int j = n - 1;j >= 0; j--)
{
if(j > i)
{
System.out.print(" ");
}
else
{
System.out.print("*");
}
}
System.out.println();
}
}

C. C++編程實現

第4題正好剛才有人要的,我寫了一個,給你吧:
4、實現一個兩個人玩「石頭,剪子,布」的游戲,游戲規則大家都知道,要求用枚舉類型定義「石頭,剪子,布」。

#include<iostream.h>
#include<time.h>
#include<stdlib.h>

enum Choose
{
stone=1,
scissors,
cloth
};

int a,b;
// a: 用來存放用戶的選擇
// b: 用來存放電腦的選擇

void customer(); // 用來獲取用戶的合法輸入,其值保存在a中
void computer();// 用來獲取計算機的輸入,其值保存在b中

// 該函數用來獲取用戶的選擇,並保存在a中
void customer()
{
// 獲取用戶的有效輸入
do
{
cout<<"Please enter your choice?(1--stone 2--scissors 3--cloth):"<<endl;
cin>>a;

if(a<stone||a>cloth)
{
cout<<"Your choice is invalid!"<<endl;
}
}while(a<stone||a>cloth);

// 顯示用戶的選擇
if(a==stone)
{
cout<<"Your choice is:stone"<<endl;
}
else if(a==scissors)
{
cout<<"Your choice is:scissors"<<endl;
}
else if(a==cloth)
{
cout<<"Your choice is:cloth"<<endl;
}
}

void computer()
{
srand((unsigned)time(NULL));
b=rand()%3+1;
if(b==stone)
cout<<"My choice is:stone"<<endl;
else if(b==scissors)
cout<<"My choice is:scissors"<<endl;
else if(b==cloth)
cout<<"My choice is:cloth"<<endl;
}

void compare(int u , int v)
{
if(b==a)
cout<<"Same!"<<endl;
else if(b==stone)
{
if(a==scissors) cout<<"You Lose!"<<endl;
else if(a==cloth) cout<<"You Win!"<<endl;
}
else if(b==scissors)
{
if(a==stone) cout<<"You Win!"<<endl;
else if(a==cloth) cout<<"You Lose!"<<endl;

}
else if(b==cloth)
{
if(a==stone) cout<<"You Lose!"<<endl;
else if(a==scissors) cout<<"You Win!"<<endl;
}
}
void main()
{
char x;
do
{
customer();
computer();
compare(a,b);
cout<<"Do you want to continue?(Y/N)"<<endl;
cin>>x;
}while(x=='y' || x=='Y');
}

D. C語言編程實現

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#defineinput"input.txt"
#defineoutput"output.txt"
#defineMax20
typedefstruct_Word_{
charwd[Max];
intn;
}sword;
intmain(intargc,char*argv[])
{
FILE*fr,*fw;
if((fr=fopen(input,"r"))==NULL)
printf("openerror");
charword[Max];
charc;
inti=0,j=0,num=0,flag=0;
sword*list=malloc(sizeof(sword));
do{
c=fgetc(fr);
if(c!=' '&&c!=' '&&c!=''&&c!=','&&c!='.'&&c!=EOF){
word[i++]=c;
flag=0;
}
else{
if(0==flag){
flag=1;
word[i]='';
i=0;
for(j=0;j<num;j++)
if(strcmp((list+j)->wd,word)==0){
(list+j)->n++;
break;
}
if(j==num){
list=realloc(list,(num+1)*sizeof(sword));
strcpy((list+num)->wd,word);
(list+num)->n=1;
++num;
}
}
}
}while(c!=EOF);
fclose(fr);
fw=fopen(output,"w");
for(i=0;i<num;i++){
if((list+i)->n>=5)
fprintf(fw,"%s %d ",(list+i)->wd,(list+i)->n);
}
fclose(fw);
return0;
}

E. 編程實現

#include<iostream>
#include<cstring>
using namespace std;
void main()
{
int num;
cout<<"input the number:"<<endl;
cin>>num;
char ch[5];
itoa(num,ch,10);
if(ch[0]==ch[4]&&ch[1]==ch[3])
cout<<"是迴文數"<<endl;
else cout<<"不是迴文數"<<endl;
}

F. 編程實現

#include <stdio.h>

int main()
{
float a[3][3]={{1.3,2.7,3.6},{2,3,4.7},{3,4,1.27}}, max;
int i, j;

for (i = 0; i < 3; i++)
{
max = 0;
for (j = 0; j < 3; j++)
if (fabs(a[i][j]) > fabs(max)) max = a[i][j];
for (j = 0; j < 3; j++)
{
a[i][j] /= max;
printf("%.1f ", a[i][j]);
}
}

return 0;
}

G. C語言編程實現

#include<stdio.h>
int main()
{
double a = 86.5,b = 75.5,c=90;
double result = (a+b+c)/3;
printf("%.2f",result);
return 0;
}

H. 編程程序是怎麼實現的

編程的話,我的語言描述就是,

  1. 要編一個程序,那麼這個程序有它的基本語言。就像我們學習說話,先學會發音,然後組織語言;

  2. 學會了基本的語言後,我們就根據需要來編程,在編程過程當中,我們要考慮各種情況,使程序實現我們需要,如果考慮不周到,就會有漏洞,需要補上。所以在編程當中,用到最多的語言就是(如果,或者)這樣的詞彙。

  3. 把各種漏洞都堵上了,電腦執行你的指令,不管你有沒有提到其它方面,所有的程序它都要復核一邊。所以程序不要太龐大,需要簡潔,減少電腦的運行。這個就與你堵漏洞有相反的要求。如果你編寫了一個子程序,程序經常要用到這個,那麼你要考慮怎麼把這個程序精簡到最低程度。

  4. 因為電腦只能識別這個語言,所以不能夠在語法上有錯誤,它會理解不了。

  5. 說到漏洞,比如說,記事本裡面查找功能,你要找文字(J3),那麼它把(J33),(J32)裡面的也找了,如果你在裡面替換什麼內容的話,就會出現問題。這個問題就是你要考慮的,怎麼把漏洞堵上,不發生這樣的問題。

  6. 所以我認為編程就是你對這個程序的理解程度考驗。至於基本語言你學會就好,你要做的就是把你想說的話,翻譯成電腦能夠聽懂的話。要說明,什麼不能夠做,什麼應當做,一一交代清楚,只要說漏了一句,電腦就不按你的思路走了。(電腦不會思考,你要做的就是讓電腦按你的思路走。)

I. 用C語言編程實現~~急

#include "stdio.h"
#include "stdlib.h"

#define M 3
#define N 3
//指針數組
int a[M][N];
int b[M][N];
int c[M][N];

void matrixMul(int b[][M],int c[][N]);
void matrixAdd(int b[][N],int c[][N]);
void matrixSub(int b[][N],int c[][N]);

int main()
{
int i,j,temp=0;
printf("Please input int matrix b[%d][%d]\n",M,N);
for(i=0;i<N;i++)
for(j=0;j<N;j++)
{
scanf("%d",&temp);
b[i][j]=temp;
}
printf("Please input int matrix c[%d][%d]\n",M,N);
for(i=0;i<M;i++)
{
for(j=0;j<N;j++)
{
scanf("%d",&temp);
c[i][j]=temp;
}
}

//輸出原矩陣
printf("Now print resource matrix b[%d][%d]=",M,N);
for(i=0;i<M;i++){
printf("\n");
for(j=0;j<N;j++)
printf("%d ",b[i][j]);
}
printf("\n");
printf("Now print resource matrix c[%d][%d]=",M,N);
for(i=0;i<M;i++){
printf("\n");
for(j=0;j<N;j++)
printf("%d ",c[i][j]);
}

if (M == N)
{
matrixMul(b,c); //調用矩陣相乘
//輸出矩陣相乘結果
printf("\n");
printf("Now printm matrixMul results matrix a[%d][%d]=B*C:",M,N);
for(i=0;i<M;i++)
{
printf("\n");
for(j=0;j<N;j++)
printf("%d ",a[i][j]);
}
}
else
{
printf("matrix Error,check and try again!!! ");
}
//輸出矩陣相加結果
matrixAdd(b,c);
printf("\n");
printf("Now printm matrixAdd results matrix a[%d][%d]=B+C:",M,N);
for(i=0;i<M;i++)
{
printf("\n");
for(j=0;j<N;j++)
printf("%d ",a[i][j]);
}

//輸出矩陣相減結果
matrixSub(b,c);
printf("\n");
printf("Now printm matrixSub results matrix a[%d][%d]=B-C:",M,N);
for(i=0;i<M;i++)
{
printf("\n");
for(j=0;j<N;j++)
printf("%d ",a[i][j]);
}

return 0;
}

void matrixMul(int b[][M],int c[][N])
{
int i,j,k;
for(i=0;i<M;i++)
for(j=0;j<N;j++)
{
for(k=0;k<N;k++)
a[i][j]+=b[i][k]*c[k][j];
}
}
void matrixAdd(int b[][M],int c[][N])
{
int i,j;
for(i=0;i<M;i++)
{
for(j=0;j<N;j++)
{
a[i][j]=b[i][j]+c[i][j];
}
}
}

void matrixSub(int b[][M],int c[][N])
{
int i,j;
for(i=0;i<M;i++)
{
for(j=0;j<N;j++)
{
a[i][j]=b[i][j]-c[i][j];
}
}
}

我大概看了下,加減乘都能實現

網上資料

熱點內容
觸動精靈腳本製作教程 發布:2024-09-21 05:13:14 瀏覽:399
自己編譯autojs 發布:2024-09-21 05:09:40 瀏覽:358
我的世界電腦版無政府伺服器 發布:2024-09-21 04:55:36 瀏覽:836
時間伺服器和筆記本電腦同步 發布:2024-09-21 04:48:04 瀏覽:762
無許可權訪問工作組的計算機 發布:2024-09-21 04:26:31 瀏覽:476
為什麼ipad需要密碼解鎖 發布:2024-09-21 04:06:22 瀏覽:211
mariadb存儲過程 發布:2024-09-21 03:56:05 瀏覽:515
壓縮殼脫殼機 發布:2024-09-21 03:14:33 瀏覽:93
熱血街籃為什麼是伺服器維護中 發布:2024-09-21 03:08:19 瀏覽:937
喇叭怎麼配置功放 發布:2024-09-21 03:06:50 瀏覽:751