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

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

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

2019-11-09 21:04:14
字體:
供稿:網(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語言之輾轉(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ā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 罗田县| 万州区| 攀枝花市| 隆安县| 天祝| 孙吴县| 禄丰县| 镇沅| 大安市| 慈溪市| 东山县| 自治县| 二手房| 武威市| 土默特右旗| 宁明县| 西城区| 双牌县| 平远县| 宜州市| 怀宁县| 望江县| 温泉县| 永年县| 玉林市| 芮城县| 灵寿县| 文成县| 永善县| 洛川县| 马鞍山市| 屏山县| 花莲县| 府谷县| 油尖旺区| 广宗县| 建阳市| 河曲县| 通城县| 万荣县| 瓮安县|