Here is all my code but I get a error with N/=10
it says:assignment of read-only parameter N
I don't know how to deal with it - #include<stdio.h>
-
#include<math.h>
-
int number(const int N);
-
int main()
-
{
-
int n1,n2,i,cnt;
-
scanf("%d %d",&n1,&n2);
-
cnt=0;
-
for(i=n1;i<n2;i++)
-
{
-
if(number(i))
-
cnt++;
-
}
-
printf("cnt=%d\n",cnt);
-
return 0;
-
}
-
-
int number(const int N)
-
{
-
int x,y;
-
int num[50]={0};
-
int b=10,count=0;
-
for(int j=1;;j++) //计算输入数值的总位数
-
{
-
if(N%b!=0) count+=1;
-
else break;
-
b/=10;
-
}
-
for(int y=0;y<count;y++) //将每一位 分别存储在数组中
-
{
-
int c=N%b;
-
num[y]=c;
-
N/=10;
-
}
-
for(y=0, x=count-1;y<count,x>=0;y++,x--)
-
{
-
if((num[y]==num[x])&&(sqrt(N)==(int)sqrt(N))) return 1;
-
else return 0;
-
}
-
}
2 5613 Frinavale 9,735
Recognized Expert Moderator Expert
Your variable N is a const .
A constant, like a variable, is a memory location where a value can be stored. Unlike variables, constants never change in value.
Therefore, you cannot do this:
Or this:
Because you can never set N after it is initialized.
donbock 2,426
Recognized Expert Top Contributor
What do you hope to accomplish by declaring int number(const int N)?
C is a call-by-value language. From the caller’s point-of-view, its arguments are safe from alteration by number regardless of const in the declaration. const can be meaningful with pointer arguments but that isn’t the case here.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Michael SL |
last post by:
I have a text area in which I have a client side javascript to process a "onclick". Because it is client side, I used a HtmlTextArea
<TextArea id="Summary" onmouseup="SumMouseUp()" style="WIDTH: 90%" name="Summary" rows="25" runat="server" /
Depending on the circumstance the user can sometimes edit the contents and at other time they cannot. There is a readonly parameter I can use at definition time
<TextArea id="Summary"...
|
by: Richard Grant |
last post by:
Hi. In c/C++ i can pass the address of a subroutine to another subroutine as an actual parameter
How do I do that in VB .NET
What should be the syntax for a parameter to receive the address of a subroutine
Let's say theres a sub that creates buttons and I want it to receive as a parameter the address of the sub that handles the OnClick event for the button being created
How do I pass such a parameter
Thanks in advance
Richar
|
by: DareDevil |
last post by:
I have written a method that should modify the folder path passed to it into one that exists and is selected by the user. It then returns a boolean depending on whether a folder path was selected by the user
It then dawned on me that I was passing in a readonly property into the method yet neither at compile time or runtime was I getting any kind of error or warning.
I tested with a simple string field and it alter the string as expected but...
|
by: Eugene |
last post by:
Hi, how can I declare in the method parameter and pass an object using ByVal
and ensure that the called method cannot change the value of the object. I
wouldn't want the called method to change the data member of the class or
change the properties when windows form is passed in.
Eugene
|
by: Brien King |
last post by:
If I have a parameter that has an Object type (as opposed to something like
a string), can I make that parameter a CONST?
Right now, if you pass an object into a sub/function, that sub/function can
modify the object no matter how it's defined (ByVal or ByRef).
In some cases, I want to make sure that you cannot modify the object. Is
there a way to do that in VS2003 or the up comming VS2005?
| |
by: Charlie |
last post by:
Hi:
I'm using the ObjectDataSource control to databind a Repeater. The method
on business object that ObjectDataSource control point to takes as a
parameter an instance of the System.Data.CommandType enumeration. When
setting up declaritively in HTML, how do I complete the following parameter
assignment...
<asp:Parameter Name="commandType" Type="Object" DefaultValue="????" />
|
by: sunil |
last post by:
Hello,
I am new to c# . I have some basic programming doubts. Please help me
in clarifying these doubts.
I want to initialize a static and readonly field with a value returned
by a static method. How ever, when I am debugging, that method is not
being called. So I am not able to figure out, whether the field is
getting initialized properly or not. Please explain this behavior
Thanks in advance
|
by: Ismail |
last post by:
Hello,
I have grid view which can go into edit mode. I have fields one of
which is primary key I dont want to display this field but will use
this field in my update method. If I make the bound column readonly i
get nulls if i set visible to false i get nulls. When visible and not
readonly i get value however I dont want people trying to change
unique ids. Here is some code
<asp:GridView ID="dgMembers" runat="server"
|
by: Weeble |
last post by:
I was surprised to discover today that local variables can't be
"readonly". (They can be "const", but that's only for compile-time
constants, not something that might be calculated at run-time.) I
would have expected such a variable to allow assignment via an
initialiser, but to be readonly for the remainder of the method, i.e.
it would be an error to place it on the left of an assignment or to
use it as an out parameter. This would be...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |