Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Tejas20-03 authored Jun 26, 2022
1 parent 7579fcf commit 435c57b
Show file tree
Hide file tree
Showing 37 changed files with 394 additions and 0 deletions.
31 changes: 31 additions & 0 deletions ArithematicOperations_1DArray.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <stdio.h>
int main()
{
int a[100], i, n, sum_even, sum_odd, avg;
printf("Enter Number of Elements in array A : ");
scanf("%d", &n);
printf("\nEnter Elements in ARRAY A: ");
for (i = 0; i < n; i++)
{
scanf("%d", a[i]);
}
sum_odd = 0;
sum_even = 0;
avg = 0;
for (i = 0; i < n; i++)
{
if (a[i] % 2 == 0)
{
sum_even += a[i];
}
else
{
sum_odd += a[i];
}
}
avg = (sum_even + sum_odd) / n;
printf("Sum of odd Number in the Array: %d \n", sum_odd);
printf("Sum of Even Number in the Array: %d \n", sum_even);
printf("Average of Numbers in the Array: %d \n", avg);
return 0;
}
Binary file added ArithematicOperations_1DArray.exe
Binary file not shown.
19 changes: 19 additions & 0 deletions Factorial_Recursion.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include<stdio.h>
int fact(int a)
{
if(a>=1)
{
return a*fact(a-1);
}
else{
return 1;
}
}
int main()
{
int n;
printf("Enter Number to find Factorial of: ");
scanf("%d",&n);
printf("Factorial of %d is %d",n,fact(n));
return 0;
}
Binary file added Factorial_Recursion.exe
Binary file not shown.
17 changes: 17 additions & 0 deletions Factorial_do-while.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include<stdio.h>
int main()
{
int n,i,fact;
fact=1;
printf("Enter Number to find the Factorial of : ");
scanf("%d",&n);
i=n;
do
{
fact=fact*i;
i--;
}
while(i>0);
printf("Factorial of %d is %d",n,fact);
return 0;
}
Binary file added Factorial_do-while.exe
Binary file not shown.
25 changes: 25 additions & 0 deletions GCD_Functions.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include<stdio.h>
int hcf(int a,int b)
{
int min,i;
min=a>b?a:b;
for(i=min;i>0;i--)
{
if(a%i==0&&b%i==0)
{
break;
}
}
return i;
}
int main()
{
int a,b,gcd;
printf("Enter First Number: ");
scanf("%d",&a);
printf("Enter Second Number: ");
scanf("%d",&b);
gcd=hcf(a,b);
printf("\nGCD of %d and %d is %d",a,b,gcd);

}
Binary file added GCD_Functions.exe
Binary file not shown.
15 changes: 15 additions & 0 deletions GCD_forLOOP.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include<stdio.h>
int main()
{
int a,b,i,hcf;
printf("Enter First Number: ");
scanf("%d",&a);
printf("Enter Second Number: ");
scanf("%d",&b);
for(i=2;(i<=a)||(i<=b);i++)
{
(a%i==0)&&(b%i==0)?hcf=i:hcf=0;
}
printf("HCF of %d and %d is %d",a,b,hcf);
return 0;
}
Binary file added GCD_forLOOP.exe
Binary file not shown.
15 changes: 15 additions & 0 deletions Greatest_TernaryOperator.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <stdio.h>
int main()
{
int a, b, c, comp;
printf("Comparing 3 Numbers \n");
printf("\nEnter First Number: ");
scanf("%d", &a);
printf("\nEnter Second Number: ");
scanf("%d", &b);
printf("\nEnter Third Number: ");
scanf("%d", &c);
comp = (a > b && a > c) ? printf("%d is Greatest among all \n", a) : (b > a && b > c) ? printf("%d is gratest among all \n", b)
: printf("%d is greatest among all\n", c);
return 0;
}
Binary file added Greatest_TernaryOperator.exe
Binary file not shown.
25 changes: 25 additions & 0 deletions LCM_functions.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include<stdio.h>
int lcm(int a,int b)
{
int max,i;
max=a>b?a:b;
for(i=max;i>0;i=i+max)
{
if(a%i==0&&b%i==0)
{
break;
}
}
return i;
}
int main()
{
int x,y,lcmul;
printf("Enter First Number : ");
scanf("%d",&x);
printf("Enter Second Number : ");
scanf("%d",&y);
lcmul=lcm(x,y);
printf("LCM of %d and %d is %d",x,y,lcmul);
return 0;
}
Binary file added LCM_functions.exe
Binary file not shown.
24 changes: 24 additions & 0 deletions Linear_Search.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <stdio.h>
int main()
{
int a[100], n, i, check, b;
printf("Enter Number of Elements in a Array: ");
scanf("%d", &n);
printf("\n Enter Elements in Array\n");
for (i = 0; i < n; i++)
{
scanf("%d", &a[i]);
}
printf("Enter Number to Search for: ");
scanf("%d", &check);
for (i = 0; i < n; i++)
{
if (a[i] == check)
{
b = i;
break;
}
}
printf(" \n %d is Found at %d position in Array ", check, i + 1);
return 0;
}
Binary file added Linear_Search.exe
Binary file not shown.
25 changes: 25 additions & 0 deletions Pallindrome.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <stdio.h>
int main()
{
int a, reverese, i, remainder, temp;
reverese = 0;
printf("Enter Number to check for: ");
scanf("%d", &a);
temp = a;
while (a != 0)
{
remainder = a % 10;
reverese = reverese * 10 + remainder;
a = a / 10;
}
printf("Reverese of %d is : %d \n", temp, reverese);
if (temp == reverese)
{
printf("%d is a Pallindrome", temp);
}
else
{
printf("%d is not a Pallindrome", temp);
}
return 0;
}
Binary file added Pallindrome.exe
Binary file not shown.
11 changes: 11 additions & 0 deletions PerimeterArea_Circle.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <stdio.h>
int main()
{
float r;
float pi = 3.14;
printf("Enter Radius of Circle: ");
scanf("%f", &r);
printf("Perimeter of Circle: %f ", 2 * pi * r);
printf("Area of Circle: %f", pi * r * r);
return 0;
}
Binary file added PerimeterArea_Circle.exe
Binary file not shown.
22 changes: 22 additions & 0 deletions Prime_Composite_functions.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include<stdio.h>
int check(int a)
{
int i,count;
count=0;
for(i=2;i<a;i++)
{
if(a%i==0)
{
count+=1;
}
}
count>0?printf("%d is a Composite Number",a):printf("%d is a Prime Number",a);
}
int main()
{
int a;
printf("Enter Number to Check for Prime or Composite: ");
scanf("%d",&a);
check(a);
return 0;
}
Binary file added Prime_Composite_functions.exe
Binary file not shown.
37 changes: 37 additions & 0 deletions Prime_Composite_recursion.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <stdio.h>
int check(int a)
{
int i;
if (i == 1)
{
return 1;
}
else
{
if (a % i == 0)
{
return 0;
}
else
{
i = i - 1;
check(a);
}
}
}
int main()
{
int a, b;
printf("Enter Number to check for Prime or Composite: ");
scanf("%d", &a);
b = check(a);
if (b == 1)
{
printf("\nPrime Number!!\n");
}
else
{
printf("Composite Number!!\n");
}
return 0;
}
Binary file added Prime_Composite_recursion.exe
Binary file not shown.
17 changes: 17 additions & 0 deletions Recursion_HW.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <stdio.h>
int printHW(int count)
{
if (count == 0)
{
return 0;
}
printf("Hello World\n");
printHW(count - 1);
}
int main()
{
int n;
printf("Enter Number of Times to print HW: ");
scanf("%d", &n);
printHW(n);
}
Binary file added Recursion_HW.exe
Binary file not shown.
16 changes: 16 additions & 0 deletions SumUptoN.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <stdio.h>
int main()
{
int n, sum, temp;
sum = 0;
printf("Enter Number upto which sum is required : ");
scanf("%d", &n);
temp = n;
while (n >= 0)
{
sum = sum + n;
n -= 1;
}
printf("Sum of %d Natural Number is %d", temp, sum);
return 0;
}
Binary file added SumUptoN.exe
Binary file not shown.
20 changes: 20 additions & 0 deletions Swap_CallbyReference.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include<stdio.h>
int swap(int *a,int *b)
{
int temp;
temp=*a;
*a=*b;
*b=temp;
}
int main()
{
int a,b;
printf("Enter First Number: ");
scanf("%d",&a);
printf("Enter Second Number: ");
scanf("%d",&b);
printf("Before Swapping... \n A= %d and B= %d",a,b);
swap(&a,&b);
printf("\n After Swapping... \n A=%d and B=%d",a,b);
return 0;
}
Binary file added Swap_CallbyReference.exe
Binary file not shown.
20 changes: 20 additions & 0 deletions Swap_CallbyValue.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include<stdio.h>
int swap(int x,int y)
{
int temp;
temp=x;
x=y;
y=temp;
printf("After Swapping A=%d and B= %d",x,y);
}
int main()
{
int a,b;
printf("Enter First Number: ");
scanf("%d",&a);
printf("Enter Second Number: ");
scanf("%d",&b);
printf("\n Before Swapping A=%d and B=%d \n",a,b);
swap(a,b);
return 0;
}
Binary file added Swap_CallbyValue.exe
Binary file not shown.
Loading

0 comments on commit 435c57b

Please sign in to comment.