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

c files added #25

Open
wants to merge 2 commits 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
22 changes: 22 additions & 0 deletions big2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#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;
}
24 changes: 24 additions & 0 deletions big3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <stdio.h>

biggest3() {

double n1, n2, n3;

printf("\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.\n", n3);

// return 0;
}

28 changes: 28 additions & 0 deletions fab.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <stdio.h>
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: ");
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;
}
19 changes: 19 additions & 0 deletions 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("\nEnter an integer: ");
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", n, fact);
}

// return 0;
}
11 changes: 11 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <stdio.h>
main() {
biggest2();
factorial();
reverse();
pallindrome();
biggest3();
sumnum();
fibonacci();
sortnum();
}
21 changes: 21 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
ABC.exe:main.o big2.o fact.o rev.o big3.o fab.o palln.o sortn.o sum2.o
gcc -o ABC.exe main.o big2.o fact.o rev.o big3.o fab.o palln.o sortn.o sum2.o

main.o:main.c
gcc -c main.c
big2.o:big2.c
gcc -c big2.c
fact.o:fact.c
gcc -c fact.c
rev.o:rev.c
gcc -c rev.c
big3.o:big3.c
gcc -c big3.c
fab.o:fab.c
gcc -c fab.c
palln.o:palln.c
gcc -c palln.c
sortn.o:sortn.c
gcc -c sortn.c
sum2.o:sum2.c
gcc -c sum2.c
22 changes: 22 additions & 0 deletions palln.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <stdio.h>
pallindrome() {
int n, reversed = 0, remainder, original;
printf("\nEnter an integer: ");
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.\n", original);

//return 0;
}
26 changes: 26 additions & 0 deletions rev.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <stdio.h>
reverse()
{
char str[1000], rev[1000];
int i, j, count = 0;
printf("\nEnter string to reverse\n");
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", rev);

// return 0;
}
40 changes: 40 additions & 0 deletions sortn.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <stdio.h>

sortnum()
{
int arr1[100];
int n, i, j, tmp;


printf("\n\nsort elements of array in ascending order :\n ");
printf("----------------------------------------------\n");

printf("Input the size of array : ");
scanf("%d", &n);

printf("Input %d elements in the array :\n",n);
for(i=0;i<n;i++)
{
printf("element - %d : ",i);
scanf("%d",&arr1[i]);
}

for(i=0; i<n; i++)
{
for(j=i+1; j<n; j++)
{
if(arr1[j] <arr1[i])
{
tmp = arr1[i];
arr1[i] = arr1[j];
arr1[j] = tmp;
}
}
}
printf("\nElements of array in sorted ascending order:\n");
for(i=0; i<n; i++)
{
printf("%d ", arr1[i]);
}
printf("\n\n");
}
14 changes: 14 additions & 0 deletions sum2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <stdio.h>
sumnum() {

int number1, number2, sum;

printf("\nEnter two integers: ");
scanf("%d %d", &number1, &number2);

// calculating sum
sum = number1 + number2;

printf("%d + %d = %d", number1, number2, sum);
//return 0;
}
1 change: 0 additions & 1 deletion test

This file was deleted.