473,508 Members | 2,298 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

assignment of read-only parameter N

1 New Member
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

Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<math.h>
  3. int number(const int N);
  4. int main()
  5. {
  6.     int n1,n2,i,cnt;
  7.     scanf("%d %d",&n1,&n2);
  8.     cnt=0;
  9.     for(i=n1;i<n2;i++)
  10.     {
  11.         if(number(i))
  12.         cnt++;
  13.     }
  14.     printf("cnt=%d\n",cnt);
  15.     return 0;
  16.  } 
  17.  
  18.  int number(const int N)
  19.  {
  20.      int x,y;
  21.      int num[50]={0};
  22.      int b=10,count=0;
  23.      for(int j=1;;j++)              //计算输入数值的总位数 
  24.      {
  25.          if(N%b!=0) count+=1;
  26.          else break;
  27.          b/=10;
  28.     }
  29.      for(int y=0;y<count;y++)      //将每一位 分别存储在数组中 
  30.      {
  31.          int c=N%b;
  32.          num[y]=c;
  33.          N/=10;
  34.     }
  35.      for(y=0, x=count-1;y<count,x>=0;y++,x--)
  36.      {
  37.          if((num[y]==num[x])&&(sqrt(N)==(int)sqrt(N))) return 1;
  38.          else return 0;
  39.      }
  40.  }
Feb 22 '18 #1
2 5580
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:
Expand|Select|Wrap|Line Numbers
  1. N/=10;
Or this:
Expand|Select|Wrap|Line Numbers
  1. N=N/10;
Because you can never set N after it is initialized.
Feb 22 '18 #2
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.
Feb 23 '18 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
7100
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:...
7
9542
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...
7
2464
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...
8
2526
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...
20
5012
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...
2
1713
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...
10
7841
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...
2
6280
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...
8
1867
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...
0
7123
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...
0
7324
Oralloy
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,...
0
7382
jinu1996
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...
0
7495
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
3193
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...
0
3181
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1556
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 ...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.