Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Programs #145

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions COLUMN WIGGLY.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#include<stdio.h>
int r,c;

int inp(int arr[r][c],int r,int c)
{
int i,j;
for(i=0;i<r;i++)
{
printf("Enter the elements in the row %d : \n",i+1);
for(j=0;j<c;j++)
{
printf("Enter : ");
scanf("%d",&arr[i][j]);
}
}
return arr;
}

int print(int arr[r][c],int r,int c)
{
int i,j;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%d ",arr[i][j]);
}
}
printf("\n");
}

int print1(int arr[r][c],int r,int c)
{
int i,j;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%d ",arr[i][j]);
}
}
}

int wiggly(int arr[r][c],int arr1[r][c],int r,int c)
{
int i,j,k,counter=0,p=0;
for(i=r-1;i>=0;i--)
{
if(p==0)
{
for(j=0;j<c;j++)
{
arr1[counter][j]=arr[j][i];
}
counter++;
p=1;
}
else
{
k=0;
for(j=c-1;j>=0;j--)
{
arr1[counter][k]=arr[j][i];
k++;
}
counter++;
p=0;
}
}
return arr1;
}

int main()
{
int i,j;
printf("Enter the number of Rows : ");
scanf("%d",&r);
printf("Enter the number of Columns : ");
scanf("%d",&c);
int arr[r][c],arr1[r][c];
inp(arr,r,c);
printf("The Matrix is :\n");
print(arr,r,c);
wiggly(arr,arr1,r,c);
printf("The wiggly Path Array is :\n");
print1(arr1,r,c);
return 0;
}
43 changes: 43 additions & 0 deletions Clock Function.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include<stdio.h>
#include<stdlib.h>
#include<time.h>

int n;

double** random(int n)
{
int i;
int *arr;
arr=(int*) malloc(n*sizeof(int));
for(i=0;i<n;i++)
{
printf("Enter the Element %d : ",i+1);
scanf("%d",(arr+i));
}
printf("The Elements in the Random Function are : ");
for(i=0;i<n;i++)
{
printf("%d ",*(arr+i));
}
return arr;
}
void main()
{
clock_t start, end;
start=clock();
int n,*ptr,i;
double ctime;
printf("Enter the number of elements in the Array : ");
scanf("%d",&n);
ptr=(int*) malloc(n*sizeof(int));
ptr=random(n);
end=clock();
ctime=((double)(end-start))/CLOCKS_PER_SEC;
printf("\nThe time taken by the Random Function is %f seconds.",ctime);
printf("\nThe Elements after returning the pointer to the array are : ");
for(i=0;i<n;i++)
{
printf("%d ",*(ptr+i));
}
free(ptr);
}
43 changes: 43 additions & 0 deletions Clock.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include<stdio.h>
#include<stdlib.h>
#include<time.h>

int n;

double** random(int n)
{
int i;
int *arr,*pos,max=0;
arr=(int*) malloc(n*sizeof(int));
for(i=0;i<n;i++)
{
printf("Enter the Element %d : ",i+1);
scanf("%d",(arr+i));
if(*(arr+i)>max)
{
max=*(arr+i);
pos=(arr+i);
}
}
printf("The Elements in the Random Function are : ");
for(i=0;i<n;i++)
{
printf("%d ",*(arr+i));
}
return pos;
}
void main()
{
clock_t start, end;
start=clock();
int n,*ptr,i;
double ctime;
printf("Enter the number of elements in the Array : ");
scanf("%d",&n);
ptr=random(n);
end=clock();
ctime=((double)(end-start))/CLOCKS_PER_SEC;
printf("\nThe time taken by the Random Function is %f seconds.",ctime);
printf("\nThe Pointer of the Max element in the Array is : %d and the Max element is %d.",ptr,*ptr);
}

21 changes: 21 additions & 0 deletions Copy Array Using Pointers.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include<stdio.h>
void copy(int*,int*,int);
void main()
{
int a[5]={1,2,3,4,5},b[5];
copy(a,b,5);
}
void copy(int a[5],int b[5],int size)
{
int i;
int *p=a;
for(i=0;i<size;i++)
{
b[i]=*p+i;
}
printf("The newly created array is : ");
for(i=0;i<size;i++)
{
printf("%d ",b[i]);
}
}
46 changes: 46 additions & 0 deletions Distance between two Points.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include<stdio.h>
#include<math.h>
int n;

