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. 8 1707
"engaref" <na*****@hotmai l.com> wrote in message
news:11******** *************@z 14g2000cwz.goog legroups.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.
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;
}
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.
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,
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?
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.the se are all
new for me.
bye
Michael Mair <Mi**********@i nvalid.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_Keit h) 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.
Keith Thompson wrote: Michael Mair <Mi**********@i nvalid.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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 beautiful script
"http://javascript.internet.com/navigation/toolbar-menu.html". It
works like a charm. I made my webpage in frames, where the nav-frame
shows the menubar, so whenever I click a link in the menubar, it opens
in the frame below. But...
|
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 your Visual Studio and compile it + run it; so
you can see what the actual problem is.
Thanks.
code:
|
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 location in the
file.
What is happening, is I can read the file, either in entirety or only
part of it. And no matter what I try setting the position to, using
fsetpos, it always gets set back to the very beginning of the file. I
|
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 process this .txt file.
Goal:
I am working on a vba script to:
|
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 receive a byte array as one of its
parameters. The project is marked for COM interop, and that all
proceeds normally.
When I reference the type library in the VB6 project, and write the
code to call the function that returns the byte array, it works
| |
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 with GCC
(Cygwin and Linux) and my problem is when i try do this
int main(int argc, char **argv) {
array<std::stringa(10);
a = "Huhuhu"; <--- with gcc i got a crash !
|
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 use
to run a UM program, I kept on getting error messages. I have used
someone else's implementation and it runs fine. I have compared my
code with other's and I still can't figure it out what's wrong with
mine. So please help me out, after 3...
|
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 *after* calling increase_arrays(), I
received segmentation fault. I tried to step it through gdb, and I
found out that after calling increase_arrays(), words's original
value is modified, and if I tried to access it, I get <address 0x11
out of...
|
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
works fine (see below). So what is the problem? I get a null
reference on the line below at *!&!* "Unhandled Exception:
System.NullReferenceException: Object reference not set to
an instance of an object.?
RL
|
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???
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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: 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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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: 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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |