From fcaf7406d5f70f8df08f5c90a074a8c6cd0e0891 Mon Sep 17 00:00:00 2001 From: Akshat-mittal1 <145672927+Akshat-mittal1@users.noreply.github.com> Date: Fri, 29 Sep 2023 22:19:02 +0530 Subject: [PATCH 1/2] acm_dsa programs by akshat mittal --- acm_dsa_pr1.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++ acm_dsa_pr2.c | 25 ++++++++++++++++ acm_dsa_pr3.c | 32 +++++++++++++++++++++ acm_dsa_pr4.c | 20 +++++++++++++ acm_dsa_pr5.c | 49 ++++++++++++++++++++++++++++++++ acm_dsa_pr6.c | 32 +++++++++++++++++++++ acm_dsa_pr7.c | 23 +++++++++++++++ 7 files changed, 260 insertions(+) create mode 100644 acm_dsa_pr1.c create mode 100644 acm_dsa_pr2.c create mode 100644 acm_dsa_pr3.c create mode 100644 acm_dsa_pr4.c create mode 100644 acm_dsa_pr5.c create mode 100644 acm_dsa_pr6.c create mode 100644 acm_dsa_pr7.c diff --git a/acm_dsa_pr1.c b/acm_dsa_pr1.c new file mode 100644 index 0000000..9e326c6 --- /dev/null +++ b/acm_dsa_pr1.c @@ -0,0 +1,79 @@ +#include +int main(){char a; + do{ + printf("number of elements to be added in an array-->"); + int num; + int num1; + scanf("%d",&num); + int arr1[num],inp,elem; + //printf("%d",num); + + for (int i=0;i",i+1); + scanf("%d",&num1); + arr1[i]=num1; + //printf("%d",arr1[i]); + } + printf("1:find index of element using binary search:\n2:find the index of element using linear search\n3:exit\nenter your choice-->"); + scanf("%d",&inp); + + + if (inp==1) + { + printf("enter the element to find its index-->"); + scanf("%d",&elem); + for (int j=0;jarr1[k]) + { + int temp=arr1[j]; + arr1[j]=arr1[k]; + arr1[k]=temp; + } + } + } + int low=0,high=num-1,mid; + while(low<=high) + { + mid=(low+high)/2; + if(arr1[mid]==elem) + { + printf("the binary index of %d is %d",elem,mid); + break; + } + else if(arr1[mid]>elem) + { + high=mid-1; + } + else + { + low=mid+1; + } + } + /*for(int m=0;m"); + scanf("%d",&elem); + for (int i=0;i"); + scanf(" %c",&a); + }while(a=='y'); + return 0; +} \ No newline at end of file diff --git a/acm_dsa_pr2.c b/acm_dsa_pr2.c new file mode 100644 index 0000000..08db0f8 --- /dev/null +++ b/acm_dsa_pr2.c @@ -0,0 +1,25 @@ +#include +int fib(int); +void main() +{ + int a; + printf("enter the number to find the nth fibonacci number-->"); + scanf("%d",&a); + int result=fib(a); + printf("the element of fibonacci series is %d",result); + +} +int fib(int y) +{ + static int p=1; + static int sum=0; + if(y==1) + {return sum;} + else{ + y--; + + sum=sum+p; + p=sum-p; + fib(y); + } +} \ No newline at end of file diff --git a/acm_dsa_pr3.c b/acm_dsa_pr3.c new file mode 100644 index 0000000..f38258f --- /dev/null +++ b/acm_dsa_pr3.c @@ -0,0 +1,32 @@ +#include + +void pla_t(int,int); +void pali(int); +void main() + +{ + int d; + printf("Enter a number to check whether the number is palidrome or not--->"); + scanf("%d",&d); + pali(d);} + +void pali(int d){ + int xx,xy=0; + xx=d; + while(d>0) + { + xy=(xy*10)+(d%10); + d=d/10;} + pla_t(xx,xy); + + +} +void pla_t(int x,int y) +{ + if (x==y){ + printf("the given number %d is a palidrome number.\n",x); + } + else{ + printf("the given number %d is not a palidrome number.\n",x); + } +} \ No newline at end of file diff --git a/acm_dsa_pr4.c b/acm_dsa_pr4.c new file mode 100644 index 0000000..32e2eca --- /dev/null +++ b/acm_dsa_pr4.c @@ -0,0 +1,20 @@ +#include +int main() +{ + char ent[20]; + printf("enter the string-->"); + scanf("%s",&ent); + int y=0; + for(int i=0;ent[i]!='\0';i++) + { + y++; + } + //printf("%d",y); + int con1=0,vov1=0; + for(int j=0;j +int main() +{ + printf("number of elements to be added in an array-->"); + int num,num1; + scanf("%d",&num); + int arr1[num],inp,elem,small,j; + //printf("%d",num); + + for (int i=0;i",i+1); + scanf("%d",&num1); + arr1[i]=num1; + //printf("%d",arr1[i]); + } + /*for(int m=0;marr1[j]) + { + small=arr1[j]; + elem=j; + arr1[i]=small; + + } + else{ + continue; + } + } + //printf("%d",small); + if (inp!=small){ + arr1[elem]=inp;} + + + + } + for(int m=0;m +int main() +{ + int y,z; + printf("number of elements to be added in an array-->"); + int num,num1; + scanf("%d",&num); + int arr1[num],inp,elem,j; + //printf("%d",num); + inp=num; + for (int i=0;i",i+1); + scanf("%d",&num1); + arr1[i]=num1; + //printf("%d",arr1[i]); + } + + for(int i=0;iarr1[y+1]) + { + elem=arr1[y]; + arr1[y]=arr1[y+1]; + arr1[y+1]=elem; + } +}} + for(int m=0;m + +int power(int base, int exponent) { + if (exponent == 0) + return 1; + else if (exponent > 0) + return base * power(base, exponent - 1); + +} + +int main() { + int base,exponent,result; + printf("enter the base value-->"); + scanf("%d",&base); + printf("enter the value of exponential power-->"); + scanf("%d",&exponent); + result = power(base, exponent); + + + printf("%d^%d = %d\n", base, exponent, result); + + return 0; +} \ No newline at end of file From 37663a71f2cdc28590e81932b68c5b2c4e646ac6 Mon Sep 17 00:00:00 2001 From: Akshat-mittal1 <145672927+Akshat-mittal1@users.noreply.github.com> Date: Sat, 21 Jun 2025 20:39:46 +0530 Subject: [PATCH 2/2] Update acm_dsa_pr7.c --- acm_dsa_pr7.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/acm_dsa_pr7.c b/acm_dsa_pr7.c index 84c3420..bfb615a 100644 --- a/acm_dsa_pr7.c +++ b/acm_dsa_pr7.c @@ -20,4 +20,4 @@ int main() { printf("%d^%d = %d\n", base, exponent, result); return 0; -} \ No newline at end of file +}