0% found this document useful (0 votes)
6 views

Coding For HTML Web

Nice work

Uploaded by

ecermit2023
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Coding For HTML Web

Nice work

Uploaded by

ecermit2023
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

#include<stdio.

h>
#include<string.h>
main()
{

}
9.array and functions
1.
#include<stdio.h>
#include<string.h>
void swap(int *n,int *m)
{
int t;
t=*n;
*n=*m;
*m=t;
}
main()
{
int n,m;
printf("Enter the value of two variables : ");
scanf("%d %d",&n,&m);
printf("Value before swap is \nn:%d\nm:%d\n",n,m);
swap(&n,&m);
printf("Value after swap is \nn:%d\nm:%d",n,m);
}
2.
#include<stdio.h>
#include<string.h>
int pal(int x)
{
int num=0,n;
static int r=0;
int t;
t=x;
for(int i=0;x!=0;i++)
{
n=x%10;
num=num*10+n;
x=x/10;
}
if(t==num)
{
r++;
printf("%d\n",t);

}
return(r);
}
main()
{
int n,x;
printf("Enter number of elements : ");
scanf("%d",&n);
int a[n];
printf("Enter the elements of the array : \n");
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("The palindrome numbers are :\n");
for(int i=0;i<n;i++)
{
x=pal(a[i]);
}
if(x==0)
{
printf("There are no palindrome in the array.");
}
}
3.
#include<stdio.h>
void read(int a[],int n)
{

printf("Enter the values : \n");


for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
}

}
void disp(int a[],int n)
{
printf("\nThe array elements are : \n");
for(int i=0;i<n;i++)
{
printf("%d\n",a[i]);
}
}
int sum(int a[],int n)
{
int s=0;
for(int i=0;i<n;i++)
{
s=s+a[i];
}
return s;
}
main()
{
int n;
printf("Enter number of elements : ");
scanf("%d",&n);
int a[n];
read(a,n);
disp(a,n);
int s=sum(a,n);
printf("\nThe sum of elements is : %d ",s);
printf("\nThe average of elemnts is : %d",s/n);
}
4.
#include<stdio.h>
void functionLinearSearch(int a[],int n,int key)
{
int r=0;
printf("The key value is found at \n ");
for(int i=0;i<n;i++)
{
if(key==a[i])
{
printf("%d\n",i+1);
r++;
}

}
if(r==0)
{
printf("The key value not found.");
}
}
main()
{
int n,key;
printf("Enter number of elements : ");
scanf("%d",&n);
int a[n];
printf("Enter the values : \n");
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("Enter the key value to search : ");
scanf("%d",&key);
functionLinearSearch(a,n,key);
}
5.
#include<stdio.h>
#include<string.h>
int check(char *a,char *b)
{
int x;
x=strcmp(a,b);
if(x==0)
return 0;
else if(x>0)
return 1;
else
return -1;
}
main()
{
char a[100],b[100];
printf("Enter two strings : ");
scanf("%s %s",a,b);
int n=check(a,b);
printf("The return value is : %d",n);
}
6.
#include<stdio.h>
#include<string.h>
void sort (int a[],int n,int k)
{
int i,j;
if(k==1)
{
for(i=1;i<n;i++)
{
for(j=0;j<n-1;j++)
{
if(a[j]>a[j+1])
{
int t;
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
}
else
{
for(i=1;i<n;i++)
{
for(j=0;j<n-1;j++)
{
if(a[j]<a[j+1])
{
int t;
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
}
printf("The sorted array is : \n");
for(i=0;i<n;i++)
{
printf("%d ",a[i]);
}
}
main()
{
int n;
printf("Enter number of elements : ");
scanf("%d",&n);
int a[n];
printf("Enter the values : \n");
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
int i;
printf("Enter parameter : \n 1.Ascending order \n Others for descending
order:");
scanf("%d",&i);
sort (a,n,i);
}
7.
#include<stdio.h>
#include<string.h>
void trace(int a[][],int n)
{
int sum=0;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(i==j)
{
sum=sum+a[i][j];
}
}
}
printf("The value of the trace is : %d",sum);
}
main()
{
int n;
printf("Enter the number of rows ");
scanf("%d",&n);
int a[n][n];
printf("Enter the values of the matrix : ");
int i,j;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",a[i][j]);
}
}
trace(a,n);
}

You might also like