Professional Documents
Culture Documents
Source Code:: Harshit Chaturvedi 1018494/26 Sem-5/Sec-C
Source Code:: Harshit Chaturvedi 1018494/26 Sem-5/Sec-C
SOURCE CODE :
#include <stdio.h>
int main()
{
int n=0;
printf("Enter size of array : ");
scanf("%d",&n);
int smin=0,min=0,i=0,a[n],minIndex=0;
printf("Enter elements with a space : ");
scanf("%d",&a[0]);
min=a[0];
for(i=1;i<n;i++)
{
scanf("%d",&a[i]);
if(a[i]<min)
{
min=a[i];
minIndex=i;
}
}
if(minIndex!=0)
smin=a[0];
else
smin=a[1];
for(i=0;i<n;i++)
{
if(i!=minIndex)
{
if(smin>a[i])
smin=a[i];
}
}
printf("Second maximum number = %d",smin);
return 0;
}
SOURCE CODE :
#define MAX 100
#include <stdio.h>
struct nums{
int num;
int freq;
};
for(int i=0;i<size;i++){
freq = findFreq( arr,arr3[i],n);
freqs[i].num = arr3[i];
freqs[i].freq = freq;
printf("%d %d \n",freqs[i].num,freqs[i].freq);
}
struct nums temp;
SOURCE CODE :
#include <stdio.h>
int main()
{
int i=0,j=0,n=0,m=0;
printf("Enter the size of array 1 and array 2 : ");
scanf("%d %d",&n,&m);
int a[n];
printf("Enter the elements of array 1 : ");
for(i;i<n;i++)
scanf("%d",&a[i]);
int b[m];
printf("Enter the elements of array 2 : ");
for(i=0;i<m;i++)
scanf("%d",&b[i]);
int num=0,flag=1,k=0,t=0;
for(i=0;i<m;i++)
{
num=b[i];
for(j=0;j<n;j++)
{
if(a[j]==num)
{
t=a[j];
a[j] = a[k];
a[k] = t;
k++;
}
return 0;
}
OUTPUT :
SOURCE CODE :
#include <stdio.h>
int main()
{
int n;
printf("Enter the size of array : ");
scanf("%d",&n);
int a[n],j,i,flag=0;
printf("Enter the elements of array : ");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
{
flag=0;
for(j=0;j<n;j++)
{
if(j!=i)
{
if(a[i]==a[j])
{
flag=1;
break;
}
}
}
if(flag==0)
printf("Non repeating elements = %d \n",a[i]);
}
return 0;
}
SOURCE CODE :
#include <stdio.h>
int main() {
int n;
printf("Enter the size of array : ");
scanf("%d",&n);
int i,j,a[n],flag=0;
printf("Enter the elements of array : ");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]==a[j]){
printf("Duplicate element = %d\n",a[i]);
flag++;
}
break;
}
}
if(flag==0)
printf("No duplicate elements");
}
CASE 2 :
Method 1 : This approach moves all negative numbers to the beginning and positive
numbers to the end but changes the order of appearance of the elements of the array.
Method 2 : In this approach, we separate the negative and positive numbers of the
array by maintaining the order of appearance of elements of the array
SOURCE CODE :
#include <stdio.h>
int main() {
int n;
printf("Enter the no of elements : ");
scanf("%d",&n);
int i,j,a[n],t;
printf("Enter the elements : ");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n-1;i++)
{
if(a[i]>0)
{
for(j=i+1;j<n;j++)
{
if(a[j]<0)
{
t=a[i];
a[i]=a[j];
a[j]=t;
break;
}
}
}
}
printf("Array after rearranging : ");
for(i=0;i<n;i++)
printf("%d ",a[i]);
}
SOURCE CODE :
#include <stdio.h>
int main()
{
int d,n;
printf("Enter the number of elements : ");
scanf("%d",&n);
int a[n],i;
printf("Enter the elements of array : ");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
OUTPUT :