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-Project_Anusha #14

Open
wants to merge 3 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 ANUSHA/big2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <stdio.h>

biggest2() {
int a, b;
printf("Please Enter Two different values\n");
scanf("%d %d", &a, &b);

if(a > b)
{
printf("%d is Largest\n", a);
}
else if (b > a)
{
printf("%d is Largest\n", b);
}
else
{
printf("Both are Equal\n");
}

// return 0;
}
16 changes: 16 additions & 0 deletions ANUSHA/big3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <stdio.h>
biggest3()
{
int num1, num2, num3, largest;

printf("\n Enter the number1 = ");
scanf("%d", &num1);
printf("\n Enter the number2 = ");
scanf("%d", &num2);
printf("\n Enter the number3 = ");
scanf("%d", &num3);

largest =((num1>num2 && num1>num3)?num1: (num2>num3)?num2:num3);
printf("Largest number = %d \n",largest);
// return 0;
}
19 changes: 19 additions & 0 deletions ANUSHA/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("Enter 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, fact);
}

// return 0;
}
29 changes: 29 additions & 0 deletions ANUSHA/fib.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#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("Enter 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;
}

11 changes: 11 additions & 0 deletions ANUSHA/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
main () {
biggest2();
factorial();
reverse();
pallindrome();
biggest3();
sum2();
fibonacci();
sortnumbers();
}

21 changes: 21 additions & 0 deletions ANUSHA/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
ABC.exe:main.o big2.o big3.o fact.o fib.o pal.o rev.o sort.o sum2.o
gcc -o ABC.exe main.o big2.o big3.o fact.o fib.o pal.o rev.o sort.o sum2.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
fib.o:fib.c
gcc -c fib.c
pal.o:pal.c
gcc -c pal.c
rev.o:rev.c
gcc -c rev.c
sort.o:sort.c
gcc -c sort.c
sum2.o:sum2.c
gcc -c sum2.c
19 changes: 19 additions & 0 deletions ANUSHA/pal.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include<stdio.h>
pallindrome()
{
int n,r,sum=0,temp;
printf("\nenter the number=");
scanf("%d",&n);
temp=n;
while(n>0)
{
r=n%10;
sum=(sum*10)+r;
n=n/10;
}
if(temp==sum)
printf("palindrome number ");
else
printf("not palindrome");
//return 0;
}
25 changes: 25 additions & 0 deletions ANUSHA/rev.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* using temp variable */
#include <stdio.h>
#include <string.h>

reverse()
{
char Str[100], temp;
int i, j, len;

printf("\n Actual : ");
gets(Str);

len = strlen(Str) - 1;

for (i = 0; i < strlen(Str)/2; i++)
{
temp = Str[i];
Str[i] = Str[len];
Str[len--] = temp;
}

printf("\n Result = %s", Str);

// return 0;
}
29 changes: 29 additions & 0 deletions ANUSHA/sort.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// C Program To Arrange Numbers in Ascending Order
#include <stdio.h>
sortnumbers(){
int num[25];
int a, j, i, n;

// Asking for input
printf("Enter total no. of elements: ");
scanf("%d", &n);

printf("Enter the numbers one by one\n");
for (i = 0; i < n; ++i){
scanf("%d", &num[i]);
}
for (i = 0; i < n; ++i){
for (j = i + 1; j < n; ++j){
if (num[i] > num[j]){
a = num[i];
num[i] = num[j];
num[j] = a;
}
}
}
printf("Numbers in ascending order: \n");
for (i = 0; i < n; ++i){
printf("%d\n", num[i]);
}
// return 0;
}
17 changes: 17 additions & 0 deletions ANUSHA/sum2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <stdio.h>

sum2() {
int a, b, result;

printf("Enter first number : ");
scanf("%d", &a);

printf("Enter second number : ");
scanf("%d", &b);

//add two numbers
result = a + b;
printf("Sum : %d\n", result);

// return 0;
}