C program-- the output is not right please help me to correct it.
#include <stdio.h>
int main()
{
int arr[100];
int i,j,n,p,value,temp;
printf("Enter the number of elements in the array: \n ");
scanf("%d",&n);
printf("Enter %d elements in the array: \n",n);
for(i=0;i<n;i++) {
printf("\nelement %d: ",i);
scanf("\n%d",&arr[i]);
}
printf("\nEnter the value to be inserted: \n ");
scanf("\n%d",&value);
printf("The exist array is: \n");
for(i=0;i<n;i++)
{
printf("%d",arr[i]);
}
p=i;
for(i=0;i<n;i++)
if(value<arr[i] )
{
p = i;
break;
}
arr[p]=value;
printf("\n");
for (i = 0; i < n; i++)
for (j = 0; j < n-i; j++)
if (arr[j] > arr[j+1])
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
printf("\nAfter insert the value, the sorted array is:\n ");
for(i=0;i<=n;i++)
{
printf("%d",arr[i]);
}
return 0;
}
#include <stdio.h>
void bubbleSort(int *arr, int n) {
for (int i = n - 1; i > 0; i--) {
for (int j = 0; j < i; j++) {
if ((arr[j] > arr[j+1])) {
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
}
int main()
{
int arr[100];
int i,j,n,p,value,temp;
printf("Enter the number of elements in the array: \n ");
scanf("%d",&n);
printf("Enter %d elements in the array: \n",n);
for(i=0;i<n;i++) {
printf("\nelement %d: ",i);
scanf("\n%d",&arr[i]);
}
printf("\nEnter the value to be inserted: \n ");
scanf("\n%d",&value);
printf("The exist array is: \n");
for(i=0;i<n;i++)
{
printf("%d ",arr[i]);
}
printf("\n");
for (i=n-1; ( i >= 0 && arr[i] > value); i--)
arr[i+1] = arr[i];
arr[i+1] = value;
n = n + 1;
bubbleSort(arr,n);
printf("\nAfter insert the value, the sorted array is:\n ");
for(i=0;i<n;i++)
{
printf("%d ",arr[i]);
}
return 0;
}
=====================================
See Output
Thanks, PLEASE COMMENT if there is any concern.
C program-- the output is not right please help me to correct it. #include <stdio.h> int...
Fix the errors in C code #include <stdio.h> #include <stdlib.h> void insertAt(int *, int); void Delete(int *); void replaceAt(int *, int, int); int isEmpty(int *, int); int isFull(int *, int); void removeAt(int *, int); void printList(int *, int); int main() { int *a; int arraySize=0,l=0,loc=0; int choice; while(1) { printf("\n Main Menu"); printf("\n 1.Create list\n 2.Insert element at particular position\n 3.Delete list.\n4. Remove an element at given position \n 5.Replace an element at given position\n 6. Check the size of...
Write a C Program that inputs an array of integers from the user along-with the length of array. The program then prints out the array of integers in reverse. (You do not need to change (re-assign) the elements in the array, only print the array in reverse.) The program uses a function call with array passed as call by reference. Part of the Program has been given here. You need to complete the Program by writing the function. #include<stdio.h> void...
#include<stdio.h> #include<stdio.h> int main(){ int i; //initialize array char array[10] = {“Smith”, “Owen”, “Kowalczyk”, “Glass”, “Bierling”, “Hanenburg”, “Rhoderick”, “Pearce”, “Raymond”, “Kamphuis”}; for(int i=0; i<8;i++){ for(int j=0; j<9; j++){ if(strcmp(array[j],array[j+1])>0){ char temp[20]; strcpy(temp,array[j]); strcpy(array[j],array[j+1]); strcpy(array[j+1],temp); } } } printf(“---------File Names---------\n”); for(inti=0; i<9; i++){ printf(“\t%s\n”,array[i]); } printf(-------5 Largest Files according to sorting----\n”); for(int i=0;i>=5;i--) { printf(“\t%s\n”,array[i]); } return0; } Consider the "sort" program (using with void* parameters in the bubblesort function) from the week 10 "sort void" lecture. Modify it as follows...
#include<stdio.h> int main() { int data[10], i, j, temp; printf("Enter 10 random number to sort in ascending order:\n"); for(i = 0; i < 10; i++) scanf("%d", &data[i]); /* Sorting process start */ ****** INSERT YOUR CODE TO COMPLETE THE PROGRAM ****** printf("After sort\n"); for(i = 0; i < 10; i++) printf("%d\n",data[i]); return 0; } Looking for alternative solutions for the program code.
the code needs to be modifed. require a output for the code Java Program to Implement Insertion Sort import java.util.Scanner; /Class InsertionSort * public class Insertion Sort { /Insertion Sort function */ public static void sort( int arr) int N- arr.length; int i, j, temp; for (i-1; i< N; i++) j-i temp arrli; while (j> 0 && temp < arrli-1) arrli]-arrli-1]; j-j-1; } arrlj] temp; /Main method * public static void main(String [] args) { Scanner scan new Scanner( System.in...
Can you write the algorithm for this code? #include<stdio.h> int main() { int process[20], priority[20], arrival_time[20], burst_time[20], turnaround_time[20], waiting_time[20]; int i, j, limit, sum = 0, position, temp; float average_wait_time, average_turnaround_time; printf("Enter Total Number of Processes:\t"); scanf("%d", &limit); printf("\nEnter Burst Time and Priority For %d Processes\n", limit); for(i = 0; i < limit; i++) { printf("\nProcess[%d]\n", i + 1); printf("Process Burst Time:\t"); scanf("%d", &burst_time[i]); printf("Process Priority:\t"); scanf("%d", &priority[i]); process[i] = i + 1; } for(i = 0; i < limit;...
i need flowchart for the following c code #include <stdio.h> int main() { int n, i, sum = 0; printf("Enter an integer: "); scanf("%d",&n); i = 1; while ( i <=n ) { sum += i; ++i; } printf("Sum = %d",sum); return 0; }
#include "stdio.h" int main() { float array[5][3],rowsum=0.0,colsum=0.0; int i,j; for(i=0;i<5;i++){ printf("Enter the %d elements of array:\n",i); for(j=0;j<3;j++){ scanf("%f",&array[i][j]); } } printf("Given table data:\n"); for(i=0;i<5;i++){ for(j=0;j<3;j++){ printf(" %0.1f",array[i][j]); } printf("\n"); } for(i=0;i<5;i++){ for(j=0;j<3;j++){ rowsum=rowsum+array[i][j]; } printf("sum of the %d row is %0.1f\n",i,rowsum); rowsum=0; } for(j=0;j<3;j++){ colsum+=array[j][i]; printf("Sum of %d coloumn is %0.1f\n",j,colsum); colsum=0; } return(0); } can someone help me to get the correct row sum and column sum in c program
I need some with this program, please look at the changes I need closely. Its running correctly, but I need to do a few adjustments here is the list of changes I need: 1. All of the integers on a single line, sorted in ascending order. 2. The median value of the sorted array on a single line 3. The average of the sorted array on a single line Here is the program: #include<stdio.h> #include<stdlib.h> /* This places the Adds...
sort.c #include <stdlib.h> #include <stdio.h> #include "libsort.h" int main() { int* array; int size, c; float median; printf("Enter the array size:\n"); scanf("%d", &size); array = (int*) malloc(size * sizeof(int)); printf("Enter %d integers:\n", size); for (c = 0; c < size; c++) scanf("%d", &array[c]); sort(array, size); printf("Array sorted in ascending order:\n"); for (c = 0; c < size; c++) printf("%d ", array[c]); printf("\n"); median = find_median(array,...