Skip to content
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
8 changes: 8 additions & 0 deletions C/Addition.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include<stdio.h>
void main()
{ int a,b,c;
printf("Enter two Numbers : ");
scanf("%d %d",&a,&b);
c=a+b;
printf("The Sum is %d",c);
}
17 changes: 17 additions & 0 deletions C/Address of 1-D array.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include<stdio.h>
int main()
{
int a[100],i,n,*add;
printf("enter the size");
scanf("%d",&n);
printf("enter the no");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
add=(a+(i*sizeof(int)));
printf("%u\n",add);
}
}
98 changes: 98 additions & 0 deletions C/AllTempScalesConv.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#include <stdio.h>
#include <stdlib.h>

// Function that performs the conversion
double convertTemp(double initValue, int initScale, int finalScale){
double finalValue;
switch(initScale){
// Celsius
case 1:
// Celsius to Kelvin
if(finalScale == 1){
finalValue = initValue + 273.15;
}
// Celsius to Fahrenheit
else if(finalScale == 2){
finalValue = (initValue * 9 / 5) + 32;
}
break;
case 2:
// Kelvin to Celsius
if(finalScale == 1){
finalValue = initValue - 273.15;
}
// Kelvin to Fahrenheit
else if(finalScale == 2){
finalValue = ((initValue - 273.15) * 9 / 5) + 32;
}
break;
case 3:
// Fahrenheit to Celsius
if(finalScale == 1){
finalValue = (initValue - 32) * 5 / 9;
}
// Fahrenheit to Kelvin
else if(finalScale == 2){
finalValue = ((initValue - 32) * 5 / 9) + 273,15;
}
break;

}
return finalValue;
}

int main(){
int option;
double initialValue, finalValue;
while(1){
// main menu
printf("\n0 - Exit\n");
printf("1 - Convert from Celsius to Kelvin\n");
printf("2 - Convert from Celsius to Fahrenheit\n");
printf("3 - Convert from Kelvin to Fahrenheit\n");
printf("4 - Convert from Kelvin to Celsius\n");
printf("5 - Convert from Fahrenheit to Celsius\n");
printf("6 - Convert from Fahrenheit to Kelvin\n");

printf("Select a number: ");
scanf("%d",&option);
if(!option){
printf("Ending program\n");
return 0;
}

printf("Please enter the initial value: ");
scanf("%lf",&initialValue);

switch(option){
case 1:
finalValue = convertTemp(initialValue,1,1);
printf("Valor em Kelvin: %.2lf",finalValue);
break;
case 2:
finalValue = convertTemp(initialValue,1,2);
printf("Valor em Fahrenheit: %.2lf",finalValue);
break;
case 3:
finalValue = convertTemp(initialValue,2,1);
printf("Valor em Celsius: %.2lf",finalValue);
break;
case 4:
finalValue = convertTemp(initialValue,2,2);
printf("Valor em Fahrenheit: %.2lf",finalValue);
break;
case 5:
finalValue = convertTemp(initialValue,3,1);
printf("Valor em Celsius: %.2lf",finalValue);
break;
case 6:
finalValue = convertTemp(initialValue,3,1);
printf("Valor em Kelvin: %.2lf",finalValue);
break;

}
printf("\n");
}

return 0;
}
71 changes: 71 additions & 0 deletions C/Anagram-Program-in-C
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int checkAnagram(char *str1, char *str2);

int main()
{
char str1[100], str2[100];

printf("Function : whether two given strings are anagram :");
printf("\nExample : pears and spare, stone and tones :");

printf(" Input the first String : ");
fgets(str1, sizeof str1, stdin);
printf(" Input the second String : ");
fgets(str2, sizeof str2, stdin);

if(checkAnagram(str1, str2) == 1)
{
str1[strlen(str1)-1] = '\0';
str2[strlen(str2)-1] = '\0';
printf(" %s and %s are Anagram.\n\n",str1,str2);
}
else
{
str1[strlen(str1)-1] = '\0';
str2[strlen(str2)-1] = '\0';
printf(" %s and %s are not Anagram.\n\n",str1,str2);
}
return 0;
}


//Function to check whether two passed strings are anagram or not

int checkAnagram(char *str1, char *str2)
{
int str1ChrCtr[256] = {0}, str2ChrCtr[256] = {0};
int ctr;

/* check the length of equality of Two Strings */

if(strlen(str1) != strlen(str2))
{
return 0;
}

//count frequency of characters in str1

for(ctr = 0; str1[ctr] != '\0'; ctr++)
{
str1ChrCtr[str1[ctr]]++;
}

//count frequency of characters in str2

for(ctr = 0; str2[ctr] != '\0'; ctr++)
{
str2ChrCtr[str2[ctr]]++;
}

//compare character counts of both strings

for(ctr = 0; ctr < 256; ctr++)
{
if(str1ChrCtr[ctr] != str2ChrCtr[ctr])
return 0;
}
return 1;
}
43 changes: 43 additions & 0 deletions C/SwapByRefandCopy.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <stdio.h>

