Question

I need help and I'm stuck on this program. I have to do it in the...

I need help and I'm stuck on this program. I have to do it in the C language on my Linux system. Can someone help me with this please? I have included my instructions and sample output. Thank you

-Initialize 2 arrays within the main method, one with odd numbers and one with even numbers.

-In the main method swap the arrays.

-Print the arrays before and after the swap.

//output should look like the following

Before Swap

firstArray[0] = 0, secondArray[0] = 1

firstArray[1] = 2, secondArray[1] = 3

firstArray[2] = 4, secondArray[2] = 5

firstArray[3] = 6, secondArray[3] = 7

firstArray[4] = 8, secondArray[4] = 9

After Swap

firstArray[0] = 1, secondArray[0] = 0

firstArray[1] = 3, secondArray[1] = 2

firstArray[2] = 5, secondArray[2] = 4

firstArray[3] = 7, secondArray[3] = 6

firstArray[4] = 9, secondArray[4] = 8

0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you have any doubts, please give me comment...

#include<stdio.h>

int main(){

    const int n = 5;

    int firstArray[n], secondArray[n];

    int i, k=0, temp;

    for(i=0, k=0; k<n; i+=2, k++){

        firstArray[k] = i;

        secondArray[k] = i+1;

    }

    printf("Before Swap\n");

    for(i=0; i<n; i++){

        printf("firstArray[%d] = %d, secondArray[%d] = %d\n", i, firstArray[i], i, secondArray[i]);

    }

    //swapping

    for(i=0; i<n; i++){

        temp = firstArray[i];

        firstArray[i] = secondArray[i];

        secondArray[i] = temp;

    }

    printf("After Swap\n");

    for(i=0; i<n; i++){

        printf("firstArray[%d] = %d, secondArray[%d] = %d\n", i, firstArray[i], i, secondArray[i]);

    }

    return 0;

}

Add a comment
Know the answer?
Add Answer to:
I need help and I'm stuck on this program. I have to do it in the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need some help on Java. I'm stuck on trying to generate a new string by...

    I need some help on Java. I'm stuck on trying to generate a new string by concatenating the reversed substrings of even indexes and odd indexes separately from a given string. I'm not sure how to figure this out. See example. Example: Input: abscacd Output: dasaccb Substrings: asad, bcc Reversed substrings: dasa, ccb.

  • I'm trying to code a C program so it sorts an array of integer numbers of...

    I'm trying to code a C program so it sorts an array of integer numbers of size n in ascending order. My code is written below but its not working properly, its giving me errors, I think my sort and swap functions aren't done right maybe, please help and fix. It says "undefined reference to "SelectionSort" as an error. But the question asks to not change the PrintArray and Main function. #include <stdio.h> void PrintArray(int size, int array[]) { for...

  • Hey, i'm super stuck on my lab in cs102. I have attempted it but never got...

    Hey, i'm super stuck on my lab in cs102. I have attempted it but never got close to what the end result should be. Please help, due in 2 days!! Assignment You will be writing a program to simulate a slot machine. The player will start with $1000 and you will repeatedly ask the user how much money they wish to insert into the machine before spinning, or allow the player to quit. If the player runs out of money,...

  • Write a complete Java program, including comments in both the main program and in each method,...

    Write a complete Java program, including comments in both the main program and in each method, which will do the following: 0. The main program starts by calling a method named introduction which prints out a description of what the program will do. This method is called just once.      This method is not sent any parameters, and it does not return a value. The method should print your name. Then it prints several lines of output explaining what the...

  • I'm stuck on this question and I have a hard time figuring this out, this used...

    I'm stuck on this question and I have a hard time figuring this out, this used as C++ Question 26 10 pts (SHORT ANSWER) Use a loop to calculate and print the sum of numbers from 1 to 10 (both numbers inclusive). Use additional variable(s) as necessary. For example your output should display as follows: Sum of numbers 1-10 = 55 BIVA-A-I EI 1 XX, EE 2.2 VX T 1 12pt - Paragraph O words

  • I'm quite stuck with this C++ question, I would greatly appreciate the help! Many companies use...

    I'm quite stuck with this C++ question, I would greatly appreciate the help! Many companies use telephone number like 888- COM - CAST so the number is easier for their customer to remember. On a standard telephone, the alphabetic letters are mapped to numbers in the following fashion. A, B, and C = 2 D, E, and F = 3 G, H, and I = 4 J , K , and L = 5 M, N, and O = 6...

  • I'm really stuck I need help. C++ Draw separate flowcharts to solve each of the following...

    I'm really stuck I need help. C++ Draw separate flowcharts to solve each of the following problems: Read in 20 numbers and write out how many of them were positive (write out the count, not the actual input numbers). Read in numbers until the user chooses to quit. Write out the smallest of the input values. (Make it so that the user has to enter at least one value) Read in numbers until 10 positive values have been found. Write...

  • WRITE A PROGRAM IN C++ THAT DECLARES AN INTEGER VECTOR V 1.)INITIALIZE THE VECTOR, V, WITH...

    WRITE A PROGRAM IN C++ THAT DECLARES AN INTEGER VECTOR V 1.)INITIALIZE THE VECTOR, V, WITH 10 INTEGERS WITH VALUES FROM 1 TO 10 2.)OUTPUT THE VECTOR IN DESCENDING ORDER, THEN ASCENDING ORDER 2.)ADD ALL THE EVEN NUMBERS 3.)ADD ALL THE ODD NUMBERS 4.)OUTPUT THE SUM OF EVEN INTEGERS 5.)OUTPUT THE SUM OF ODD INTEGERS 7.)OUTPUT THE PRODUCT OF EVEN INTEGERS 8.)OUTPUT THE PRODUCT OF ODD INTEGERS SAMPLE: Vector: 2 4 3 5 2 3 8 9 1 10 Ascending...

  • Hello, I need help understanding what happens to the value in each loop. I missed a...

    Hello, I need help understanding what happens to the value in each loop. I missed a lot of class so I need help. I decoded the final message but I'm supposed to fill in tables for each function. Homework 4: Program Trace Check out this “instructional” video on decoding strings - http://www.youtube.com/watch?v=zdA__2tKoIU Determine the output of the program below. You will receive no credit for a submission that shows no work. You must make variable tables and show how the...

  • I'm currently working on a problem and I'm stuck at this step --> I need to...

    I'm currently working on a problem and I'm stuck at this step --> I need to get Q to equal 504 from this equation, 0.45V = 0.53V - 0.0592/2 logQ No matter what I try I can't seem to get Q=504 as an answer for that. Please help and explain how you got it! Thank you!! ..I know the first step would be to -0.53 from both sides which gives me -0.08= -0.0592/2 logQ but then I don't know what...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT