将以下c语言换为C++语言 - 爱问答

(爱问答)

将以下c语言换为C++语言

#include<iostream> 

#include<math.h>

using namespace std;

int main()

{

int a=0,b,i,j,x,n,n1;

long *s=0;

scanf("%ld",&n);

 

s=(long*)malloc(sizeof(long)*(n+2));

 

for(i=0;i<n;i++)

scanf("%d",&s[i]);

 

for(i=0;i<n;i++)

{

b=0;

n1=2;

for (j=3;j<s[i];j++)

{a=0;

for(x=2;x<j;x++)

{

if (j%x==0)

{

a=1;

break;

}

 

}

 

  if (a==0&&j-n1<=2&&j-n1>0)

     { b++;

  n1=j;}

}

printf("%d ",b);

}

free(s);

return 0;

}


printf("%d ",b);

改成cout<<b<<" ";

scanf("%ld",&n);

改成cin>>n;

你都把命名空间用上了,本来就是C++了啊!

相关标签:c语言

下一篇:excel每隔1行、2行、3行、4行取一个单元格,如此循环

上一篇:易语言怎么获取任务栏里已运行的程序?

热门标签:
excel 网盘 破解 word dll
最新更新:
微软重新评估新的Outlook的使用时机 联想推出搭载联发科Helio G80芯片组的Tab M9平板 英特尔创新大赛时间确定! 微软Edge浏览器在稳定渠道中推出Workspaces功能 英伟达RTX4060TiGPU推出MaxSun动漫主题! 谷歌地图为用户提供了街景服务! GameSir 在T4 Kaleid中推出了一款出色的控制器! 微软开始在Windows 11 中测试其画图应用程序的新深色模式! LG电子推出全球首款无线OLED电视 英伟达人工智能芯片崭露头角! Steam Deck可以玩什么游戏-Steam Deck价格限时优惠 雷蛇推出CobraPro鼠标 Kindle电子阅读器可以访问谷歌商店吗 Windows10如何加入组策略 window10图片查看器怎么没有了?