主函數怎麼寫?

General 更新 2023年10月15日

C語言,C++,怎麼寫主函數

主函數的作用是程序的入口。就是說只要程序一開始,第一句執行的就是主函數中的第一條語句。

編寫規律:主函數一般是調用函數和簡單的邏輯判斷,代碼長度不宜超過80行。

技巧:將功能儘量整合到一個子函數,採用調用。例如,長方形體積是一個子函數一樣。

舉例如下:

#include

double V(double a, double b, double c); //聲明子函數

void main() //主函數

{double a,b,c; //長 寬 高

double v;

scanf("%lf%lf%lf",&a,&b,&c); //輸入長 寬 高

v = V(a,b,c); /撫;體積子函數

printf("%lf",v);

}

double V(double a, double b, double c)

{

double v;

v = a*b*c;

return v; //返回給主函數的值

}

c語言中,標準main函數的書寫規範是什麼?

那是因為C語言剛剛出來的時候標準還不統一!

最先前是main() 連頭文件都不需要,後來又出現了需要#include頭文件,再後來是int main() 這樣的形式就必要要有個返回值! 這些都是因為C語言在不斷改進,所以各個版本都有區別,現在這就在於你公司或自己要求個標準是哪個標準了或者是使用的哪個編譯器,因為編譯器支持的標準也不一樣!

int main(int argc, char* argv[]) 其實main函數還有兩個參數!

java中,main方法怎麼寫?

main方法定義如下:

public static void main(String[] args){…}

關鍵字的作用:

(1)public關鍵字,這個好理龔,聲明主函數為public就是告訴其他的類可以訪問這個函數。

(2)static關鍵字,告知編譯器main函數是一個靜態函數。也就是說main函數中的代碼是存儲在靜態存儲區的,即當定義了類以後這段代碼就已經存在了。如果main()方法沒有使用static修飾符,那麼編譯不會出錯,但是如果你試圖執行該程序將會報錯,提示main()方法不存在。因為包含main()的類並沒有實例化(即沒有這個類的對象),所以其main()方法也不會存。而使用static修飾符則表示該方法是靜態的,不需要實例化即可使用。

(3)void關鍵字表明main()的返回值是無類型。

(4)參數String[] args,作用是為程序使用者在命令行狀態下與程序交互。

這個單鏈表的主函數怎麼寫?

你要寫的主函數用來幹什麼

C語言主函數寫法

main函數是操作系統調用的入口,前面的int void 是返回類型,返回給操作系統。

int 是整型 void 是無返回值。

你說的main()寫法是編譯器會自動幫你補充int 或void的,有的編譯器不支持。

這是小問題,看情況試試就可以知道了,。

建立文件a.c,並在主函數main()中實現以下語句: 急急,怎麼寫

#include void main() {int a,b=80;float c;a=b;c=a+1;printf("%d\n%d\n%f",a,b,c);}將上述內容存為a.c,並編譯執行,就可以了。

執行結果:

友元函數的主函數怎麼寫?

#include

class B

{

public:

void d();

};

class A

{

friend void f();

friend void B::d();

public:

A(int x=0){this->x=x;}

private :

int x;

};

void B::d()//成員函數做為類的友元函數

{

A a;

a.x++;

cout<<"調用了成員函數作為友員函數:a.x="<

}

void f()//普通函數做為類的友元函數

{

A a;

a.x++;

cout<<"調用普通成員函數作為友元a.x="<

}

void main()

{

B b;

A a;

f();

b.d();

}

數據結構主函數怎麼寫

/* 串a: abcdefghijklmnopqrstuvwxyz 串b: 01234567890123456789 串a: abcdefghijklmnopqrstuv012345678901234567 串c: abcdefghijklmnopqrstuvwxyz Press any key to continue */ #include #define MAXLEN 40typedef struct { char ch[MAXLEN]; int len;}SString;void StrInsert(SString *s,int pos,SString t) { int i; if(pos < 0 ) pos = 0; if(pos > s->len - 1) pos = s->len; if(s->len + t.len <= MAXLEN) { // 長度適中 for(i = s->len + t.len - 1;i > pos;i--) s->ch[i] = s->ch[i - t.len]; for(i = 0;i < t.len;i++) s->ch[i + pos] = t.ch[i]; s->len += t.len; } else if(pos + t.len > MAXLEN) { // 長度超限1,從pos後不再有s的內容 for(i = pos;i < MAXLEN; ++i) s->ch[i] = t.ch[i - pos]; s->len = MAXLEN; } else { // 長度超限2,從pos + t.len後還有s的部分內容 for(i = MAXLEN - 1; i >= pos + t.len; --i) s->ch[i] = s->ch[i - t.len]; for(i = 0; i < t.len; ++i) s->ch[i + pos] = t.ch[i]; s->len = MAXLEN; }}// 在s中從pos位置開始刪除len個字符int StrDelete(SString *s,int pos,int len) { int i; if(pos < 0 || pos > s->len) return 0; if(pos + len < s->len) { // 刪除s的中間部分 for(i = pos;i < pos + len;i++) s->ch[i] = s->ch[i + len]; s->len -= len; } else { // len太大 s->len = pos; } return 1;}SString StrCopy(SString *s,SString t) { int i; for(i = 0;i < t.len;i++) s->ch[i] = t.ch[i]; s->len = t.len; return *s;}int StrEmpty(SString s) { if(s.len == 0) return 1; return 0;}int SteCompare(......

