diff --git a/Armstrong number.c b/Armstrong number.c new file mode 100644 index 0000000..00caa46 --- /dev/null +++ b/Armstrong number.c @@ -0,0 +1,52 @@ +#include +#include + +int check_armstrong(int); + +int main() +{ + int num_1,num_2; + printf("Enter first number : "); + scanf("%d",&num_1); + printf("Enter second number : "); + scanf("%d",&num_2); + printf("\nThe armstrong numbers in the interval %d to %d are as follows: \n",num_1,num_2); + for(int i=num_1;i<=num_2;i++) + { + if(check_armstrong(i)==1) + { //checking whether the num is armstrong or + printf("%d\n",i); //if it is then printing its value. + } + } + +} + +int check_armstrong(int p) +{ + int temp,flag; + temp=p; + flag=p; + int rem=0,total=0,count=0; + while(p) //this while loop is for counting the total number of digits in the number + { + rem=p%10; + p=p/10; + count++; + } + rem=0; + while(temp) //this while loop is for calculating the sum of digits raised to the total + { //count of digits in the number as power + rem=temp%10; + total+=pow(rem,count); + temp=temp/10; + } + if(total==flag) + { + return 1; + } + else + { + return 0; + } + return 0; +} diff --git a/Operation on arrays.c b/Operation on arrays.c new file mode 100644 index 0000000..0939408 --- /dev/null +++ b/Operation on arrays.c @@ -0,0 +1,88 @@ +//Find the Union and Intersection of two sorted arrays. +#include + +void operations_on_array(int arr1[],int arr2[],int m,int n); + +int main() +{ + printf("Implementing union and intersection of two sorted arrays: \n"); + int m,n; + printf("Enter the size of first array : "); + scanf("%d",&m); + printf("Enter the elememts of first array (in sorted manner): \n"); + int arr1[m]; + for(int i=0;iarr2[j]) + { + printf("%d ",arr2[j]); + j++; + } + else if(arr1[i]==arr2[j]) + { + printf("%d ",arr1[i]); + i++; + j++; + } + } + while(i