473,322 Members | 1,496 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Problem on Array

Hello Every body,
I am new with C programming.I have received the Problems from my
advisor on Array
but I did not find any Proper answer yet.
If Possible,please make a solution for the Problems.

Thanks

The Problems are as follows:
1-Declare an array of length of 10 and read integers into the elements
of array from keyboard(using Scanf).
Then exchange the preceding two elemnt of the array and print the
contents.
Out put Example:
1 2 3 4 5 6 7 8 9 10
2 1 3 4 5 6 7 8 9 10

2-Similear as above,but this time insert the first element of the array
into the fifth position and print the contents.
Output Ex:
1 2 3 4 5 6 7 8 9 10
2 3 4 5 1 6 7 8 9 10

3-Similear as above,but insert the first element of the array into the
position specified by a following integer and print the contents.
output Ex:
1 2 3 4 5 6 7 8 9 10
7
3 5 7 9 2 4 1 6 8 10
4-Declare an array of Length of 10 an read integers into the elements
of the array from keyboard.then read an integer which specifies the
number of repetition.
according to the repetition number,print the contents of the array.

Output Ex:
1 2 3 4 5 6 7 8 9 10
3
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
5- Declare a two-dimensional array "a" of size 10 by 10 and read 10
integers into a[0][0] to a[0][9].then repeat
insertion operation specified by an integers sequence nin times and
store the results from a[1] to a[9].
Finally,print the array.

Nov 14 '05 #1
8 1661

"engaref" <na*****@hotmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
Hello Every body,
I am new with C programming.I have received the Problems from my
advisor on Array but I did not find any Proper answer yet.


That's too bad.

Unfortunately, people around here are much too busy to do *your* homework.
As soon as you have at least *tried* that, people will be unwilling to help
you. First show us what solution you arrived at, or what you have tried.

The problems do not seem overly complicated.
Nov 14 '05 #2
Hi again,
Of Course,this is not the homwork.thius is just for my undestanding and
Practice.
because,I have no experinces with C specailly with Arrays.
By the way,I tried as follows,but is wrong:
#include <stdio.h>

main()
{

int a[10];
int i;
for(i=0; i<10; i++){
scanf("%d", &a[i]);
}
for(i=0; i<10; i++){
printf("%d",a[i],a[0] = a[1]);
}
return 0;
}

Nov 14 '05 #3
Please quote enough context that we know what you are referring to.

Guess:
"
1-Declare an array of length of 10 and read integers into the elements
of array from keyboard(using Scanf).
Then exchange the preceding two elemnt of the array and print the
contents.
Out put Example:
1 2 3 4 5 6 7 8 9 10
2 1 3 4 5 6 7 8 9 10
"

engaref wrote:
Hi again,
Of Course,this is not the homwork.thius is just for my undestanding and
Practice.
because,I have no experinces with C specailly with Arrays.
By the way,I tried as follows,but is wrong:
#include <stdio.h>

main() main() must return int. You return int. But you do not give a return
type for main(). Correct:

int main ()
or
int main (void)

Look for compiler warnings. If there are none, get another
compiler.
{

int a[10];
int i;
for(i=0; i<10; i++){
scanf("%d", &a[i]);
You are not using the return value of scanf().
}
for(i=0; i<10; i++){
printf("%d",a[i],a[0] = a[1]);
Why exactly are you doing that?
You tell printf() with "%d" that you are giving _one_ further argument.
You provide _two_.
a[0] = a[1]
has the effect that the first two array elements are identical.
You want to exchange them. That is, you want to print the "original"
a[0] when i==1.
Thus: Do the exchange first, then do the output:

i=a[0]; a[0]= a[1]; a[1]=[i];
for (i=0; i<10; i++)
printf("%d ",a[i]);
}
return 0;
without output of '\n' before exiting the program, it is possible
that you will not get any output at all. }


Cheers
Michael

____arr1.c_______

#include <stdio.h>