數據結構用C語言寫的串怎麼寫主函數

/*

串a:

abcdefghijklmnopqrstuvwxyz

串b:

01234567890123456789

串a:

abcdefghijklmnopqrstuv012345678901234567

串c:

abcdefghijklmnopqrstuvwxyz

Press any key to continue

*/

#include #define MAXLEN 40typedef struct {char ch[MAXLEN];int len;}SString;void StrInsert(SString *s,int pos,SString t) {int i;if(pos < 0 ) pos = 0;if(pos > s->len - 1) pos = s->len;if(s->len + t.len <= MAXLEN) { // 長度適中for(i = s->len + t.len - 1;i > pos;i--)s->ch[i] = s->ch[i - t.len];for(i = 0;i < t.len;i++) s->ch[i + pos] = t.ch[i];s->len += t.len;}else if(pos + t.len > MAXLEN) { // 長度超限1,從pos後不再有s的內容for(i = pos;i < MAXLEN; ++i)s->ch[i] = t.ch[i - pos];s->len = MAXLEN;}else { // 長度超限2,從pos + t.len後還有s的部分內容for(i = MAXLEN - 1; i >= pos + t.len; --i)s->ch[i] = s->ch[i - t.len];for(i = 0; i < t.len; ++i)s->ch[i + pos] = t.ch[i];s->len = MAXLEN;}}// 在s中從pos位置開始刪除len個字符int StrDelete(SString *s,int pos,int len) {int i;if(pos < 0 || pos > s->len) return 0;if(pos + len < s->len) { // 刪除s的中間部分for(i = pos;i < pos + len;i++)s->ch[i] = s->ch[i + len];s->len -= len;}else { // len太大s->len = pos;}return 1;}SString StrCopy(SString *s,SString t) {int i;for(i = 0;i < t.len;i++) s->ch[i] = t.ch[i];s->len = t.len;return *s;}int StrEmpty(SString s) {if(s.len == 0) return 1;return 0;}int S......

線性表的主函數要怎麼寫。 幫幫忙進來看看。。。 10分

/*

請輸入待建立的表長 : 5

請輸入5個元素用空格分開 : 56 54 34 12 76

成功建立表!

插入元素10。

56 10 54 34 12 76

刪除第3個元素。

56 10 34 12 76

Press any key to continue

*/

#include

using namespace std;

#define MaxSize 100

typedef int datatype;

typedef struct {

datatype data[MaxSize];

int last;

}SeqList;

void Init_SeqList(SeqList*L) {

int i;

cout << "請輸入待建立的表長 : ";

cin >> L->last;

cout << "請輸入" << L->last << "個元素用空格分開 : ";

for(i = 0;i < L->last;i++) {

cin >> L->data[i];

}

cout << "\n成功建立表!\n";

}

int Insert_SeqList(SeqList *L,int i,datatype x) {

int j;

if(L->last == MaxSize - 1) {

cout <<"表滿!\n";

return -1;

}

if((i < 1) || (i > L->last + 2)) {

cout << "位置錯!\n";

return 0;

}

for(j = L->last;j >= i - 1;j--)L->data[j + 1] = L->data[j];

L->data[i - 1] = x;

L->last++;

return 1;

}

int Delete_SeqList(SeqList *L,int i) {

int j;

if((i < 1) || (i > L->last + 1)) {

cout << "不存在第i個元素。\n";

return 0;

}

for(j = i;j < L->last;j++) L->data[j - 1] = L->data[j];

L->last--;

return 1;

}

int Locate_SeqList(SeqList *L,datatype x) {

int i = 0;

while((i < L->last) && (L->data[i] != x)) i++;

if(i >= L->last) return -1;

else return 0;

}

void Display_SeqList(SeqList *L) {

if(L == NULL) cout <&l埂; "表為空,不能輸出。&......

相關問題答案
主函數怎麼寫?
無參構造函數怎麼寫?
外部中斷函數怎麼寫?
中斷函數怎麼寫?
匹配函數怎麼用視頻?
冪函數的和函數怎麼求?
家務英文複數怎麼寫?
反需求函數怎麼求?
指數函數怎麼計算?
六一幼兒主持稿怎麼寫?