Professional Documents
Culture Documents
Arrays and Functions
Arrays and Functions
Arrays and Functions
Arrays:
1. Find an Element in an Array
#include <stdio.h>
int main()
int arraySize,i;
scanf("%d",&arraySize);
int a[arraySize];
scanf("%d",&a[i]);
int n;
scanf("%d", &n);
return 0;
}
ARRAYS AND FUNCTIONS
int main()
int arraySize,i;
scanf("%d",&arraySize);
int a[arraySize];
scanf("%d",&a[i]);
sum += (a[i]
);
printf("Sum of all Elements in array is %d \nAverage of all Elements in array is %d", sum ,
sum / arraySize);
return 0;
#include <stdio.h>
int main()
{
int r,c,i;
// printf("Enter size of array : ");
ARRAYS AND FUNCTIONS
int a[r][c];
printf("\n");
}
return 0;
}
#include <stdio.h>
int main()
int r = 0,c,i,n;
scanf("%d ",&n);
int a[n];
scanf("%d",&a[i]);
r = a[i];
}
ARRAYS AND FUNCTIONS
return 0;
#include <stdio.h>
int main()
{
ARRAYS AND FUNCTIONS
int r = 0,c,i,n;
scanf("%d ",&n);
int a[n];
scanf("%d",&a[i]);
int t = a[j];
a[j] = a[j+1];
a[j+1] = t;
}
ARRAYS AND FUNCTIONS
return 0;
#include <stdio.h>
int main()
int r = 0,c,i,n;
scanf("%d ",&n);
int a[n];
scanf("%d",&a[i]);
}
ARRAYS AND FUNCTIONS
int j = i -1;
a[j+1] = a[j];
a[j+1] = temp;
return 0;
}
ARRAYS AND FUNCTIONS
#include <stdio.h>
int main()
int a[20];
ARRAYS AND FUNCTIONS
scanf("%d",&a[i]);
if(a[i] % 2 ==0 ){
sum+=a[i];
count++;
return 0;
int main() {
int i,n = 5;
int a[n];
scanf("%d",&a[i]);
printf("\n");
// Sorting of array
int j = i -1;
a[j+1] = a[j];
a[j+1] = temp;
// since the lowest value in the array can’t be formed by other elemrnts.
return 0;
ARRAYS AND FUNCTIONS
Functions:
1. Prime numbers between intervals:
#include <stdio.h>
#include <math.h>
if(a == 2)
return 2;
if (a % 2 == 0)
ARRAYS AND FUNCTIONS
return -1;
if(a%i == 0)
return -1;
return a;
if(isPrime(i) != -1){
printf("%d ",i);
return 0;
int main() {
scanf("%d %d",&a,&b);
n = b - a;
ARRAYS AND FUNCTIONS
checkPrime(a,b);
return 0;
}
ARRAYS AND FUNCTIONS
#include <stdio.h>
#include <math.h>
if(a%i == 0)
return -1;
return a;
if(isPrime(i) != -1){
if(isPrime(b-i) != -1){
return 0;
int main() {
scanf("%d ",&b);
// n = b - a;
primenum(b);
return 0;
}
ARRAYS AND FUNCTIONS
3. Factorial
#include <stdio.h>
int factorial(int a){
if(a==2)
return 2;
else
return a * factorial(a-1) ;
}
int main() {
int b;
scanf("%d ",&b);
printf("%d",factorial(b));
return 0;
}
ARRAYS AND FUNCTIONS