Hi,
I am also new with C.I am studying the C in course.
I performed this solution just as Practice to me.
I found this Problem among messages from this page on Dec.27.
The Problem says:
Declare an array a[10], insert the first element of the array into the
position specified by a following integer and print the contents.
output Example:
1 2 3 4 5 6 7 8 9 10
4
2 3 4 1 5 6 7 8 9 10
I tried .the result showed the error in output and it print the
different output and not the same as said.
then what would be the best way to do that?what is the most proper
alternative way to pay for this problem?
Thanks for all.
My Proposed solution is as follows:
#include <stdio.h>
int main ()
{
int a[10], x;
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');
x = a[0];a[0]= a[1]; a[1]=a[2];
a[2]=a[3];a[3]=x;
for(i=0; i<10; i++){
printf("%d ",a[i]);
}
putchar('\n');
return 0;
}
---
John 3 1052
> Declare an array a[10], insert the first element of the array into the position specified by a following integer and print the contents. output Example: 1 2 3 4 5 6 7 8 9 10 4 2 3 4 1 5 6 7 8 9 10
I tried .the result showed the error in output and it print the different output and not the same as said. then what would be the best way to do that?what is the most proper alternative way to pay for this problem?
Cash in an envelop is the best. I will take Paypal. The amount is up to you.
for(i=0; i<10; i++){ scanf(" %d", &a[i]); --- for testing, just do a[i] = i; } x = a[0];a[0]= a[1]; a[1]=a[2]; a[2]=a[3];a[3]=x; ---- > assuming the input was 4 is not good. Get it from
the user, then use a loop to copy. Flexibility is what you want.
Here is my version that seems to do what you want.
#include <stdio.h>
int main ()
{
int a[10], x, temp;
int i;
for(i=0; i<10; i++){
a[i] = i;
printf("%d ",a[i]);
}
printf("\nEnter a number:");
scanf("%d", &x);
if(x>=10) return 1;
temp = a[0];
for (i=0;i<x;i++)
a[i] = a[i+1];
a[x-1] = temp;
for(i=0; i<10; i++)
printf("%d ",a[i]);
printf("\n");
return 0;
}
Thanks Jon Yi,
But I was asked on starting from 1 and not zero.
as you put:
int i;
for(i=0; i<10; i++){
a[i] = i;
printf("%d ",a[i]);
it bring the output from 0 to 9.
now,I am asking if i put like this:
a[i]=i +1
then,the out put will show:
1 2 3 4 5 6 7 8 9 10
what do you think about?Is it a correct way or no?
Cheers!
John
}
On Wed, 29 Dec 2004 01:13:30 -0800, John wrote: Thanks Jon Yi, But I was asked on starting from 1 and not zero. as you put: int i; for(i=0; i<10; i++){ a[i] = i; printf("%d ",a[i]);
it bring the output from 0 to 9. now,I am asking if i put like this:
a[i]=i +1
then,the out put will show: 1 2 3 4 5 6 7 8 9 10 what do you think about?Is it a correct way or no?
Yes, that's fine. If you need to read the numbers in you can still do it
as you did originally.
Lawrence This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Matt Kruse |
last post by:
http://www.mattkruse.com/temp/css_expressions.html
One of the standard CSS questions is "how can I shade every other table row
a different color with CSS?"
The answers are usually 1) you can't...
|
by: Mark |
last post by:
Is there a realistic way for some developers on our team to work with
multiple projects in a single solution under VSS source control, and have
other developers only working with a single project...
|
by: kai |
last post by:
Hi,
I use XP Pro and VS2005. I find when I create a new Website, I only see the
Project node not Solution. After I add sedcond project under the solution
tree, then I see the solution node.
How...
|
by: Tom C |
last post by:
In the visual studio IDE, how do I delete a whole solution using Solution
Explorer? I can delete the projects in the solution, but not the solution
itself.
|
by: =?Utf-8?B?VGhpbmtSUzIzMg==?= |
last post by:
We develop professional development libraries. I created a Visual Studio 2005
solution that includes several solution folder with projects.
e.g)
Solution
SolutionFolder1
ProjectA
ProjectB...
|
by: GroupReader |
last post by:
We have a shared solution that is in VSS. The solution contains
several projects in addition to the main website "project".
The solution seems to work fine. All developers can open the solution...
|
by: =?Utf-8?B?SmVmZnJleQ==?= |
last post by:
I made a typo on a Project name (e.g. Wong, instead of Wang). Later on I
renamed the Soution, Project, WebForm., etc, except the file folder name,
back to Wang. Then after I closed the VS.net and...
|
by: Ronald S. Cook |
last post by:
If I choose not to include a dependent project in my solution, but rather
just reference the .dll in that project's bin\debug folder, are there any
negative repercussions?
Or, is it more...
|
by: techie |
last post by:
List of Solution manuals:
Engineering Circuit Analysis 6Ed - Hayt Solutions Manual
Norbury - Solutions manual for mechanics and thermodynamics
Physics For Scientists And Engineers - Solution...
|
by: =?Utf-8?B?RHdlZWJlcmVsbGE=?= |
last post by:
I created an Access 2007 application for my customer. The application is
shared by three employees on a server. It maintains a contact list including
financial data and social security numbers. ...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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...
| |