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

Add files via upload #30

Open
wants to merge 1 commit into
base: main
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
23 changes: 23 additions & 0 deletions C_Project-main/big2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <stdio.h>
biggest2()
{
int num1, num2;
// Ask user to enter the two numbers
printf("Please Enter Two different values\n");
// Read two numbers from the user
scanf("%d %d", &num1, &num2);
if(num1 > num2)
{
printf("%d is Largest\n", num1);
}
else if (num2 > num1)
{
printf("%d is Largest\n", num2);
}
else
{
printf("Both are Equal\n");
}
// return 0;
}

23 changes: 23 additions & 0 deletions C_Project-main/big3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <stdio.h>

int biggest3() {

double n1, n2, n3;

printf("\n\nEnter three different numbers: ");
scanf("%lf %lf %lf", &n1, &n2, &n3);

// if n1 is greater than both n2 and n3, n1 is the largest
if (n1 >= n2 && n1 >= n3)
printf("%.2f is the largest number.", n1);

// if n2 is greater than both n1 and n3, n2 is the largest
if (n2 >= n1 && n2 >= n3)
printf("%.2f is the largest number.", n2);

// if n3 is greater than both n1 and n2, n3 is the largest
if (n3 >= n1 && n3 >= n2)
printf("%.2f is the largest number.", n3);

return 0;
}
19 changes: 19 additions & 0 deletions C_Project-main/fact.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <stdio.h>
factorial() {
int n, i;
unsigned long long fact = 1;
printf("\n\nEnter an integer to find factorial: ");
scanf("%d", &n);

// shows error if the user enters a negative integer
if (n < 0)
printf("Error! Factorial of a negative number doesn't exist.");
else {
for (i = 1; i <= n; ++i) {
fact *= i;
}
printf("Factorial of %d = %llu \n", n, fact);
}

// return 0;
}
29 changes: 29 additions & 0 deletions C_Project-main/fib.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <stdio.h>
int fibonacci() {

int i, n;

// initialize first and second terms
int t1 = 0, t2 = 1;

// initialize the next term (3rd term)
int nextTerm = t1 + t2;

// get no. of terms from user
printf("\nEnter the number of terms to find fibonacci: ");
scanf("%d", &n);

// print the first two terms t1 and t2
printf("Fibonacci Series: %d, %d, ", t1, t2);

// print 3rd to nth terms
for (i = 3; i <= n; ++i) {
printf("%d, ", nextTerm);
t1 = t2;
t2 = nextTerm;
nextTerm = t1 + t2;
}

return 0;
}

12 changes: 12 additions & 0 deletions C_Project-main/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include<stdio.h>
main() {

biggest2();
biggest3();
factorial();
reverse();
fibonacci();
palindrome();
sum2num();
sorting();
}
22 changes: 22 additions & 0 deletions C_Project-main/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
ABC.exe:main.o big2.o big3.o fact.o rev.o palindrome.o sum2num.o sort.o fib.o
gcc -o ABC.exe main.o big2.o big3.o fact.o rev.o palindrome.o sum2num.o sort.o fib.o
main.o:main.c
gcc -c main.c
big2.o:big2.c
gcc -c big2.c
big3.o:big3.c
gcc -c big3.c
fact.o:fact.c
gcc -c fact.c
rev.o:rev.c
gcc -c rev.c
palindrome.o:palindrome.c
gcc -c palindrome.c
sum2num.o:sum2num.c
gcc -c sum2num.c
sort.o:sort.c
gcc -c sort.c
fib.o:fib.c
gcc -c fib.c
clean:
rm -rf *.o
22 changes: 22 additions & 0 deletions C_Project-main/palindrome.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <stdio.h>
int palindrome() {
int n, reversed = 0, remainder, original;
printf("\n\nEnter an integer to check a palindrom: ");
scanf("%d", &n);
original = n;

// reversed integer is stored in reversed variable
while (n != 0) {
remainder = n % 10;
reversed = reversed * 10 + remainder;
n /= 10;
}

// palindrome if orignal and reversed are equal
if (original == reversed)
printf("%d is a palindrome.", original);
else
printf("%d is not a palindrome.", original);

return 0;
}
24 changes: 24 additions & 0 deletions C_Project-main/rev.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <stdio.h>
reverse()
{
char str[1000], rev[1000];
int i, j, count = 0;
printf("\n\nEnter string to reverse:");
scanf("%s", str);
printf("\nString Before Reverse: %s", str);
//finding the length of the string
while (str[count] != '\0')
{
count++;
}
j = count - 1;

//reversing the string by swapping
for (i = 0; i < count; i++)
{
rev[i] = str[j];
j--;
}

printf("\nString After Reverse: %s \n\n", rev);
}
36 changes: 36 additions & 0 deletions C_Project-main/sort.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <stdio.h>
void sorting()
{

int i, j, a, n, number[30];
printf("\n\nEnter the value of N \n");
scanf("%d", &n);

printf("Enter the numbers \n");
for (i = 0; i < n; ++i)
scanf("%d", &number[i]);

for (i = 0; i < n; ++i)
{

for (j = i + 1; j < n; ++j)
{

if (number[i] > number[j])
{

a = number[i];
number[i] = number[j];
number[j] = a;

}

}

}

printf("The numbers arranged in ascending order are given below \n");
for (i = 0; i < n; ++i)
printf("%d\n", number[i]);

}
14 changes: 14 additions & 0 deletions C_Project-main/sum2num.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include<stdio.h>

int sum2num() {
int a, b, sum;

printf("\n\nEnter two no: ");
scanf("%d %d", &a, &b);

sum = a + b;

printf("Sum : %d", sum);

return(0);
}