int main (void)
{
int a[10], tmp;
int i;

for(i=0; i<10; i++){
scanf(" %d", &a[i]);
}

putchar('\n');
for(i=0; i<10; i++){
printf("%d ",a[i]);
}
putchar('\n');

tmp = a[0]; a[0] = a[1]; a[1] = tmp;
for(i=0; i<10; i++){
printf("%d ",a[i]);
}
putchar('\n');

return 0;
}

--
E-Mail: Mine is a gmx dot de address.

Nov 14 '05 #4
Dear Mr.Michael,

Thanks a lot for your kind reply and advice.
I understood some on Array by using yours explaination now.
Thanks and Regards,

Nov 14 '05 #5
engaref wrote:
Hello Every body,
I am new with C programming.I have received the Problems from my
advisor on Array
but I did not find any Proper answer yet.
If Possible,please make a solution for the Problems.


If you get other people to do your homework for you, you're going to
stay new with C programming for quite some time.

Don't you agree that you'd learn far more if you tried these for
yourself, and then asked for help on matters that you are "stuck"
with?
Nov 14 '05 #6
Hi,
Thanks for advice.
These are not home work.these are all for my practice.I need help and
advice more.
this is the first time that I am learning the Programming.these are all
new for me.

bye

Nov 14 '05 #7
Michael Mair <Mi**********@invalid.invalid> writes:
[...]
Thus: Do the exchange first, then do the output:

i=a[0]; a[0]= a[1]; a[1]=[i];
for (i=0; i<10; i++)
printf("%d ",a[i]);

[...]

And finding the error in the above code is a good exercise.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #8


Keith Thompson wrote:
Michael Mair <Mi**********@invalid.invalid> writes:
[...]
Thus: Do the exchange first, then do the output:

i=a[0]; a[0]= a[1]; a[1]=[i];
for (i=0; i<10; i++)
printf("%d ",a[i]);


[...]

And finding the error in the above code is a good exercise.

*g* Too hasty...

Thanks for mentioning :-)
Cheers
Michael
--
E-Mail: Mine is a gmx dot de address.

Nov 14 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: JesusFreak | last post by:
From: us_traveller@yahoo.com (JesusFreak) Newsgroups: microsoft.public.scripting.jscript Subject: toolbar script problem NNTP-Posting-Host: 192.92.126.136 Recently, I downloaded the following...
0
by: crawlerxp | last post by:
This is the problem: I do not get the output I need when encoding and decoding data using rijndael alghoritm. Look at the code and see what the problem is actually: Please paste this code into...
8
by: Brady | last post by:
Hi, I'm having a problem reading and writing to a file. What I'm trying to do is read a file, modify the portion of the file that I just read, and then write the modified data back to the same...
8
by: mytfein | last post by:
Hi Everyone, Background: Another department intends to ftp a .txt file from the mainframe, for me to process. The objective is to write a vb script that would be scheduled to run daily to...
8
by: intrepid_dw | last post by:
Hello, all. I've created a C# dll that contains, among other things, two functions dealing with byte arrays. The first is a function that returns a byte array, and the other is intended to...
4
by: daroman | last post by:
Hi Guys, i've problem with my small C++ programm. I've just small template class which represetns a array, everything works fine up to combination with std::string. I did tried it with M$ VC++ and...
5
by: weidongtom | last post by:
Hi, I tried to implement the Universal Machine as described in http://www.boundvariable.org/task.shtml, and I managed to get one implemented (After looking at what other's have done.) But when I...
9
by: weidongtom | last post by:
Hi, I've written the code that follows, and I use the function add_word(), it seems to work fine *before* increase_arrays() is called that uses realloc() to allocate more memory to words. But...
3
by: raylopez99 | last post by:
Below is my problem. I've narrowed it down to one thing: my unfamiliarity on how class instances are instantiated in an array. This is because the "un-array" / "non-array" version of the program...
25
by: biplab | last post by:
Hi all, I am using TC 3.0..there if I declare a integer array with dimension 162*219...an error msg saying that too long array is shown....what should I do to recover from this problem???
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.