欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C語言

當前位置:主頁 > 軟件編程 > C語言 >

C語言中交換int型變量的值及轉(zhuǎn)換為字符數(shù)組的方法

來源:本站原創(chuàng)|時間:2020-01-10|欄目:C語言|點擊: 次

不使用其他變量交換兩個整型的值:

#include <stdio.h> 
 
void main(){ 
  int a = 3; 
  int b = 4; 
 
  a = a ^ b;//使用異或交換 
  b = b ^ a; 
  a = a ^ b; 
 
  printf("%d, %d\n", a, b); 
 
  a = a - b;//使用加減交換 
  b = a + b; 
  a = b - a; 
 
  printf("%d, %d\n", a, b); 
 
  a ^= b ^= a ^= b; 
 
  printf("%d, %d\n", a, b); 
} 

整形和字符數(shù)組型轉(zhuǎn)換:

#include <stdio.h> 
#include <stdlib.h> 
 
int sumof1(int x)//求一個數(shù)轉(zhuǎn)換成二進制以后1的個數(shù) 
{ 
  int countx = 0; 
  while(x) 
  { 
    countx ++; 
    x &= x-1; //每位與一次x - 1;就能消掉最后一個1 
  } 
  return countx; 
} 
 
void main(){ 
 
  char c[10]; 
  int i = 999; 
 
  itoa(i, c, 10);//以10進制轉(zhuǎn)換成字符數(shù)組 
  puts(c); 
 
  itoa(i, c, 16);//以16進制轉(zhuǎn)換成字符數(shù)組 
  printf("0x%s\n", c); 
 
  itoa(i, c, 8);//以8進制轉(zhuǎn)換成字符數(shù)組 
  printf("0%s\n", c); 
 
  itoa(i, c, 2);//以2進制轉(zhuǎn)換成字符數(shù)組 
  puts(c); 
 
  i = atoi(c);//再將字符串轉(zhuǎn)成整形 
  printf("%d\n", i); 
 
  printf("%d\n", sumof1(i));//以2進制表示時1的個數(shù) 
} 

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時內(nèi)進行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負任何責任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有