為了中心對(duì)稱,顯然要用空格補(bǔ)齊前面的位置,循環(huán)才能做到。
富平ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場(chǎng)景,ssl證書未來市場(chǎng)廣闊!成為創(chuàng)新互聯(lián)的ssl證書銷售渠道,可以享受市場(chǎng)價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:13518219792(備注:SSL證書合作)期待與您的合作!
#include stdio.h
void tow(char c,int n)
{
for (int i=1;i=n;i++)
{
for(int j=1;j=n-i;j++)
{
printf(" ",c);
}
for(int k=1;k=i;k++)
{
printf("%c ",c);
}
printf("\n");
}
}
void main()
{
char c=0;
int n;
printf("輸入du字符:zhi");
scanf("%c",c);
printf("輸入行數(shù):");
scanf("%d",n);
tow(c,n);
}
擴(kuò)展資料:
C語言包含的各種控制語句僅有9種,關(guān)鍵字也只有32 個(gè),程序的編寫要求不嚴(yán)格且以小寫字母為主,對(duì)許多不必要的部分進(jìn)行了精簡(jiǎn)。實(shí)際上,語句構(gòu)成與硬件有關(guān)聯(lián)的較少,且C語言本身不提供與硬件相關(guān)的輸入輸出、文件管理等功能,如需此類功能,需要通過配合編譯系統(tǒng)所支持的各類庫進(jìn)行編程,故c語言擁有非常簡(jiǎn)潔的編譯系統(tǒng)。
參考資料來源:百度百科-c語言
4 二進(jìn)制左移4位,也就是*16
如:
int x = 10;
int y = x 4;
printf( "%d", y );
輸出160 ;
那么上面就是如果xx[i][j]的值*16后大于32而且小于或等于100的話,就執(zhí)行下面的語句
itoa函數(shù)
是int 轉(zhuǎn)string類型的一個(gè)函數(shù) msdn上是這么寫的
_itoa, _i64toa, _ui64toa, _itow, _i64tow, _ui64tow
Convert an integer to a string.
char *_itoa( int value, char *string, int radix );
char *_i64toa( __int64 value, char *string, int radix );
char * _ui64toa( unsigned _int64 value, char *string, int radix );
wchar_t * _itow( int value, wchar_t *string, int radix );
wchar_t * _i64tow( __int64 value, wchar_t *string, int radix );
wchar_t * _ui64tow( unsigned __int64 value, wchar_t *string, int radix );
Routine Required Header Compatibility
_itoa stdlib.h Win 95, Win NT
_i64toa stdlib.h Win 95, Win NT
_ui64toa stdlib.h Win 95, Win NT
_itow stdlib.h Win 95, Win NT
_i64tow stdlib.h Win 95, Win NT
_ui64tow stdlib.h Win 95, Win NT
For additional compatibility information, see Compatibility in the Introduction.
Libraries
LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version
Return Value
Each of these functions returns a pointer to string. There is no error return.
Parameters
value
Number to be converted
string
String result
radix
Base of value; must be in the range 2 – 36
Remarks
The _itoa, _i64toa, and _ui64toa function convert the digits of the given value argument to a null-terminated character string and stores the result (up to 33 bytes) in string. If radix equals 10 and value is negative, the first character of the stored string is the minus sign ( – ). _itow, _i64tow, and _ui64tow are wide-character versions of _itoa, _i64toa, and _ui64toa respectively.
Generic-Text Routine Mappings
TCHAR.H Routine _UNICODE _MBCS Not Defined _MBCS Defined _UNICODE Defined
_itot _itoa _itoa _itow
Example
/* ITOA.C: This program converts integers of various
* sizes to strings in various radixes.
*/
#include stdlib.h
#include stdio.h
void main( void )
{
char buffer[20];
int i = 3445;
long l = -344115L;
unsigned long ul = 1234567890UL;
_itoa( i, buffer, 10 );
printf( "String of integer %d (radix 10): %s\n", i, buffer );
_itoa( i, buffer, 16 );
printf( "String of integer %d (radix 16): 0x%s\n", i, buffer );
_itoa( i, buffer, 2 );
printf( "String of integer %d (radix 2): %s\n", i, buffer );
_ltoa( l, buffer, 16 );
printf( "String of long int %ld (radix 16): 0x%s\n", l,
buffer );
_ultoa( ul, buffer, 16 );
printf( "String of unsigned long %lu (radix 16): 0x%s\n", ul,
buffer );
}
Output
String of integer 3445 (radix 10): 3445
String of integer 3445 (radix 16): 0xd75
String of integer 3445 (radix 2): 110101110101
String of long int -344115 (radix 16): 0xfffabfcd
String of unsigned long 1234567890 (radix 16): 0x499602d2
Data Conversion Routines
See Also _ltoa, _ultoa
//最符合題意的答案,沒有超過本章知識(shí)點(diǎn),可以完全升級(jí)下面的答案,簡(jiǎn)潔明了
#includestdio.h
int tow(int *,int);
int tow(int a[],int n)
{int yu=0;
while(n!=0)
{ a[yu]=n%2;
n=n/2;
yu++;
}
return yu;
}
int main()
{ int a[10000],num,n;
printf("input num:");
scanf("%d",num);
n=tow(a,num);
for(n--;n=0;n--)//注意這里第一個(gè)n--;只執(zhí)行一次,沒有他數(shù)組下標(biāo)會(huì)越界
printf("%d",a[n]);
return 0;
}
書本上是這樣的,double pow(double x, double y); 求教函數(shù)參數(shù)非得是.
原型:extern float pow(float x, float y); 用法:#include 功能:計(jì)算x的y次冪。 說明:x應(yīng)大于零,返回冪指數(shù)的結(jié)果。 舉例: // pow.c #include #include.
這個(gè)函數(shù)在頭文件中是這樣定義的:long double pow(long double,int)”“float 。
在VC++6.0中原型為double pow( double x, double y ); 頭文件:cmath 功能:計(jì)算x的y次冪。返回值:x不能為負(fù)數(shù)且y為小數(shù),或者x為0且y小于等于0,返回冪指數(shù)的結(jié)果.
C語言里面怎么使用pow函數(shù)啊,比如我要計(jì)算10的x次方怎么寫,為什么我寫。
#include#include //必須引用頭文件 int main() { int x; double d ; //pow返回結(jié)果為double類型 printf("input x: " ); scanf("%d", x ); d=pow(10,x) ; //函數(shù).
#include?"stdio.h"
#define?N?20
void?Largesttow?(int?a[],int?n,int?*pfirst,int?*psecond){
int?i,j,k;
for(i=0;in;i++){
for(k=i,j=k+1;jn;j++)
if(a[k]a[j])
k=j;
if(k!=i)
j=a[k],a[k]=a[i],a[i]=j;
if(a[i]!=a[0]){
*pfirst=a[0];
*psecond=a[i];
return;
}
else?if(i==n-1)
*pfirst=*psecond=a[0];
}
}
int?main(int?argv,char?*argc[]){
int?i,n,a[N],max1,max2;
printf("Please?enter?n(int?0n=N)...\nn=");
if(scanf("%d",n)!=1?||?n1?||?nN){
printf("Input?error,?exit...\n");
return?0;
}
printf("Please?enter?%d?integers...\n",n);
for(i=0;in;i++)
scanf("%d",a[i]);
Largesttow(a,n,max1,max2);
if(max1!=max2)
printf("\n%d?%d\n",max1,max2);
else
printf("\nOnly?one?number:?%d\n",max1);
return?0;?
}
運(yùn)行樣例:
//聲明
#includestdio.h
#includestdlib.h
#includetime.h
#includeconio.h
#includewindows.h
#define SIZE 4
static int score=0;
void putn(int n[][SIZE]);
void getn(int n[][SIZE]);
int isempty(int n[][SIZE]);
int isfull(int n[][SIZE]);
void math(int n[][SIZE],char c);
void tow(int n[][SIZE]);
void toa(int n[][SIZE]);
void tos(int n[][SIZE]);
void tod(int n[][SIZE]);
//主函數(shù)
int main()
{
int i,j;
int n[SIZE][SIZE];
char c=' ';
for(i=0;iSIZE;i++)
{
for(j=0;jSIZE;j++)
{
n[i][j]=0;
}
}
printf( "***********************\n"
" 2048(%dX%d) \n"
" control:W/A/S/D \n"
"press any key to begin \n"
"***********************\n",SIZE,SIZE);
getch();
system("cls");
//n[0][1]=2048;
//n[0][3]=2048;
while(1)
{
if(isempty(n))
getn(n);
putn(n);
if(!isempty(n)isfull(n))
break;
sleep(200);
c=getch();
while(c!='w'c!='a'c!='s'c!='d')
c=getch();
math(n,c);
system("cls");
}
printf(" Game Over!\n",score);
return 0;
}
//函數(shù)
void putn(int n[][SIZE])
{
int i,j;
for(i=0;iSIZE;i++)
{
for(j=0;jSIZE;j++)
printf("| ");
printf("|\n");
for(j=0;jSIZE;j++)
{
if(n[i][j]==0)
printf("| ");
else
printf("|%4d ",n[i][j]);
}
printf("|\n");
for(j=0;jSIZE;j++)
printf("|_____");
printf("|\n");
}
printf("score: %d",score);
}
void getn(int n[][SIZE])
{
int a,b;
a=rand()%SIZE;
b=rand()%SIZE;
while(n[a][b]!=0)
{
a=rand()%SIZE;
b=rand()%SIZE;
}
n[a][b]=2;
}
int isempty(int n[][SIZE])
{
int i,j,count=0;
for(i=0;iSIZE;i++)
for(j=0;jSIZE;j++)
if(n[i][j]==0)
count++;
return count;
}
int isfull(int n[][SIZE])
{
int i,j,count=0;
for(i=0;iSIZE;i++)
{
for(j=1;jSIZE-1;j++)
{
if(n[i][j]==n[i][j+1]||n[i][j]==n[i][j-1])
count++;
}
}
for(j=0;jSIZE;j++)
{
for(i=1;iSIZE-1;i++)
{
if(n[i][j]==n[i+1][j]||n[i][j]==n[i-1][j])
count++;
}
}
return count0?0:1;
}
void math(int n[][SIZE],char c)
{
switch(c)
{
case 'w':tow(n);break;
case 'a':toa(n);break;
case 's':tos(n);break;
case 'd':tod(n);break;
default :;
}
}
void tow(int n[][SIZE])
{
int i,j,a;
int m[SIZE];
for(a=0;aSIZE;a++)
m[a]=0;
for(j=0;jSIZE;j++)
{
for(a=0;aSIZE;a++)
{
for(i=0;iSIZE-1;i++)
{
if(n[i][j]==0)
{
n[i][j]=n[i+1][j];
n[i+1][j]=0;
}
}
}
}
for(j=0;jSIZE;j++)
{
for(a=0,i=0;iSIZE;i++)
{
if(n[i][j]!=n[i+1][j]n[i][j]!=0||n[i][j]==2048)
{
m[a++]=n[i][j];
n[i][j]=0;
}
else if(n[i][j]==n[i+1][j])
{
m[a++]=n[i][j]+n[i+1][j];
score+=m[a-1];
n[i][j]=0,n[i+1][j]=0;
}
}
for(i=0;iSIZE;i++)
{
n[i][j]=m[i];
m[i]=0;
}
}
}
void toa(int n[][SIZE])
{
int i,j,a;
int m[SIZE];
for(a=0;aSIZE;a++)
m[a]=0;
for(i=0;iSIZE;i++)
{
for(a=0;aSIZE;a++)
{
for(j=0;jSIZE-1;j++)
{
if(n[i][j]==0)
{
n[i][j]=n[i][j+1];
n[i][j+1]=0;
}
}
}
}
for(i=0;iSIZE;i++)
{
for(a=0,j=0;jSIZE;j++)
{
if(n[i][j]!=n[i][j+1]n[i][j]!=0||n[i][j]==2048)
{
m[a++]=n[i][j];
n[i][j]=0;
}
else if(n[i][j]==n[i][j+1])
{
m[a++]=n[i][j]+n[i][j+1];
score+=m[a-1];
n[i][j]=0,n[i][j+1]=0;
}
}
for(j=0;jSIZE;j++)
{
n[i][j]=m[j];
m[j]=0;
}
}
}
void tos(int n[][SIZE])
{
int i,j,a;
int m[SIZE];
for(a=0;aSIZE;a++)
m[a]=0;
for(j=SIZE-1;j=0;j--)
{
for(a=SIZE-1;a=0;a--)
{
for(i=SIZE-1;i0;i--)
{
if(n[i][j]==0)
{
n[i][j]=n[i-1][j];
n[i-1][j]=0;
}
}
}
}
for(j=SIZE-1;j=0;j--)
{
for(a=SIZE-1,i=SIZE-1;i=0;i--)
{
if(n[i][j]!=n[i-1][j]n[i][j]!=0||n[i][j]==2048)
{
m[a--]=n[i][j];
n[i][j]=0;
}
else if(n[i][j]==n[i-1][j])
{
m[a--]=n[i][j]+n[i-1][j];
score+=m[a+1];
n[i][j]=0,n[i-1][j]=0;
}
}
for(i=SIZE-1;i=0;i--)
{
n[i][j]=m[i];
m[i]=0;
}
}
}
void tod(int n[][SIZE])
{
int i,j,a;
int m[SIZE];
for(a=0;aSIZE;a++)
m[a]=0;
for(i=SIZE-1;i=0;i--)
{
for(a=SIZE-1;a=0;a--)
{
for(j=SIZE-1;j0;j--)
{
if(n[i][j]==0)
{
n[i][j]=n[i][j-1];
n[i][j-1]=0;
}
}
}
}
for(i=SIZE-1;i=0;i--)
{
for(a=SIZE-1,j=SIZE-1;j=0;j--)
{
if(n[i][j]!=n[i][j-1]n[i][j]!=0||n[i][j]==2048)
{
m[a--]=n[i][j];
n[i][j]=0;
}
else if(n[i][j]==n[i][j-1])
{
m[a--]=n[i][j]+n[i][j-1];
score+=m[a+1];
n[i][j]=0,n[i][j-1]=0;
}
}
for(j=SIZE-1;j=0;j--)
{
n[i][j]=m[j];
m[j]=0;
}
}
}
需要注意的是:
srand((unsigned) time(0);rand();是固定形式,不要更改任何一個(gè)字符!
如果不能編譯,請(qǐng)把sleep(200);注釋掉,如果提示不能找到system("cls");請(qǐng)把system("cls")更換為clrscr()。
c語言中沒有類,只有結(jié)構(gòu),也可以像類一樣編寫,用結(jié)構(gòu),但其成員都是公開訪問的,C++才有真正的類。
當(dāng)前名稱:c語言tow函數(shù)用法 c語言todo語句
本文來源:http://m.kartarina.com/article38/hgjgpp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營銷、網(wǎng)站改版、企業(yè)建站、網(wǎng)站內(nèi)鏈、微信小程序、用戶體驗(yàn)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
移動(dòng)網(wǎng)站建設(shè)知識(shí)