




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
in this u can find programming c questions and answers
Typology: Study notes
1 / 109
This page cannot be seen from the preview
Don't miss anything!
EXPERIMENT NO…… DATE ……………… …..
Aim : Write a program to find the occurrence of an element in the array. Code :
#include<stdio.h> void main() { int a[10],n,i,p,count=0; printf ("\nEnter the size of the array "); scanf("%d",&n); printf("\nEnter the elements into the array "); for(i=0;i<n;i++) { scanf("%d",&a[i]); } printf("\nEnter the element to find "); scanf("%d",&p); for(i=0;i<n;i++) { if(p==a[i]) count++; } printf("\nOccurence = %d\n",count); }
e1 | P a g
e2 | P a g
EXPERIMENT NO…… DATE …………… ……..
Aim : Write a program to find the sum of the numbers at even positions in the array. Code : #include<stdio.h> void main() { int a[10],n,i,sum=0; printf("\nEnter the size of the array "); scanf("%d",&n); printf("\nEnter the elements into the array "); for(i=0;i<n;i++) { scanf("%d",&a[i]); } for(i=0;i<n;i=i+2) { sum+=a[i]; } printf("\nSum of elements at even position = %d\n",sum); }
Output :
e4 | P a g
5 | P a g e
Output :
EXPERIMENT NO…… DATE …………… ……..
Aim : Write a program to insert a element into the array. Code : #include<stdio.h> void main() { int a[30], i, num, pos, el; printf("\nEnter no of elements :"); scanf("%d", &num); printf("\nEnter the elements"); //Read n elements in an array for (i = 0; i < num; i++) scanf("%d", &a[i]); printf("\nEnter element for insertion "); scanf("%d",&el); printf("\nEnter position for insertion "); scanf("%d",&pos); for(i=num;i>=pos;i--) { a[i+1]=a[i]; } a[pos]=el; num=num+1; printf("\nThe array is ");
7 | P a g e
8 | P a g e
EXPERIMENT NO…… DATE …………… ……..
Aim : Write a program to delete an element from the array. Code : #include<stdio.h> void main() { int a[30], i, num, pos; printf("\nEnter no of elements :"); scanf("%d", &num); printf("\nEnter the elements"); //Read n elements in an array for (i = 0; i < num; i++) scanf("%d", &a[i]); printf("\nEnter position for deletion "); scanf("%d",&pos); for(i=pos;i<num;i++) { a[i]=a[i+1]; } num=num-1; printf("\nThe array is "); for (i = 0; i < num; i++) printf("%d ", a[i]);
Output :
10 | P a g e