Thread: need some quick help

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    72

    need some quick help

    heya.. I have programming exam tomorrow in C and i've messed up with some notes regrding arrays.. i'm looking for 2 programs basically now .. the first is that how can I display a array in accending order.. for example lets say
    Code:
    arr[6]={22,10,55,9,32,33}
    how do I display this in accending or decending order? all I get from google etc is qsort and bubble sort .. however we are not allowed to use built-in function, i remember last time we did it was something comparision or something.. i totally forgot.. ill be thankful if you can write a program that will do it.. the 2nd thing im looking for is that "a 4 digit number is entered through a keyboard, write a program to reverse it" well i know about the char thing but there's some other logic its like number/100/1000 or something like that.. so if u know about it post it.. thanks .. also i'm confused about array swapping.. like if i have 2 arrays as follows

    Code:
    arr[]={2,3,4,5}
    
    and
    brr[]={3.4.5.6}
    how do i swap their values, like brr should go to arr and arr value should be stored in brr.. i remember the TEMP thing but dunno how exactly to do it, ill be thankful if u can help.. its 9:49 pm here and i have exam tomorrow at 12:15 PM .. and i'll sleep in the next hour so plz hurry and thanks in advance

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Do you know how to make a loop that counts down instead of up?

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    103
    for the first question, I guess you just have to do swapping using a nested loop!!
    try something out..

  4. #4
    Registered User
    Join Date
    Apr 2008
    Posts
    72
    lol
    Code:
    for (i=0; i>=10; i--)
    if thats what u meant? anyways, if anyone can write the programs for the things i mentioned plz do.. i really need them to analyse the logic before the exam tomorow

    thanks

  5. #5
    Super unModrator
    Join Date
    Dec 2007
    Posts
    321
    Quote Originally Posted by salmansalman View Post

    if thats what u meant? anyways, if anyone can write the programs for the things i mentioned plz do..
    That doesn't happen on this board very often. (I know. I have tried )

    EDIT: Looks like this is it. But don't just copy-paste the code, read the whole tutorial.

    edit edit: wooooho! post #201
    Last edited by abh!shek; 04-29-2008 at 11:35 AM.

  6. #6
    Registered User
    Join Date
    Dec 2007
    Posts
    214
    Quote Originally Posted by salmansalman View Post
    lol
    Code:
    for (i=0; i>=10; i--)
    if thats what u meant?
    Try that and let us know if it works.
    Last edited by DaveH; 04-29-2008 at 11:40 AM.

  7. #7
    Registered User
    Join Date
    Apr 2008
    Posts
    72
    try that where? lol ..

    Code:
    arr[]={22,31,10,2,51}
    if i want to do this manually i can just do
    Code:
    arr[0]=2;
    arr[1]=10;
    nd ........ like tht.. i need a logic for this, please write down the logic and i realy need to sleep.. ill wait for 5 minutes and if someone here comes up with serious help, it will be appritiated otherwise im already ........ed off so plz dont post anything useless

  8. #8
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    so plz dont post anything useless
    Before asking this - you better post something useful yourself.
    Show your attemp and ask question about problems you have encountered...
    Don't just sit and wait till the Santa brings you a Cristmas gift...
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  9. #9
    Registered User
    Join Date
    Dec 2007
    Posts
    214
    Quote Originally Posted by salmansalman View Post
    try that where? lol ..
    you wrote this for a loop counting down :

    Code:
    for (i=0; i>=10; i--)
    This will not work. First time through, i=0, test the end condition, i=0 which is not >=10 so exit loop.

  10. #10
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    The trick is to use a variable in the indexing part when you refer to the array.

    int i;

    arr[i];

    Then you can put it in a loop and just spit out every element that corresponds to the iteration you're in.

    To do it backwards, initialize i to the maximum, then count down until it's zero. To to the forward direction, do it like a regular loop, initialize at zero, and count up until it's at the maximum. See the tutorial on loops for more information: http://www.cprogramming.com/tutorial/c/lesson3.html

    Feel free to use more than one loop.

  11. #11
    Registered User
    Join Date
    Apr 2008
    Posts
    72
    lol I seriously dont understand ;\\\\\\\\\\\\\
    Code:
    void main()
    {
    int arr[5]={100,22,10,103,44}
    int order;
    
    for(i=1; i<=5; i--)
    {
    printf("%d", order);
    }
    or what, im totaly confused ;\ just 3 hours left for exam.. i request pleas to paste the complete logic for pasting that array into accending order, ill be thankful

  12. #12
    Registered User
    Join Date
    Dec 2007
    Posts
    214
    Quote Originally Posted by salmansalman View Post
    lol I seriously dont understand ;\\\\\\\\\\\\\
    Code:
    void main()
    {
    int arr[5]={100,22,10,103,44}
    int order;
    
    for(i=1; i<=5; i--)
    {
    printf("&#37;d", order);
    }
    Trace through that for loop.

    i=1, 1<=5 so do loop. decrement i, now i=0.
    i=0, 0 <=5 so do loop. decrement i, now i=-1.
    i=-1, -1 <=5 so do loop. decrement i, now i=-2.

    See a pattern? Infinite loop.

  13. #13
    Registered User
    Join Date
    Apr 2008
    Posts
    72
    well thanks for whatever u did i.e flamming and other crap, none of u actually tried to help or helped.. but anyways, thanks.. now just pray (if possible) for me to pass the exam.. im going now and i will never come back to this board, thanks alot

    byee

  14. #14
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Instead of Salman Khan if you only knew about Yashwant Kanetkar!

    Best of luck for your exams! Why you are so sure about above problems. They may not be asked in exams! Just chill dude!

  15. #15
    Registered User
    Join Date
    Apr 2008
    Posts
    72
    manav lol haha you were right :P anyway I think I did well in the paper.. here are a few objectives I just want to know if they are correct..

    Choose the correct

    1)If Var is an integer variable var = 5/2 will return a value
    a)2.5
    b)3
    3)2
    d)0

    2)Minimum value that an integer constant can have is
    a)0
    b)-32767
    c)32767
    d)1.701e+38

    3)A C Variable cannot start with
    a)An Alphabet
    b)A Number
    c)A Special symbol except underscore
    d)Both b & c

    4)C Program is converted to machine language with the help of
    a)An Editor
    b)An Operating system
    c)A Compiler
    d)none of the above

    5)A Pointer is a special variable which can only store
    a)Another pointer
    b)Integer values
    c)Addresses
    d)All of the above

    I ticked option "c" in 1 .. option "b" in 2nd .. option "d" in 3rd .. option "c" in 4th and option "c" in 5th..

    and now true false

    1)Each new C instruction has to b e written on seperate line
    2) Blank spaces cannot be inserted within a variable name
    3)An Integer constant in C must have atleast one decimal point
    4)Output of the instruction 'a' + 10 is 75
    5) 3+a=10 is not a valid C statement

    I did
    1) True
    2)True
    3)False
    4)true
    5)True

    .. these objections carried 10 marks.. please tell me if all the options i choosed were correct if not pls let me know? thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Do you know...
    By davejigsaw in forum C++ Programming
    Replies: 1
    Last Post: 05-10-2005, 10:33 AM
  2. recursive quick sort - stack overflow
    By Micko in forum C Programming
    Replies: 9
    Last Post: 01-01-2005, 05:51 PM
  3. Questions on basic Quick Sort
    By Weng in forum C++ Programming
    Replies: 4
    Last Post: 12-16-2003, 10:06 AM
  4. Quick Sort Help
    By NavyBlue in forum C Programming
    Replies: 1
    Last Post: 03-02-2003, 10:34 PM
  5. Replies: 0
    Last Post: 04-30-2002, 07:24 PM