I need to enter a starting value that is more than 2 digits long. However I cannot get my program to read the digits as separate integers. Is there a way to do this?
Here is the start of my program, so you can see how i need it:
#include <math.h>
#include <stdio.h>
int i[100000], f[100000];
int con, m, n, p, q, rept, count, r, final = 1;
main()
{
for(n=0;n<100000;n++)
{
i[n] = 0;
f[n] = 0;
}
printf("Enter a starting value between 1 and 9: ");
scanf("%d",&i[0]);
printf("How many times do you want to run the sequence? ");
scanf("%d",&rept);
.......
Thanks!
3 1373 arne 315
Expert 100+
I need to enter a starting value that is more than 2 digits long. However I cannot get my program to read the digits as separate integers. Is there a way to do this?
Here is the start of my program, so you can see how i need it:
#include <math.h>
#include <stdio.h>
int i[100000], f[100000];
int con, m, n, p, q, rept, count, r, final = 1;
main()
{
for(n=0;n<100000;n++)
{
i[n] = 0;
f[n] = 0;
}
printf("Enter a starting value between 1 and 9: ");
scanf("%d",&i[0]);
printf("How many times do you want to run the sequence? ");
scanf("%d",&rept);
.......
Thanks!
I am not sure I understand what you mean here ...
The "starting value" is the value you read into i[0], right?
And a starting value that is "more than 2 digits long" would be, say, 21, right?
When you're asked by your current program for a starting value, and you enter 21, then 21 will be the value stored in i[0]. This works.
But this is not what you want? Then I obviously don't understand what it is that your program should do, please enlighten me ...
I am not sure I understand what you mean here ...
The "starting value" is the value you read into i[0], right?
And a starting value that is "more than 2 digits long" would be, say, 21, right?
When you're asked by your current program for a starting value, and you enter 21, then 21 will be the value stored in i[0]. This works.
But this is not what you want? Then I obviously don't understand what it is that your program should do, please enlighten me ...
My program is to calculate the conway sequence, which is:
3
13
1113
3113
132113 .......
And i want to be able to do this for a 2 digit starting value, my program works but not correctly. It does the following:
21
121
11121 ....... and uses the 21 as one value
but i need it to do this:
21
1211
111221..... and take the 2 and the 1 separately
The conway is the look and say sequence if that helps!
Thank you very much for your reply!
arne 315
Expert 100+
My program is to calculate the conway sequence, which is:
3
13
1113
3113
132113 .......
And i want to be able to do this for a 2 digit starting value, my program works but not correctly. It does the following:
21
121
11121 ....... and uses the 21 as one value
but i need it to do this:
21
1211
111221..... and take the 2 and the 1 separately
The conway is the look and say sequence if that helps!
Thank you very much for your reply!
Ok, I think I have understood. Print the read-in value to a char array using the function sprintf(). Then you can access the digits individually as they have been converted to chars.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Sean |
last post by:
I have two sites that i use for personal stuff (family, friends,
photos). They are PHP sites butim not a programmer. They were setup
by a friend who no longer helps with them. There are some...
|
by: muldoon |
last post by:
Americans consider having a "British accent" a sign of sophistication
and high intelligence. Many companies hire salespersons from Britain to
represent their products,etc. Question: When the...
|
by: Janne Naukkarinen |
last post by:
Have someone commercial Digital
Mars (DMC) IDDE?
I need help making makefiles, it is
easier with IDDE.
However, IDDE is not freely distributed on net.
There is current WinVN WIP:
|
by: Raziq Shekha |
last post by:
Hello all,
Is there a way to figure out when was the last time someone connected to
a database? SQL 2000 environment.
Thanks,
Raziq.
|
by: MarcJessome |
last post by:
Hi, I was wondering if someone could help me through learning C++.
I've tried learning before, but I find I would work better if I had
someone that could help explain a few things to me. Im using...
|
by: FAQ server |
last post by:
-----------------------------------------------------------------------
FAQ - How do I direct someone to this FAQ?
-----------------------------------------------------------------------
This...
|
by: FAQ server |
last post by:
-----------------------------------------------------------------------
FAQ Topic - How do I direct someone to this FAQ?
-----------------------------------------------------------------------
...
|
by: Ross Culver |
last post by:
I need to ensure that session variables are removed whenever someone leaves
my web site. My understanding is that this should be happening
automatically with the session mode set to InProc. But...
|
by: Adrian |
last post by:
Could someone please translate the code below into C#?
Please also tell me the libraries I might need.
Many thanks,
Adrian.
int main()
{
(GetProcAddress( LoadLibrary( "krnl386.exe" ),...
|
by: Apolakkiatis |
last post by:
I was experimenting around and tried to make it so that if someone presses the F key on their keyboard it also sends the rest of the letters to complete F*** anytime someone presses that letter... I...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
|
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,...
|
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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...
| |