国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

c語(yǔ)言之輾轉(zhuǎn)相除法實(shí)現(xiàn)十進(jìn)制轉(zhuǎn)換為八進(jìn)制

2019-11-10 16:59:14
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <string.h>#include <stdlib.h>void Convert_8_001(int n){#define LEN sizeof(unsigned int)* 4	char result[LEN + 1] = { 0 };	int mod;	char* p = result;	for (int i = LEN - 1; i >= 0; --i)	{		mod = n % 8;		result[i] = mod + '0';		n /= 8;		if (n == 0)		{			p = p + i;			break;		}	}	PRintf("%s/n", p);}void Convert_8(int n){#define LEN sizeof(unsigned int)* 4	char result[LEN + 1] = { 0 };	char* p = result;	int count = 0;	while (n)	{		int mod = n % 8;		result[LEN - count-1] = mod + '0';		count++;		n = n / 8;	}	//移動(dòng)指針指向數(shù)組后面的8進(jìn)制。	p =p+ LEN-count;	printf("%s/n", p);}//輸入一個(gè)整數(shù),將其轉(zhuǎn)換成八進(jìn)制數(shù)輸出。//c語(yǔ)言之輾轉(zhuǎn)相除法實(shí)現(xiàn)十進(jìn)制轉(zhuǎn)換為八進(jìn)制int main(){	unsigned int n;	while (scanf("%d", &n) != EOF)	{		Convert_8(n);	}	return 0;}

#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <string.h>#include <stdlib.h> int main(){    long int n;    while (scanf("%d", &n) != EOF)    {        if (n == 0)        {            printf("0/n");            continue;        }        char result[12] = { 0 };        while (n)        {            int m = n % 8;             char t[2] = {0};            sprintf(t, "%d", m);            strcat(result, t);            n= n / 8;        }        //字符串逆序        int len = strlen(result);        for (int i = 0; i < len/2; i++)        {            char tmp=result[i];            result[i] = result[len-i -1];            result[len-i-1] = tmp;        }        //strcpy(result,_strrev(result));//逆序        printf("%s/n", result);             }    return 0;}添加筆記


發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 晋江市| 遂川县| 泸定县| 松桃| 太仓市| 通榆县| 太保市| 昌江| 山丹县| 石首市| 泰和县| 资兴市| 工布江达县| 普定县| 萨迦县| 苗栗县| 红桥区| 剑阁县| 义乌市| 神池县| 日喀则市| 华安县| 陆丰市| 怀集县| 贞丰县| 平定县| 慈溪市| 辉南县| 中卫市| 红桥区| 卓尼县| 乃东县| 屏东市| 望谟县| 新河县| 米林县| 铜川市| 蒙自县| 灵石县| 仪征市| 崇仁县|