首页 \ 问答 \ 基本的嵌套循环计算1 - 239之间的素数(basic nestled loop calculate prime numbers between 1 - 239, inclusive)

基本的嵌套循环计算1 - 239之间的素数(basic nestled loop calculate prime numbers between 1 - 239, inclusive)

我正在制定一个计划,在这个计划中,我必须从1 - 239中打印出包括1和239在内的素数(我知道其中一个或两个可能不是素数,但我们会在此计划中考虑它们)它必须是一个非常简单的程序,因为我们只是讨论了一些基础知识。 到目前为止,我的代码是这样的,这对我来说似乎是体面的逻辑流程,但不产生输出。

#include <iostream>

using namespace std;
int main()
{
int x;
int n = 1;
int y = 1;
int i = 0;

while (n<=239)
    {x = n % y;
    if (x = 0)
        i++;
    if (y < n)
    y++;
    n++;
    while (i == 2)
        cout << n;
    }
return 0;
}

我希望这个工作的方式是取n,只要n等于或小于239,并且预制型模数除以从1到n的每个数字。 每当数字y均匀地进入n时,计数器将增加1.如果计数器等于2,则数字为素数,我们将其打印到屏幕。 任何帮助将非常感激。 谢谢


I am working on a program in which I must print out the number of primes, including 1 and 239, from 1 - 239 ( I know one and or two may not be prime numbers, but we will consider them as such for this program) It must be a pretty simple program because we have only gone over some basics. So far my code is as such, which seems like decent logical flow to me, but doesnt produce output.

#include <iostream>

using namespace std;
int main()
{
int x;
int n = 1;
int y = 1;
int i = 0;

while (n<=239)
    {x = n % y;
    if (x = 0)
        i++;
    if (y < n)
    y++;
    n++;
    while (i == 2)
        cout << n;
    }
return 0;
}

The way I want this to work is to take n, as long as n is 239 or less, and preform modulus division with every number from 1 leading up to n. Every time a number y goes evenly into n, a counter will be increased by 1. if the counter is equal to 2, then the number is prime and we print it to the screen. Any help would be so greatly appreciated. Thanks


原文:https://stackoverflow.com/questions/33176155
更新时间:2024-01-15 21:01

最满意答案

我认为问题是由您将数据添加到$ http调用的方式引起的。 您可以尝试更改控制器功能,如下所示:

controller : function(){
  this.regdata = {};

  //Send Data
  this.addData = function(){
    var url = 'http://url.com/account/register';
    $http.post(url, this.regdata).then(function(dt){
      console.log(dt);
    },function(dt){
    console.log(dt);
    });
  };
}

您不必进行字符串化,因为$ http服务将为您执行此操作。

注意:网址对我不起作用,因此我无法测试该部分代码。


I think the issue is caused by the way you add the data to your $http call. You could try to change your controller function as follow:

controller : function(){
  this.regdata = {};

  //Send Data
  this.addData = function(){
    var url = 'http://url.com/account/register';
    $http.post(url, this.regdata).then(function(dt){
      console.log(dt);
    },function(dt){
    console.log(dt);
    });
  };
}

You do not have to stringify since the $http service will do that for you.

Note: The url is not working for me, so I cannot test that part of the code.

相关问答

更多
  • 我可以在代码中看到两个问题: 您使用JSON.stringify创建JSON内容,但对于表单,您需要使用URLSearchParams类或手动创建字符串内容。 您的内容类型值不正确。 它是application/x-www-form-urlencoded而不是application/x-www-urlencoded 。 以下是您应该使用的内容: sendMail(value: Object): Observable { const body = new URLSearchParams(); ...
  • @Vivek的回复是正确的。 请允许我详细介绍一下细节,以便更好地了解发生的情况: 浏览器使用OPTIONS http动词执行预检请求,这是XHR对象发出的附加请求,以确保允许它实际发出请求。 除非您设置自定义标头,否则没有预检,在设置这些预检时,与授权标头一样,将执行OPTIONS请求。 这个不包括@Vivek在他的回复中指定的那些海关标题。 一旦弄清楚为什么您的端点没有响应预检请求,并且该请求成功,您将看到具有基本身份验证凭据值的Authorization标头。 这是一个jsfiddle ,我向虚拟ap ...
  • 尝试修改angularjs的默认http标头并发出请求。 $http.defaults.headers.common.Authorization = 'token'; Try modifying the default http header of angularjs and make the request. $http.defaults.headers.common.Authorization = 'token';
  • 您可以通过确保正确格式化URL来强制$ http使用HTTPS。 var req = { method: 'POST', url: 'https://localhost/api/v1/users', // note: https specified headers: { 'Content-Type': undefined }, data: { test: 'test' } } angularjs docs - $ https You can force $http to use HTTPS ...
  • 我认为人们不回答你的问题的原因是因为这是一个故事。 简化您的问题,例如:“我不想在我离开页面时收到回复”会增加我的看法。 话虽如此。 你正在寻找的东西叫做取消订阅。 httpClient.post返回一个Observable,您可能会在.subscribe()订阅中返回一个可用于取消订阅的订阅。 例如: @Component({etc.etc}) export class MyComponent implements OnInit, OnDestroy { subscription; const ...
  • 我认为问题是由您将数据添加到$ http调用的方式引起的。 您可以尝试更改控制器功能,如下所示: controller : function(){ this.regdata = {}; //Send Data this.addData = function(){ var url = 'http://url.com/account/register'; $http.post(url, this.regdata).then(function(dt){ console.l ...
  • 你的相对网址的原因很简单,因为你有一个拼写错误,这导致了这一点。 代替 private heroesUrl = "http:localhost:9000/read"; 它应该是 private heroesUrl = "http://localhost:9000/read"; 这里可能不需要其他魔法。 你可能会遇到一个cors问题。 但由于这是一个操场,而不是实际的开发,如果是CORS,你可以在chrome中轻松启用CORS。 但这在现实应用中自然不推荐。 但是对于比赛来说,这样做会很好。 The re ...
  • $scope.loginUser = function() { $scope.statusMsg = 'Sending data to server...'; $http({ url: 'http://##.##.##.##/login', method: 'POST', data: user, headers: {'Content-Type': 'application/json'} }).then(function(r ...
  • 用这个: json_decode(file_get_contents('php://input')); 检查开发人员栏中的网络标签。 您可以看到您在http正文中发送了有效负载数据。 这就是$ _POST数组为空的原因。 Use this: json_decode(file_get_contents('php://input')); Check your network tab in your developer bar. You can see that you send payload data i ...
  • 您的console.log打印与您的请求相对应的observable,但不打印其结果。 如果要打印此结果,可以使用do运算符: createPost(post){ return this._http.post(this._url,JSON.stringify(post)) .map(res=>res.json()) .do(data => { console.log(data); }); } 你说请求已经执行了。 如果你订阅了observable就是这种情况: th ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。