This program needs to be written using SSH secure shell client. This program nee
ID: 645679 • Letter: T
Question
This program needs to be written using SSH secure shell client.
This program needs to be written using SSH secure shell client.
This program needs to be written using SSH secure shell client.
1. (100 pts) Write a program that swaps the elements of an array pairwise. Start from the left of the array, take 2 elements at a time and swap the two elements. Continue in this fashion until you reach the end of the array. Declare an integer array of size 10 and place random numbers in the range [0?9]. Print the original array, pairwise swap the elements of the array and print the final array after swap. Consider the following example.
0123456789
After pairwise swap you get the following array
0123456789
In the array first two numbers 1 and 7 are swapped, 4 and 0 are swapped, 9 and 4 are swapped, 8 and 8 are swapped and 2 and 4 are swapped. Sample execution of the program is given below
Original array 1740948824
After pairwise swap 7104498842
Explanation / Answer
#include <stdio.h>
#include<conio.h>
voidmain()
{
float a[10];
int i,n;
void swap(float *ptr1,float *ptr2);//function declearation
printf(''No of elements........ ");
scanf("%d", &n);
printf(" enter elements ");
for(i=o;i<n;i++);
{
scanf("%f",x+i);
}
swap(x,x+1);
printf(" result array ");
for(i=0;i<n;i++)
{
printf("x[%d]=%f ,i,x[i]);
}
}
void swao(float *ptr1,float *ptr2)
{
float temp;
temp = *ptr1;
*ptr1 = *ptr2;
*ptr2 = temp;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.