// Swap_ref creates a temporary variable temp and dereffrences the address that was sent to it(this is done to get the actual
// value of the int in the memory space). the dereffrencing allows us to change the actual values.
void swap_ref(int* a, int* b){
int temp = *a;

*a = *b;
*b = temp;
}

// Swap however does not use addresses and reffrences and only alters the ints within it's own scope
void swap(int a, int b)
{
int temp = a;
a = b;
b = temp;
}

int main(void) {
//Declare 2 int variables that are going to be swapped by reference
int a = 1;
int b = 2;

printf("%d\n", a);
printf("%d\n", b);

//Pass the Address of the Values to the Swap function
swap_ref(&a, &b);

printf("%d\n", a);
printf("%d\n", b);

int c = 5;
int d = 10;
printf("%d\n", c);
printf("%d\n", d);

swap(c, d);

printf("%d\n", c);
printf("%d\n", d);
}
15 changes: 15 additions & 0 deletions C/SwapIntegers.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <stdio.h>
int main()
{
int num1=5, num2=10;

printf("The numbers are: %d and %d", &num1,&num2);

num1=num1+num2; //num1=15 and num2=10
num2=num1-num2; //num1=15 and num2=5
num1=num1-num2; //num1=10 and num2=5

printf("The numbers have been swapped with new positions: %d and %d", &num1,&num2);

return 0;
}
15 changes: 15 additions & 0 deletions C/SwapIntegersWithout3rdVariable(Arithmatic).c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <stdio.h>
int main()
{
int num1=5, num2=10;

printf("The numbers are: %d and %d", &num1,&num2);

num1=num1+num2; //num1=15 and num2=10
num2=num1-num2; //num1=15 and num2=5
num1=num1-num2; //num1=10 and num2=5

printf("The numbers have been swapped with new positions: %d and %d", &num1,&num2);

return 0;
}
15 changes: 15 additions & 0 deletions C/SwapValueUsingThirdVariable.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Swap two integers using third variable


#include<stdio.h>
int main()
{
int a,b,c;
printf("Enter two no :\n");
scanf("%d%d",&a,&b);
c=a;
a=b;
b=c;
printf("After swapping value of a = %d\n b =%d",a,b);
return 0;
}
15 changes: 15 additions & 0 deletions C/SwapValueWithoutUsingThirdVariable.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Swap two integers without using third variable


#include<stdio.h>
int main()
{
int a, b;
printf("Enter two no :\n");
scanf("%d%d",&a,&b);
a = a^b;
b = a^b;
a= a^b;
printf("After swapping value of a and b : %d,%d",a,b);
return 0;
}
13 changes: 13 additions & 0 deletions C/Swapping(without using extra variable).cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
printf("Enter a and b\n");
scanf("%d%d",&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf("After swapping a and b are %d %d",a,b);
getch();
}
8 changes: 8 additions & 0 deletions C/Temperature.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include<stdio.h>
void main()
{ float a,c,f;
printf("Enter the Temperature in Celcius : ");
scanf("%f",&c);
f=c*(9/5)+32;
printf("Temperature in Fahernheit is %f",f);
}
38 changes: 38 additions & 0 deletions C/TemperatureSwitch.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <stdio.h>

int main()
{
// The resultant temperatures can be in decimals as well, so we use double
double c, f, result;
// We use an integer type data to run the switch statement
int choice;
printf("Select your choice: \n");
printf("1. Celcius to Fahrenheit\n");
printf("2. Fahrenheit to Celcius\n");

printf("Enter your choice: ");
scanf("%d", &choice);

// We compute the temperatures for both the cases here respectively
switch(choice)
{
case 1:
printf("Enter the temperature in Celcius: ");
scanf("%lf", &c);
result = (9 / 5) * c + 32;
break;
case 2:
printf("Enter the temperature in Fahrenheit: ");
scanf("%lf", &f);
result = (5 / 9) * (f - 32);
break;

// This case gets activated when the user inputs anything othrer than 1 or 2
default:
printf("Invalid case!\n");
}

// Printing out the result according to the computation
printf("The resultant temperature is: %lf", result);
return 0;
}
13 changes: 13 additions & 0 deletions C/TernaryOperator.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//Largest number among 3 numbers using ternary operator

#include<stdio.h>
int main()
{
float a,b,c,large;
printf("Enter any 3 numbers\n");
scanf("%f%f%f",&a,&b,&c);
large = a>b? (a>c?a:c): (b>c?b:c);
printf("The larger no is :%f\n", large);
return 0;

}
10 changes: 10 additions & 0 deletions C/Trif.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include<stdio.h>
#include<math.h>
void main()
{ double a,b;
printf("Enter the degree : ");
scanf("%lf",&a);
a=(a*3.14)/180;
b=sin(a);
printf("Sine is %lf",b);
}
Loading