473,387 Members | 1,590 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,387 software developers and data experts.

Reading the data from keyboard!

Hi all,

I got totally confusion on the following code:
#include <stdio.h>

#define MAX 1000

main()
{
int n, a[MAX], i, j;

scanf("%d", &n);

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

/* find the index j here */

printf("%d\n", j);
}

I want to get the following outputs:
For example:

5 3 2 1 4 5
3
or:
6 6 3 1 4 2 5
5

or:
4 3 2 1 4
3
or"

10 10 9 8 7 6 5 4 3 2 1
10

In fact, I am going to solve this problem by the
follow-up code,but it has some mistake.

-----------------------------------------------------

The Problem says:

[Write a C program that reads the number of data "n" and
the data themselves "d1", "d2", ...,"dn" from the keyboard
and stores them into an array.
Then it finds the index "j"that satisfies the inequations:

d(j-1) > dj < d(j+1) < ... < d(n-1) < dn

and reports "j".]
----------------------------------------------------------
So,If you know the proper way to pay for this solutions,
please show them with kindness.

Tanx in advance!

John

Nov 14 '05 #1
2 2034
John <na*****@hotmail.com> wrote:
Hi all, I got totally confusion on the following code:
What does confuse you? You haven't actually told us.
#include <stdio.h> #define MAX 1000 main() int main() {
int n, a[MAX], i, j; scanf("%d", &n); for (i = 0; i < n; i++)
scanf("%d", &a[i]); /* find the index j here */ printf("%d\n", j);
}
Your code seems to me generally correct.

I want to get the following outputs:
For example: [snip examples]

In fact, I am going to solve this problem by the
follow-up code,but it has some mistake.
Why haven't you sent it here then?
----------------------------------------------------- The Problem says: [Write a C program that reads the number of data "n" and
the data themselves "d1", "d2", ...,"dn" from the keyboard
and stores them into an array.
Then it finds the index "j"that satisfies the inequations: d(j-1) > dj < d(j+1) < ... < d(n-1) < dn and reports "j".]
Hints: d(j) is the minimal element in the range [(j-1), n].
There might be more than one solution. Perhaps the fastest
(and easiest) way is to search backwards from the end.
----------------------------------------------------------
This is an algorithms problem and is off-topic in c.l.c.
See "Welcome ..." message for directions.
So,If you know the proper way to pay for this solutions,
please show them with kindness.


The proper way to solve the assignment would be: sit down and
solve it yourself. A pencil and paper might help.

--
Stan Tobias
mailx `echo si***@FamOuS.BedBuG.pAlS.INVALID | sed s/[[:upper:]]//g`
Nov 14 '05 #2
Interesting advice!
he wrote the problem to make the matter clear.
he may do not expect the "fun" from yours side:
sit down and
solve it yourself. A pencil and paper might help.


thanks

Nov 14 '05 #3

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

Similar topics

3
by: Simon | last post by:
Using qbasic, the following accepts input from com1, and prints its output : OPEN "com1:9600,n,8,1,CD0,CS0,DS0,RS" FOR INPUT AS #1 WHILE INKEY$ <> " " INPUT #1, a$ PRINT a$ WEND What...
0
by: Jaywant Dharwadkar | last post by:
We are developing a Web application on J2EE platform and require to support cetain peripheral devices such as MAGTEK PinPad and Card Swipe (http://www.magtek.com/) connected to a PC port. I am...
2
by: Michael Bendzick | last post by:
Is there a simple way in python to read a keyboard scan code? I'm working on a shell script that interfaces with a proprietary keyboard device (extra buttons) and need to be able to distinguish...
50
by: Michael Mair | last post by:
Cheerio, I would appreciate opinions on the following: Given the task to read a _complete_ text file into a string: What is the "best" way to do it? Handling the buffer is not the problem...
40
by: googler | last post by:
I'm trying to read from an input text file and print it out. I can do this by reading each character, but I want to implement it in a more efficient way. So I thought my program should read one...
0
by: rs | last post by:
Hi guys, I am trying to read from a USB keyboard using vb.net and HID classes. the USB keyboard is not my primary keyboard. I have a ps2 keyboard connected and is detected in device manager as...
2
by: rs | last post by:
Hi guys, I am trying to read from a USB keyboard using vb.net and HID classes. the USB keyboard is not my primary keyboard. I have a ps2 keyboard connected and is detected in device manager as...
0
by: Chris Herring | last post by:
I am writing a WinForms app that will integrate a handheld voting device system into the app. The handhelds communicate to the PC via a USB connection. The USB device has no manufacturer driver,...
9
by: perpetualsoft | last post by:
hey guys i have a big problem,actually I m developing a software for my a client. this is verfication of RFID card via PS/2 port its reader. I can read data from card easily when application is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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...
0
BarryA
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...
1
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...
0
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...
0
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...

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.