void dis(int arr1[n],int arr2[n],int n)
{
int i,diff=0;
for(i=0;i<n;i++)
{
diff+=pow((arr2[i]-arr1[i]),2);
}
printf("\nThe distance is %lf.",sqrt(diff));
}

void main()
{
int n=3,i;
int *arr1,*arr2;
arr1=(int*)malloc(n*sizeof(int));
arr2=(int*)malloc(n*sizeof(int));
printf("Array 1 : \n");
for(i=0;i<n;i++)
{
printf("Enter the Element %d : ",i+1);
scanf("%d",(arr1+i));
}
printf("The Elements are : ");
for(i=0;i<n;i++)
{
printf("%d ",*(arr1+i));
}
printf("\nArray 2 : \n");
for(i=0;i<n;i++)
{
printf("Enter the Element %d : ",i+1);
scanf("%d",(arr2+i));
}
printf("The Elements are : ");
for(i=0;i<n;i++)
{
printf("%d ",*(arr2+i));
}
dis(arr1,arr2,n);
free(arr1);
free(arr2);
}
20 changes: 20 additions & 0 deletions External 1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
int n;
void dis(int arr1[n],int arr2[n],int n)
{
int i,diff=0;
for(i=0;i<n;i++)
{
diff+=pow((arr2[i]-arr1[i]),2);
}
printf("\nThe distance is %lf.",sqrt(diff));
}

void pro(int arr1[n],int arr2[n],int n)
{
int i,prod=0;
for(i=0;i<n;i++)
{
prod=prod+(arr1[i]*arr2[i]);
}
printf("\nThe Scalar Product of two Arrays is : %d.",prod);
}
33 changes: 33 additions & 0 deletions External 2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include<stdio.h>
#include<math.h>
#include "7.c"
int n;

void main()
{
int n=3,i;
int *arr1[n],*arr2[n];
printf("Array 1 : \n");
for(i=0;i<n;i++)
{
printf("Enter the Element %d : ",i+1);
scanf("%d",(arr1+i));
}
printf("The Elements are : ");
for(i=0;i<n;i++)
{
printf("%d ",*(arr1+i));
}
printf("\nArray 2 : \n");
for(i=0;i<n;i++)
{
printf("Enter the Element %d : ",i+1);
scanf("%d",(arr2+i));
}
printf("The Elements are : ");
for(i=0;i<n;i++)
{
printf("%d ",*(arr2+i));
}
dis(arr1,arr2,n);
}
31 changes: 31 additions & 0 deletions External 3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include<stdio.h>
#include "7.c"

void main()
{
int n=2,i;
int *arr1[n],*arr2[n];
printf("Array 1 : \n");
for(i=0;i<n;i++)
{
printf("Enter the Element %d : ",i+1);
scanf("%d",(arr1+i));
}
printf("The Elements are : ");
for(i=0;i<n;i++)
{
printf("%d ",*(arr1+i));
}
printf("\nArray 2 : \n");
for(i=0;i<n;i++)
{
printf("Enter the Element %d : ",i+1);
scanf("%d",(arr2+i));
}
printf("The Elements are : ");
for(i=0;i<n;i++)
{
printf("%d ",*(arr2+i));
}
pro(arr1,arr2,n);
}
45 changes: 45 additions & 0 deletions Frequency of a character.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

void main()
{
char *a,*b;
int i=0,j,k=0,c=0,ptr=0,f=0;
a=(char*)malloc(50*sizeof(char));
b=(char*)malloc(50*sizeof(char));
printf("Enter the String : ");
fgets(a,50,stdin);
strlwr(a);
while(a[i]!='\0')
{
c=0;
f=0;
if(a[i]>='a' && a[i]<='z')
{
for(j=0;j<ptr;j++)
{
if(b[j]==a[i])
{
f=1;
break;
}
}
if(f==0)
{
b[ptr++]=a[i];
for(k=i;a[k]!='\0';k++)
{
if(a[k]==a[i])
{
c+=1;
}
}
printf("The character %c is found %d times in the string.\n",a[i],c);
}
}
i++;
}
free(a);
free(b);
}
8 changes: 8 additions & 0 deletions Incrementing Pointer.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include<stdio.h>
void main()
{
int a[5]={1,2,3,4,5};
int *p=a,*q=a;
printf("The value of *p++ is %d",*p++);
printf("\nThe value of (*q)++ is %d",(*q)++);
}
Loading