當前位置:首頁 » 編程語言 » c語言lt函數
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

c語言lt函數

發布時間: 2022-08-17 16:30:52

c語言函數的定義與調用

# include <stdio.h>

int main(void)
{
int a, b, c,t;

printf("請輸入3個值: \n");
scanf("%d %d %d", &a, &b, &c);
printf("%d %d %d\n", a, b, c);

if(a < b)
{
t = a;
a = b;
b = t;
}

if(a < c)
{
t = a;
a = c;
c = t;

}

if(b < c)
{
t = b;
b = c;
c = t;

}

printf("%d\n", c);

}

㈡ C語言函數的定義與調用

錯誤一、
void strca1(char s1[],char s2[])
{
int i,j; //這里i , j 沒的初值,運行結果是不確定的!!加上一句:
i=j=0;
錯誤二、
char e[20]="aaaa",f[20]="bbbb",*g,*h,*k; //這里g h都是指針,且沒有給指定空間位置
g="cccc"; //這里直接向g所指向的位置放數據,就好比,你想往盒子裡面放蘋果,但你卻沒有告訴往哪個盒子里放,「cccc"就不知道會存放到哪裡了,當g指向了一個不可用的內存地址,程序就會運行錯誤了!
h="dddd";//同上
改正方法:

char e[20]="aaaa",f[20]="bbbb";
char *g="cccc",*h="dddd",*k; //在定義時這樣寫是可以的,意思是讓g直接指向一個存放"cccc"數據的位置。

㈢ 編寫一個C語言函數,比較兩個字元串的大小

#include&lt;stdio.h&gt;

#define N 100

int input(char*a,char*b)//輸入兩個字元串

{

printf("Input the first information: ");

fgets(a,N,stdin);

printf("Input the secend information: ");

fgets(b,N,stdin);

}

int my_strcmp(char*a,char*b)//比較字元串每個字元的大小

{

while((*a!='')&&(*b!=''))

{

if(*a&gt;*b)

{

return 0;

}

else if(*a&lt;*b)

{

return 1;

}

else

{

a++;

b++;

}

}

if((*a=='')&&(*b!=''))//字元串b比字元串a長

{

return 1;

}

else if((*a!='')&&(*b==''))//字元串a比字元串b長

{

return 0;

}

else

{

return 2;

}

}

int main()

{

char a[N]={0};

char b[N]={0};

int net2=0;

input(a,b);//調用輸入函數

net2=my_strcmp(a,b);//調用比較大小函數

if(0==net2)//輸出大小

{

printf("a&gt;b ");

}

else if(1==net2)

{

printf("a&lt;b ");

}

else

{

printf("a=b ");

}

return 0;

}

(3)c語言lt函數擴展閱讀:

一、return在函數中的作用

我們如果將函數看做一個加工廠,參數就是我們向加工廠投入的原料,具體的函數功能實際上就是加工的過程,而return語句代表返回值,就是加工廠在實現加工之後給「投資人」的成品。

二、return語句的特點

1、在函數當中,遇到return語句之後就意味著函數運行的結束,在此之後的代碼是不運行的。

2、它不支持任何運算也沒有任何內建方法,和任何其他的數據類型比較是否相等時永遠返回false,也可以將None賦值給任何變數。

3、執行到return語句時,會退出函數,return之後的語句不再執行。但將return語句放在try語句塊中,是個例外。

三、return的默認值:return函數默認的返回值為undefined。

㈣ 一句c語言不懂 LT=(a&0xF0)5:0;

這句話的意思如果問號前的語句為真 則LT=5 如果假 LT=0

㈤ 用c語言實現演算法功能由線性表lt建立h指向鏈表

#include<iostream>
usingnamespacestd;

#definemax15
#defineNULL0

structllist{
inte[max];
intn;
};
structnode{
intdata;
node*next;
};

voidsetnull(llist&lt)//置線性表lt為空
{
lt.n=0;
}

voidcreat(llist&lt)//輸入線性表lt中元素的值
{
inti;
do
{
cout<<"(1<=n<="<<max<<"):";
cin>>lt.n;
}while(lt.n<1||lt.n>max);
for(i=0;i<lt.n;i++)
{
cout<<" "<<i+1<<":";
cin>>lt.e[i];
}
}

voidoutllist(llistlt)//輸出線性表lt中元素的值
{
inti;
cout<<"DATAINLINEARLISTlt: ";
for(i=0;i<lt.n;++i)
cout<<lt.e[i]<<' ';
cout<<' ';
}

voiderror(charerr[])//輸出出錯信息
{
cout<<err<<"出錯 ";
}

intlength(llistlt)//函數功能為求線性表lt的表長
{
returnlt.n;
}

voidgetelem(llistlt,inti,int&ai)//演算法功能取第i個元素的值,由ai返回
{
if(lt.n==0)
error("err1");//表空出錯
elseif(i<1||i>lt.n)
error("err2");//i值出錯
elseai=lt.e[i-1];
}

voidcreate(llistlt,node*&h)//演算法功能由線性表lt建立h指向鏈表
{
inti;
node*p,*q;
if(lt.n<1)
{
h=NULL;
return;
}
else
{
h=newnode();
h->data=lt.e[0];
h->next=NULL;
}
q=h;
for(i=1;i<lt.n;++i)
{
p=newnode();
p->data=lt.e[i];
p->next=NULL;
q->next=p;
q=p;
}
}

voidoutllink(node*h)//輸出h指向鏈表中的結點數據
{
node*p;
p=h;

cout<<"DATAINLINEARLINKEDLISTh: ";
while(p)
{
cout<<p->data<<' ';
p=p->next;
}
cout<<' ';
}

voidinsert_llink(node*&h,intai,intx)//線性鏈表插入演算法
{
node*i,*p,*q;
i=newnode;
i->data=x;
if(h==NULL)
{
error("err1");//鏈表為空cout<<"鏈表空"<<' ';
}
else
{
if(h->data==ai)
{
i->next=h;
h=i;
}
else{
p=h;
while(p->data!=ai&&p->next!=NULL)
{
q=p;
p=p->next;
}
if(p->data==ai)
{
q->next=i;
i->next=p;
}
else
error("err2");//未找到數據域值為ai的結點
}
}
}

voiddelete_llink(node*&h,intx)//線性鏈表刪除演算法
{
node*p,*q;
if(h==NULL)
error("err1");//表空出錯
elseif(h->data==x)
{
p=h;
h=h->next;
p->next=NULL;

delete(p);//由系統收回結點存儲空間
}
else
{
p=h;
while(p->data!=x&&p->next!=NULL)
{
q=p;
p=p->next;
}
if(p->data==x){
q->next=p->next;
p->next=NULL;
delete(p);//由系統收回結點存儲空間
}
else
error("err2");//未找到數據域值等於x的結點
}
}


voidmain(void)
{
llistlt;
node*h;
charc;
intai,x;
cout<<"***THEPROGRAMFORLINEARLINKEDLIST*** ";

setnull(lt);
creat(lt);
outllist(lt);
h=NULL;
create(lt,h);
outllink(h);
do{
cout<<"TOSELECTCOMMAND(I,D,O,E) ";
cout<<"COMMAND:";
cin>>c;
switch(c){
case'I':cout<<" ";
cout<<"VALUEOFTHEELEMENT(ai)=";
cin>>ai;
cout<<"VALUEOFNEWELEMENT(x)=";
cin>>x;
insert_llink(h,ai,x);

outllink(h);
break;
case'D':cout<<" ";
cout<<"VALUEOFTHEELEMENT(x)=";
cin>>x;
delete_llink(h,x);
outllink(h);
break;
case'O':cout<<" ";
outllink(h);
break;
case'E':
break;
default:
error("命令字");
}
}
while(c!='E');
}

㈥ c語言函數的使用,定義一個交換函數 實現2個數字的交換。

void Swap(int&x,int&y)

{

int temp=0;

temp=x;

x=y;

y=temp;

}

int main()

{

int a=1;

int b=2;

Swap(a,b);

cout&lt;&lt;"a="&lt;&lt;a&lt;&lt;endl;

cout&lt;&lt;"b="&lt;&lt;b&lt;&lt;endl;

system("pause");

return 0;

}

運行結果:

(6)c語言lt函數擴展閱讀:

用指針交換:

void Swap(int*x,int*y)

{

int temp=0;

temp=*x;

*x=*y;

*y=temp;

}

int main()

{

int x=1;

int y=2;

Swap(&x,&y);

printf("x=%d,y=%d ",x,y);

system("pause");

return 0;

}

運行結果:

X=2;Y=1

㈦ c語言中itoa()和ltoa()函數分別是什麼意思

itoa是廣泛應用的非標准C語言擴展函數。由於它不是標准C語言函數,所以不能在所有的編譯器中使 用。但是,大多數的編譯器(如Windows上的)通常在<stdlib.h>頭文件中包含這個函數。在<stdlib.h>中與之有相反功能的函數是atoi。功能:把一整數轉換為字元串。

㈧ c語言 時間函數

c語言時間函數:
1、獲得日歷時間函數:
可以通過time()函數來獲得日歷時間(Calendar Time),其原型為:time_t time(time_t * timer);
如果已經聲明了參數timer,可以從參數timer返回現在的日歷時間,同時也可以通過返回值返回現在的日歷時間,即從一個時間點(例如:1970年1月1日0時0分0秒)到現在此時的秒數。如果參數為空(NUL),函數將只通過返回值返回現在的日歷時間,比如下面這個例子用來顯示當前的日歷時間:
2、獲得日期和時間函數:
這里說的日期和時間就是平時所說的年、月、日、時、分、秒等信息。從第2節我們已經知道這些信息都保存在一個名為tm的結構體中,那麼如何將一個日歷時間保存為一個tm結構的對象呢?
其中可以使用的函數是gmtime()和localtime(),這兩個函數的原型為:
struct tm * gmtime(const time_t *timer);
struct tm * localtime(const time_t * timer);
其中gmtime()函數是將日歷時間轉化為世界標准時間(即格林尼治時間),並返回一個tm結構體來保存這個時間,而localtime()函數是將日歷時間轉化為本地時間。比如現在用gmtime()函數獲得的世界標准時間是2005年7月30日7點18分20秒,那麼用localtime()函數在中國地區獲得的本地時間會比世界標准時間晚8個小時,即2005年7月30日15點18分20秒。

㈨ c語言函數問題

一個函數的的聲明,要給出 四個信息,舉個例子

void printfMessage (void)

{

printf("Programming is fun. ");

}

  1. 誰可以調用它 who call call it (注意 static 的應用)

  2. 返回值的類型 The type of value it returns

  3. 函數名 its name

  4. 參數列表 the arguments it takes

很顯然 ,你說的例子中,get作為函數名

不同的是它們的返回類型,一個返回Int &, 一個返回int.前者是一個指向int 類的指針,後者是整型

下面截至 k & r

here is the function power and a main program to excuter it , so you can see the whole structure at once.

A function definition has this form: 函數定義具有如下格式

return-type function-name(parameter declarations, if any)

{

declarations

statements

}

返回類型 函數名(參數聲明,...)

{

聲明

語句

}

Returning Pointers

Although functions tht return pointers are handled just like any other type of function, it is review some key concepts and look at an example. Pointers are neither integers nor unsigned integers, They are the memory address of a certain type of data. One reason for this distinction is that pointer arithmetic is relative to the base type. For example, if an integer

pointer is incremented , it will contain a value that is four greater than its previous value

(assuming 4-byte integers), In general, each time a pointer is incremented(or decremented),

it points to the next(of previous) item of its type. Since the length of different data types may differ, the compiler must know what type of data the pointer is pointing to. For this reason that returns a pointer must declare explicitly what type of pointer it is returning. For example, you should not use a return type of int * to return a char * pointer! In a few case, a function will need to return a generic pointer. In this case, the function return type must be specified as void *.

To return a ponter, a function must be declared as having a pointer return type. For example, the following function returns a pointer to the first occurrence of the character c in string s; If no match is found, a pointer to the null terminator is returned.

/* Rerurn pointer of fisrt occurrence of c in s. */

char *match(char c, char *s)

{

while (c != *s, && *s) s++;

return (s);

}

Here is a short program that uses match();

#include <stdio.h>

char *match(char c, char *s); /* prototype */

int main(void)

{

char s[80], *p, ch;

gets(s);

ch = getchar();

p = match(ch, s);

if (*p) /* there is a match */

printf(" %s ", p);

else

printf("No match found.");

return 0;

}

簡單的翻譯一下:

雖然函數返回一個指針和函數返回其他類型的值並沒有什麼區別,但是通過它回顧一些關鍵概念還是很有用處的。指針無非就是整型和無符號整型,它們是某些數據類型的內存地址,指針的運算涉及到它的基本類型,比如說,一個指向整型的指針增加1.這個指針變數的的值將會比他的前一個值大4, 一般來講,指針每加1或者減1,它將指向下一項(這種類型)。由於不同數據類型有著不同的長度,編譯器必須知道指針指向了哪種類型,為了解決這個問題,如果一個函數返回一個指針,它必須明確的給出它將返回哪種類型的指針。 比如說,你不能使用 int * 來返回char *. 在某些情況下,一個函數需要返回一個泛型(generic pointer), 在這種情況下,函數必須聲明為 void *.

為了能夠返回一個指針,函數必須明確的指出,它將返回哪種指針類型。舉個例子,下列函數返回一個指針,指向字元串S中第一次出現的c,如果不能匹配上,返回一個指向NULL的指針

reference:

[1] Brian W. Kernighan& Dennis M. Ritchie the c programming language

[2] Stephen G.Kochan Pogramming in C Third Edition

[3] Herbert Schildt C The Complete Reference Fourth Edition

㈩ c語言常用的函數有哪些

#include
<assert.h>
//設定插入點
#include
<ctype.h>
//字元處理
#include
<errno.h>
//定義錯誤碼
#include
<float.h>
//浮點數處理
#include
<fstream.h>
//文件輸入/輸出
#include
<iomanip.h>
//參數化輸入/輸出
#include
<iostream.h>
//數據流輸入/輸出
#include
<limits.h>
//定義各種數據類型最值常量
#include
<locale.h>
//定義本地化函數
#include
<math.h>
//定義數學函數
#include
<stdio.h>
//定義輸入/輸出函數
#include
<stdlib.h>
//定義雜項函數及內存分配函數
#include
<string.h>
//字元串處理
#include
<strstrea.h>
//基於數組的輸入/輸出
#include
<time.h>
//定義關於時間的函數
#include
<wchar.h>
//寬字元處理及輸入/輸出
#include
<wctype.h>
//寬字元分類
標准
C/C++
(同上的不再注釋)
#include
<algorithm>
//STL
通用演算法
#include
<bitset>
//STL
位集容器
#include
<cctype>
#include
<cerrno>
#include
<clocale>
#include
<cmath>
#include
<complex>
//復數類
#include
<cstdio>
#include
<cstdlib>
#include
<cstring>
#include
<ctime>
#include
<deque>
//STL
雙端隊列容器
#include
<exception>
//異常處理類
#include
<fstream>
#include
<functional>
//STL
定義運算函數(代替運算符)
#include
<limits>
#include
<list>
//STL
線性列表容器
#include
<map>
//STL
映射容器
#include
<iomanip>
#include
<ios>
//基本輸入/輸出支持
#include
<iosfwd>
//輸入/輸出系統使用的前置聲明
#include
<iostream>
#include
<istream>
//基本輸入流
#include
<ostream>
//基本輸出流
#include
<queue>
//STL
隊列容器
#include
<set>
//STL
集合容器
#include
<sstream>
//基於字元串的流
#include
<stack>
//STL
堆棧容器
#include
<stdexcept>
//標准異常類
#include
<streambuf>
//底層輸入/輸出支持
#include
<string>
//字元串類
#include
<utility>
//STL
通用模板類
#include
<vector>
//STL
動態數組容器
#include
<cwchar>
#include
<cwctype>
using
namespace
std;
C99
增加
#include
<complex.h>
//復數處理
#include
<fenv.h>
//浮點環境
#include
<inttypes.h>
//整數格式轉換
#include
<stdbool.h>
//布爾環境
#include
<stdint.h>
//整型環境
#include
<tgmath.h>
//通用類型數學宏