Page 1 of 2 12 LastLast
Results 1 to 10 of 20

Thread: Exercise in C

  1. #1

    Default Exercise in C


    Make a C program with 2 arrays A1 and A2 of size 10(both). Accept 10 numbers and store the numbers to array A1. Initialize the second array with zero. Then copy the values of the first array to the second array in reverse way. The print the elements of the second array.

  2. #2

    Default Re: Exercise in C

    sorry dinalian ni..

    #include <stdio.h>

    void get_inputs(int*);
    void copy_reverse(int*, int*);
    void print_array(int*);

    int main() {
    Â* Â* Â* Â* int x[10], y[10];
    Â* Â* Â* Â* get_inputs(x);
    Â* Â* Â* Â* copy_reverse(x, y);
    Â* Â* Â* Â* print_array(y);
    Â* Â* Â* Â* return 0;
    }

    void get_inputs(int x[]) {
    Â* Â* Â* Â* printf("Input 10 numbers: \n");
    Â* Â* Â* Â* int i;
    Â* Â* Â* Â* for (i = 0; i < 10; i++) {
    Â* Â* Â* Â* Â* Â* Â* Â* scanf("%d", &x[i]);
    Â* Â* Â* Â* }
    Â* Â* Â* Â* printf("\n");
    }

    void copy_reverse(int x[], int y[]) {
    Â* Â* Â* Â* int i;
    Â* Â* Â* Â* for (i = 0; i < 10; i++) {
    Â* Â* Â* Â* Â* Â* Â* Â* y[9 - i] = x[i];
    Â* Â* Â* Â* }
    }

    void print_array(int y[]) {
    printf("The 10 numbers in reverse order: \n");
    Â* Â* Â* Â* int i;
    Â* Â* Â* Â* for (i = 0; i < 10; i++) {
    Â* Â* Â* Â* Â* Â* Â* Â* printf("%d\n", y[i]);
    Â* Â* Â* Â* }
    }

  3. #3

    Default Re: Exercise in C

    hahaha nagpahimo lagi ug assignment

  4. #4

    Default Re: Exercise in C

    oh i hope dili assigment. anyways, siya ra man sad luoy kay cya man sad ang wala makat onan.

  5. #5

    Default Re: Exercise in C

    salamat sa pag hatag ug tubag... dili mani assignment nako amo ni quiz den wala ko sure sa ako answer mao na ask ko ninyo kay kabalo ko nga daghan pro diri...

    salamat!

  6. #6

    Default Re: Exercise in C

    post lang ngahi bro basta naa ka malibgan. daghan man mutabang dinhi. pero ayaw lang assignment kay allergic mga tao diri ug assignments. hehehe

  7. #7

    Default Re: Exercise in C

    void get_inputs(int*);
    void copy_reverse(int*, int*);
    void print_array(int*);


    dba x and y man unta ibutang dha sa astris? pwede di astris gamiton?

  8. #8

    Default Re: Exercise in C

    Quote Originally Posted by lestat1116
    dba x and y man unta ibutang dha sa astris? pwede di astris gamiton?
    not unless you don't want to change the values of the parameters. those asterisks are pointers btw.

  9. #9

    Default Re: Exercise in C

    so ok ra di gamiton ang astris?

  10. #10

    Default Re: Exercise in C

    it's actually needed coz you're passing a whole array to the function. kung int lang ang type, you're passing only one element by value (meaning, the value of the param is not modified once the function exits). going back to my previous post, i think this is the more suitable reason for the use.

  11.    Advertisement

Page 1 of 2 12 LastLast

Similar Threads

 
  1. More than 87k students dance in Bacolod for world aerobics exercise record
    By DailyCore in forum Politics & Current Events
    Replies: 23
    Last Post: 02-16-2012, 10:31 AM
  2. For Sale: All-in-one exerciser -total gym 1000
    By Lady-L in forum Sporting Goods
    Replies: 17
    Last Post: 05-04-2011, 10:52 AM
  3. For Sale: Treadmill & 5 in 1 Body Weight Exercise
    By mojo™ in forum Sporting Goods
    Replies: 38
    Last Post: 03-11-2010, 08:33 AM
  4. what is the best exercise in the morning?
    By francegreat in forum Relationships (Old)
    Replies: 0
    Last Post: 12-13-2008, 10:31 AM
  5. Replies: 45
    Last Post: 01-30-2008, 10:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top