-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7579fcf
commit 435c57b
Showing
37 changed files
with
394 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
Oops, something went wrong.