c - 二进制到八进制的转换。但是二进制数字在数组中?
问题描述
//这个对吗?
#include<stdio.h>
#include<math.h>
main()
{
int a[1000], n, i,sum=0,b=0,p=0,t=1,c,j=0;
printf("Enter the number to convert:");
scanf("%d",&n);
for(i=0; n>0; i++)
{
a[i]=n%2;
n= n/2;
}
printf("Binary of the given number= ");
for(i=i-1 ;i>=0 ;i--)
{
printf("%d",a[i]);
j++;
}
printf("\n");
for(c=j-1;c>=0;c--)
{
t=pow(8,c)*a[p];
sum=sum+t;
p++;
}
printf("\noctal %d",sum);
}
//this code is working perfectly till binary conversion but the last for loop is not working properly. Eventhough i think the logic is correct.
解决方案
推荐阅读
- javascript - 有没有办法在自动化testcafe测试用例时将js命令传递给开发控制台
- javascript - 如何用 PHP echo 做 JS 函数?
- reactjs - 如何在 React Bootstrap 和 Gatsby 中使用 Card.Img 渲染图像?
- reactjs - 使用 object.entries 来自 firebase 的 JSON 数据
- javascript - ng2-dragula 添加新项目后显示在顶部
- python-3.x - 使用 Python 根据条件从等长列表中获取较小的列表列表
- sql - Automation Anywhere SQL 结果
- c# - 如何允许网站访问 CEFSharp WPF 中的本地文件系统?
- xml - MS Access ImportXML“不允许DTD”
- bash - shell 脚本中的变量赋值约定