#include<stdio.h>
int main()
{
int arr[30], num, i, loc;
printf("nEnter no of elements : ");
scanf("%d", &num);
//Read elements in an array
printf("nEnter %d elements : ", num);
for (i = 0; i < num; i++) {
scanf("%d", &arr[i]);
}
//Read the location
printf("nLocation of the element to be deleted : ");
scanf("%d", &loc);
/* loop for the deletion */
while (loc < num) {
arr[loc - 1] = arr[loc];
loc++;
}
num--; // No of elements reduced by 1
//Print Array
for (i = 0; i < num; i++)
printf("n %d", arr[i]);
return (0);
}
Output :
Enter no of elements : 5
Enter 5 elements :
10 20 30 40 50
Location of the element to be deleted : 3
10
20
40
50
Computer Science » C Program » C Program Examples "How to print hello, world! using c program ? How to find area of a circle using c program ? How to find smallest element in an array using c program ? You all must have this kind of questions in your mind. Below article will solve this puzzle of yours. Just take a look.” - Here we have listed all the programs in C programming language, categorised under different progamming concepts like Basic, Area, Mathematical, Number, Array etc. Check the respective category to view all the programs under that category. C Programs - Basic C Programs C Programs - Number Programs C Programs - Area Programs C Programs - Mathematical Programs C Programs - Array Programs C Programs - Electrical Programs C Programs - Pyramid Programs
Computer Science » C Program » Print Alternate Numbers in an Array Program : [php] int main() { int array[9]; int i; printf("Enter the element of the array : "); for (i = 0; i < 9; i++) scanf("%d", &array[i]); printf("nAlternate elements of the entered array : n"); for (i = 0; i < 9; i += 2) printf( "%dn", array[i]) ; }[/php] Output : [php]Enter the element of the array : 1 2 3 4 5 6 7 8 9 Alternate elements of the entered array : 1 3 5 7 9[/php]
Computer Science » C Program » Find the Number of Elements in An Array Program : [php]#include <stdio.h> int main() { int array[] = {10, 20, 30, 40, 50, 60, 70,80,90,100}; int n,m; n = sizeof(array); m = n/sizeof(int); printf("Size of the given array is : %d", m); return 0; }[/php] Output : [php]Size of the given array is : 10[/php]
Computer Science » C Program » Calculate Addition of All Elements in Array Program : [php]#include<stdio.h> int main() { int i, arr[50], sum, num; printf("nEnter number of elements :"); scanf("%d", &num); //Reading values into Array printf("nEnter the values :"); for (i = 0; i < num; i++) scanf("%d", &arr[i]); //Computation of total sum = 0; for (i = 0; i < num; i++) sum = sum + arr[i]; //Printing of all elements of array for (i = 0; i < num; i++) printf("na[%d]=%d", i, arr[i]); //Printing of total printf("nSum of all elements : %d", sum); return (0); }[/php] Output : [php]Enter number of elements : 4 Enter the values : 10 20 30 40 a[0]=10 a[1]=20 a[2]=30 a[3]=40 Sum of all elements : 100[/php]