├── .gitignore ├── README.md └── codes ├── 3digit_sum.c ├── add_float.c ├── add_int.c ├── armstrong_3digit.c ├── ascii.c ├── circum_area.c ├── compound_interest.c ├── even_odd_iff.c ├── even_odd_ter_bit.c ├── even_odd_ter_mod.c ├── farehn_to_celscius.c ├── final_velocity.c ├── greatest_iff.c ├── greatest_ter.c ├── gross_sal.c ├── hello.c ├── interchange_3var.c ├── leap_year_iff.c ├── leap_year_ter.c ├── lowercase_upper.c ├── palindrom.c ├── quadratic_root.c ├── reverse.c ├── simple_intrest.c ├── st_line.c ├── swaping.c ├── swaping_3rd_var.c ├── swping_add.c ├── uppercase_lower.c ├── velocity.c └── velocity1.c /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Kernel Module Compile Results 46 | *.mod* 47 | *.cmd 48 | .tmp_versions/ 49 | modules.order 50 | Module.symvers 51 | Mkfile.old 52 | dkms.conf 53 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # This is project for beginer who wants to learn C language. 2 | # Here is a collection of program. Which will help to beginer to makes basic programs in C. 3 | # This project contains all the programs which is needed for learning C language , therefore it is very helpful for beginers. 4 | # When I Was learning this language , I faced some problems in some program, Then I decided that I will Make a project which will contain all the basic programs so that other beginers can learn easily. 5 | 6 | # Following are the collection of programs :- 7 | 8 | # [1) Program to print HELLO WORLD.](codes/hello.c) 9 | # [2) Program to Add two numbers.](codes/add_int.c) 10 | # [3) Program to Add two numbers in which one is of float type.](codes/add_float.c) 11 | # [4) Program for swaping using 3rd variable.](codes/swaping_3rd_var.c) 12 | # [5) Program for swaping without using 3rd variable ( By XOR operator).](codes/swaping.c) 13 | # [6) Program for swaping without using 3rd variable ( By addtion).](codes/swping_add.c) 14 | # [7) Program for conversion of temprature from Farinheit to Celcius.](codes/farehn_to_celscius.c) 15 | # [8) Program for calculation of circumference and area of circle by given radius.](codes/circum_area.c) 16 | # [9) Program for velocity conversion from km/hr to m/s.](codes/velocity.c) 17 | # [10) Program for velocity conversion from m/s to km/hr.](codes/velocity1.c) 18 | # [11) Program for calculation of simple interest.](codes/simple_intrest.c) 19 | # [12) Program for calculation of compound interest.](codes/compound_interest.c) 20 | # [13) Program for calculation of equation of straight line passing through (X1,Y1) & (X2,Y2).](codes/st_line.c) 21 | # [14) Program for conversion of upper case charecter to lower case.](codes/uppercase_lower.c) 22 | # [15) Program for conversion of lower case charecter to upper case.](codes/lowercase_upper.c) 23 | # [16) Program for printing the ASCII value of the charecter.](codes/ascii.c) 24 | # [17) Program for interchanging 3 values X ,Y , Z.](codes/interchange_3var.c) 25 | # [18) Program for calculating the final velocity.](codes/final_velocity.c) 26 | # [19) Program for finding Gross Salary. Where DA is 20% of Basic salary and HRA is 25% of Basic salary ,Gross salary = DA + HRA](codes/gross_sal.c) 27 | # [20) Program for Checking even or odd by Ternary operator using modulas operator.](codes/even_odd_ter_mod.c) 28 | # [21) Program for Checking even or odd by Ternary operator using bitwise operator.](codes/even_odd_ter_bit.c) 29 | # [22) Program for finding greatest among 3 number using ternary operator.](codes/greatest_ter.c) 30 | # [23) Program for checking given year is LEAP or NOT using Ternary operator.](codes/leap_year_ter.c) 31 | # [24) Program for Finding the sum of the digit of 3 digit number without Loop.](codes/3digit_sum.c) 32 | # [25) Program for finding the roots of the quadratic equation.](codes/quadratic_root.c) 33 | # [26) Program for checking even or odd number using if / else statement.](codes/even_odd_iff.c) 34 | # [27) Program for checking given year is LEAP or NOT using if / else statement.](codes/leap_year_iff.c) 35 | # [28) Program for finding greatest among 3 number using if / else statement.](codes/greatest_iff.c) 36 | # [29) Program for reverse the given 3 digit number without loop.](codes/reverse.c) 37 | # [30) Program for Checking the number whether the number is PALINDROM or NOT.](codes/palindrom.c) 38 | # [31) Program for checking the number for armsstrong number of 3 digit without loop.](codes/armstrong_3digit.c) 39 | -------------------------------------------------------------------------------- /codes/3digit_sum.c: -------------------------------------------------------------------------------- 1 | // This is the program for finding the sum of digits 3 digit number 2 | /* Sample Input : 3 | Enter the 3 digit number : 123 4 | Sample Output : 5 | The sum of 3 digit number is : 6 6 | */ 7 | 8 | #include 9 | 10 | void main() 11 | { 12 | int num ,n,sum=0; // variable declaration 13 | 14 | printf("Enter the 3 digit number :"); 15 | scanf("%d",&num); // input number 16 | 17 | n = num % 10; // separate the unit place of the number 18 | sum = sum + n ; // add it to sum 19 | num = num/10; // remove it unit place 20 | 21 | // For 3 digit number repeat this step for 3 times. 22 | 23 | n = num % 10; 24 | sum = sum + n ; 25 | num = num/10; 26 | 27 | n = num % 10; 28 | sum = sum + n ; 29 | num = num/10; 30 | 31 | printf("The sum of 3 digit number is : %d",sum); // output 32 | } 33 | -------------------------------------------------------------------------------- /codes/add_float.c: -------------------------------------------------------------------------------- 1 | // This is program for adding two numbers , one of float and other is intger type. 2 | 3 | /* sample input: 4 | Enter the first number: 2 5 | Enter the second number: 5.2 6 | sample output: 7 | The sum is 7.2 8 | */ 9 | 10 | #include //This file is to be included from library of c which is standard input output function. 11 | void main() 12 | { 13 | int num1 ; 14 | float num2 , result; // declaration of variables 15 | 16 | printf("Enter the first number:"); 17 | scanf("%d",&num1); // input first number 18 | 19 | printf("Enter the second number:"); 20 | scanf("%f",&num2); // input second number 21 | 22 | result = num1 + num2 ; // adding both numbers 23 | 24 | printf("The sum is %f ",result); // output result 25 | 26 | 27 | } 28 | -------------------------------------------------------------------------------- /codes/add_int.c: -------------------------------------------------------------------------------- 1 | // This is program for adding two numbers of integer type. 2 | 3 | /* sample input: 4 | Enter the first number: 2 5 | Enter the second number: 5 6 | sample output: 7 | The sum is 7 8 | */ 9 | 10 | #include //This file is to be included from library of c which is standard input output function. 11 | void main() 12 | { 13 | int num1 , num2 , result; // declaration of variables 14 | 15 | printf("Enter the first number:"); 16 | scanf("%d",&num1); // input first number 17 | 18 | printf("Enter the second number:"); 19 | scanf("%d",&num2); // input second number 20 | 21 | result = num1 + num2 ; // adding both numbers 22 | 23 | printf("The sum is %d ",result); // output result 24 | 25 | 26 | } 27 | -------------------------------------------------------------------------------- /codes/armstrong_3digit.c: -------------------------------------------------------------------------------- 1 | // This is the program for checking the 3 digit number for Armstrong or Not without using loop 2 | /* 3 digit Armstrong number is the sum of cube of the digits of the number. if it is of 2 digit then sum of 3 | square of the digits and so on. 4 | example 153 = 1*1*1 + 5*5*5 + 3*3*3 = 153 it is armstrong number. 5 | */ 6 | /* Sample Input : 7 | Enter the 3 digit number : 150 8 | Sample Output : 9 | The number is Not Armstrong 10 | */ 11 | #include 12 | 13 | void main() 14 | { 15 | int num ,n,cube=0 ,flag; // variable declaration 16 | 17 | printf("Enter the 3 digit number :"); 18 | scanf("%d",&num); // input number 19 | 20 | flag = num; 21 | 22 | n = num % 10; // separate the unit place and store it in variable 'n' 23 | cube = cube + n*n*n ; // add the cube of the digit to variable cube 24 | num = num/10; // divide the number by 10 to convert it into 2 digit. 25 | 26 | // For 3 digit number repeat this process for 3 times 27 | 28 | n = num % 10; 29 | cube = cube + n*n*n ; 30 | num = num/10; 31 | 32 | n = num % 10; 33 | cube = cube + n*n*n ; 34 | num = num/10; 35 | 36 | if (cube == flag) 37 | { 38 | printf("The number is Armstrong "); 39 | } 40 | else 41 | { 42 | printf("The number is Not Armstrong"); 43 | } 44 | 45 | 46 | 47 | 48 | 49 | } 50 | -------------------------------------------------------------------------------- /codes/ascii.c: -------------------------------------------------------------------------------- 1 | // This is the program for printing the ASCII value of the charecter 2 | /* Sample Input : 3 | Enter the charecter : s 4 | Sample Output : 5 | The ASCII value of the charecter s is 115 6 | */ 7 | #include 8 | 9 | void main() 10 | { 11 | char charecter ; // declaration of variable 12 | 13 | printf("Enter the charecter :"); 14 | scanf("%c",&charecter); // input charecter 15 | 16 | printf("The ASCII value of the charecter %c is %d",charecter,charecter); // printing ASCII value 17 | } 18 | -------------------------------------------------------------------------------- /codes/circum_area.c: -------------------------------------------------------------------------------- 1 | // program for calculation of area and the circumference of the circle of given radius. 2 | /* Sample Input : 3 | Enter the Radius of the circle: 7.2 4 | 5 | Sample output : 6 | The circumference of the circle is : 45.216000 And the area is : 162.777588 7 | */ 8 | 9 | #include 10 | #include // This is to be included from the library of C for using power 11 | 12 | void main() 13 | { 14 | float radius , area , circumference ; // declaration of variable 15 | 16 | printf("Enter the Radius of the circle:"); 17 | scanf("%f",&radius); // Input radius 18 | 19 | circumference = 2 * 3.14 * radius ; // Circumference calculation 20 | 21 | area = 3.14 * pow(radius,2) ; // area calculation using power function 22 | 23 | printf("The circumference of the circle is : %f And the area is : %f",circumference,area); // output 24 | } 25 | -------------------------------------------------------------------------------- /codes/compound_interest.c: -------------------------------------------------------------------------------- 1 | // This is the program to calculate the compound interest rate . 2 | 3 | /* Sample Input : 4 | Enter the principle amount : 1000 5 | Enter the interest rate: 12.5 6 | Enter the time period : 2 7 | Enter number of times interest is compounded yearly : 2 8 | Sample Output : 9 | The simple_interest is : 2761816.500000 10 | */ 11 | #include 12 | 13 | void main() 14 | { 15 | float principle , interest , time ,amount, compound_interest ; // Variable declaration 16 | int n ; 17 | 18 | printf("Enter the principle amount :"); 19 | scanf("%f",&principle); // Input Principle 20 | 21 | printf("Enter the interest rate:"); 22 | scanf("%f",&interest); // Input interest 23 | 24 | printf("Enter the time period :"); 25 | scanf("%f",&time); // Input time 26 | 27 | printf("Enter number of times interest is compounded yearly :"); 28 | scanf("%d",&n); // Input value of n 29 | 30 | amount = principle*pow((1+interest/n),n*time); 31 | compound_interest = amount - principle ; // Calculation of compound interest 32 | 33 | printf(" The compound_interest is : %f",compound_interest); // Output 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /codes/even_odd_iff.c: -------------------------------------------------------------------------------- 1 | // This is the program for checking the number whether it is even or odd by if else statement 2 | /* Sample Input : 3 | Enter the number : 5 4 | Sample Output : 5 | The number is ODD 6 | */ 7 | #include 8 | 9 | void main() 10 | { 11 | int num ; // variable declaration 12 | 13 | printf("Enter the number :"); 14 | scanf("%d",&num); // input number 15 | 16 | if (num % 2 == 0) // testing the condition for Even number 17 | { 18 | printf("The number is EVEN"); 19 | } 20 | else 21 | { 22 | printf("The number is ODD"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /codes/even_odd_ter_bit.c: -------------------------------------------------------------------------------- 1 | // This is the program for checking number for even or odd using ternary operator by using modulas operator 2 | /* Sample Input : 3 | Enter the number : 4 4 | Sample Output : 5 | The number is Even number 6 | */ 7 | #include 8 | 9 | void main() 10 | { 11 | int num ; // declaration of variable 12 | 13 | printf("Enter the number :"); 14 | scanf("%d",&num); // input number 15 | 16 | (num & 1) ? (printf("The number is Odd number.")) : (printf("The number is Even number")) ; // Condition for even or odd 17 | } 18 | -------------------------------------------------------------------------------- /codes/even_odd_ter_mod.c: -------------------------------------------------------------------------------- 1 | // This is the program for checking number for even or odd using ternary operator by using modulas operator 2 | /* Sample Input : 3 | Enter the number : 5 4 | Sample Output : 5 | The number is odd number 6 | */ 7 | #include 8 | 9 | void main() 10 | { 11 | int num ; // declaration of variable 12 | 13 | printf("Enter the number :"); 14 | scanf("%d",&num); // input number 15 | 16 | ((num % 2) == 0) ? (printf("The number is even number.")) : (printf("The number is odd number")) ; // Condition for even or odd 17 | } 18 | -------------------------------------------------------------------------------- /codes/farehn_to_celscius.c: -------------------------------------------------------------------------------- 1 | // WAP to convert temparature from farinheit to celcius . 2 | /* Sample INPUT : 3 | Enter the temparature in Farinheit: 45 4 | 5 | Sample OUTPUT: 6 | The Tempareture in celcius is: 7.222222 7 | */ 8 | #include 9 | 10 | void main() 11 | { 12 | float farinheit ,celcius; // Variable declaration 13 | 14 | printf("Enter the temparature in Farinheit: "); 15 | scanf("%f",&farinheit); // Input from user 16 | 17 | celcius = (farinheit-32)*5/9; // Conversion of temparature 18 | 19 | printf("The Tempareture in celcius is: %f ",celcius); // output 20 | } 21 | -------------------------------------------------------------------------------- /codes/final_velocity.c: -------------------------------------------------------------------------------- 1 | // This is the program for calculating the final velocity . 2 | /* Sample Input : 3 | Enter the initial velocity (u) : 5.2 4 | Enter the acceleration (a) : 10 5 | Enter the time (t) : 6 6 | Sample Output: 7 | The final velocity (v) is : 65.199997 8 | */ 9 | #include 10 | 11 | void main() 12 | { 13 | float v , u , a , t; // variable declaration 14 | 15 | printf("Enter the initial velocity (u) :"); 16 | scanf("%f",&u); // input initial velocity 17 | 18 | printf("Enter the acceleration (a) :"); 19 | scanf("%f",&a); // input acceleration 20 | 21 | printf("Enter the time (t) :"); 22 | scanf("%f",&t); // input time 23 | 24 | v = u+a*t; // calculation of final velocity 25 | 26 | printf("The final velocity (v) is : %f",v); // output 27 | } 28 | -------------------------------------------------------------------------------- /codes/greatest_iff.c: -------------------------------------------------------------------------------- 1 | // This is the program for finding greatest among 3 number using if else statement 2 | /* Sample Input : 3 | Enter the first number : 14 4 | Enter the first number : 15 5 | Enter the first number : 10 6 | Sample Output : 7 | The 15 is greatest. 8 | */ 9 | #include 10 | 11 | void main() 12 | { 13 | int x , y , z ; // variable declaration 14 | 15 | printf("Enter the first number :"); 16 | scanf("%d",&x); // input first number 17 | 18 | printf("Enter the second number :"); 19 | scanf("%d",&y); // input second number 20 | 21 | printf("Enter the third number :"); 22 | scanf("%d",&z); // input third number 23 | 24 | if (x > y) // checking greatest among number 1 and number 2 25 | { 26 | if (x > z) // if the first one is greater then check with 3rd one 27 | { 28 | printf("The %d is greatest.",x); // if above is true then number 1 is greatest else 3rd one is greater 29 | } 30 | else 31 | { 32 | printf("The %d is greatest.",z); 33 | } 34 | } 35 | else // if number 2 is greater then compare with 3rd number. 36 | { 37 | if (y > z) // if true number 2 is greater else number 3 is greater 38 | { 39 | printf("The %d is greatest.",y); 40 | } 41 | else 42 | { 43 | printf("The %d is greatest.",z); 44 | } 45 | } 46 | 47 | 48 | } 49 | -------------------------------------------------------------------------------- /codes/greatest_ter.c: -------------------------------------------------------------------------------- 1 | // This is the program for checking the greatest among 3 number 2 | /* Sample Input : 3 | Enter the number 1 : 16 4 | Enter the number 2 : 8 5 | Enter the number 3 : 18 6 | Sample Output : 7 | 18 is greatest 8 | */ 9 | #include 10 | 11 | void main() 12 | { 13 | int num1 , num2 ,num3 ; // variable declaration 14 | 15 | printf("Enter the number 1 :"); 16 | scanf("%d",&num1); // input number 1 17 | 18 | printf("Enter the number 2 :"); 19 | scanf("%d",&num2); // input number 2 20 | 21 | printf("Enter the number 3 :"); 22 | scanf("%d",&num3); // input number 3 23 | 24 | 25 | // Below line is for checking the greatest among 3 number using ternary operator 26 | (num1 > num2) ? ((num1 > num3) ? (printf("%d is greatest",num1)) : (printf("%d is greatest",num3))) : ((num2 > num3) ? (printf("%d is greatest",num2)) : (printf("%d is greatest",num3))) ; 27 | } 28 | -------------------------------------------------------------------------------- /codes/gross_sal.c: -------------------------------------------------------------------------------- 1 | // This is the program for calculating the Gross salary where DA is 20% of Basic salary and HRA is 25% of Basic salary 2 | // Gross salary = DA + HRA 3 | /* Sample Input : 4 | Enter the Basic Salary : 40000 5 | Sample Output : 6 | The Gross salary is : 18000.00000 7 | */ 8 | 9 | #include 10 | 11 | void main() 12 | { 13 | float DA , HRA , gross_sal , basic_sal ; // variable declaration 14 | 15 | printf("Enter the Basic Salary :"); 16 | scanf("%f",&basic_sal); // Input Basic salary 17 | 18 | DA = (basic_sal*20)/100 ; // calculation of DA 19 | HRA = (basic_sal*25)/100 ; // Calculation of HRA 20 | 21 | gross_sal = DA+HRA ; // Calculation of Grass salary 22 | 23 | printf("The Gross salary is : %f",gross_sal); // Output 24 | } 25 | -------------------------------------------------------------------------------- /codes/hello.c: -------------------------------------------------------------------------------- 1 | // This is program to print HELLO WORLD in the output Screen. 2 | #include // This is header file which is to be included from library of C , which is standard input output funtion. 3 | void main() 4 | { 5 | printf("HELLO WORLD"); // this is keyword for printing any value , statement etc. 6 | } 7 | -------------------------------------------------------------------------------- /codes/interchange_3var.c: -------------------------------------------------------------------------------- 1 | // this is program for interchanging the vlue of X , Y , Z 2 | 3 | # include 4 | 5 | void main() 6 | { 7 | int x , y , z ,w; // declaration of variables 8 | 9 | printf("Enter the X :"); 10 | scanf("%d",&x); // input X 11 | 12 | printf("Enter the Y :"); 13 | scanf("%d",&y); // input Y 14 | 15 | printf("Enter the Z :"); 16 | scanf("%d",&z); // input Z 17 | 18 | w = x; 19 | x = y; // swaping of variable 20 | y = z; 21 | z = w; 22 | 23 | printf("The values after swaping are : %d %d %d ",x,y,z); // after swaping 24 | } 25 | -------------------------------------------------------------------------------- /codes/leap_year_iff.c: -------------------------------------------------------------------------------- 1 | // This is the program for checking the year for LEAP or NOT by if else statement 2 | /* Sample Input : 3 | Enter the Year : 2016 4 | Sample Output : 5 | The year is LEAP year 6 | */ 7 | #include 8 | 9 | void main() 10 | { 11 | int year ; // variable declaration 12 | 13 | printf("Enter the Year :"); 14 | scanf("%d",&year); // input year 15 | 16 | if ((year % 400 == 0) || (year % 4 == 0 && year % 100 !=0)) // condition for LEAP year 17 | { 18 | printf("The year is LEAP year"); 19 | } 20 | else 21 | { 22 | printf("The year is NOT LEAP year"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /codes/leap_year_ter.c: -------------------------------------------------------------------------------- 1 | // This is the program for checking whether the given year is LEAP or NOT 2 | /* Sample Input : 3 | Enter the yaer : 1998 4 | Sample Output : 5 | The yaer 1998 is Not leap year 6 | */ 7 | 8 | #include 9 | 10 | void main() 11 | { 12 | int year ; // variable declaration 13 | 14 | printf("Enter the yaer :"); 15 | scanf("%d",&year); // input year 16 | 17 | // below line is for checking the year for LEAP or NOT 18 | ((year % 400 ==0)|| ((year % 4 == 0) && (year % 100 != 100))) ? (printf("The yaer %d is leap year.",year)) : (printf("The yaer %d is Not leap year",year)) ; 19 | } 20 | -------------------------------------------------------------------------------- /codes/lowercase_upper.c: -------------------------------------------------------------------------------- 1 | // This is the program for conversion of lower case charecter to upper case 2 | /* Sample Input : 3 | Enter the Lower case Charecter : a 4 | Sample Output : 5 | The Upper case case charecter is : A 6 | */ 7 | #include 8 | 9 | void main() 10 | { 11 | char charecter ; 12 | int uppercase ; // declaration of variable 13 | 14 | printf("Enter the lower case Charecter :"); 15 | scanf("%c",&charecter); // Input upper case charecter 16 | 17 | uppercase = charecter - 32 ; // conversion of charecter to Upper case 18 | 19 | printf("The Upper case charecter is : %c",uppercase); // Output 20 | } 21 | -------------------------------------------------------------------------------- /codes/palindrom.c: -------------------------------------------------------------------------------- 1 | // This is th program For checking the number whether it is PALINDROM or NOT. 2 | // if the reverse of the number is same as the input number then it is called as PALINDROM number. 3 | /* Sample Input : 4 | Enter the 3 digit number : 121 5 | Sample Output : 6 | The number 121 is PALINDROM 7 | */ 8 | #include 9 | 10 | void main() 11 | { 12 | int num, n, reverse=0, flag ; // variable declaration 13 | 14 | printf("Enter the 3 digit number :"); 15 | scanf("%d",&num); // input the number 16 | 17 | flag = num ; // store the number in other variable for comparing the input number 18 | 19 | n = num % 10; // separate the unit place 20 | reverse = reverse*10 + n ; // add it to the variable 'reverse' at 10's place 21 | num = num/10; // divide the number by 10 for converting it to 2 digit number 22 | 23 | // repeat this process 3 times for 3 digit number 24 | 25 | n = num % 10; 26 | reverse = reverse*10 + n ; 27 | num = num/10; 28 | 29 | n = num % 10; 30 | reverse = reverse*10 + n ; 31 | num = num/10; 32 | 33 | if (flag == reverse) // compare the reverse number to the input number for checking for PALINDROM 34 | { 35 | printf("The number %d is PALINDROM",flag); 36 | } 37 | else 38 | { 39 | printf("The number %d is NOT PALINDROM",flag); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /codes/quadratic_root.c: -------------------------------------------------------------------------------- 1 | // This is the program for finding the roots of the quadratic equation 2 | /* Sample Input : 3 | Enter the cofficient of X^2 : 1 4 | Enter the cofficient of X : -5 5 | Enter the constant term : 6 6 | Sample Output : 7 | The roots of the equation 1X^2 + -5X + 6 is : 3.0000 and 2.0000 8 | */ 9 | #include 10 | #include 11 | 12 | void main() 13 | { 14 | int a , b , c; 15 | float x1 , x2 ; // variable declaration 16 | 17 | printf("Enter the cofficient of X^2 :"); 18 | scanf("%d",&a); // input a 19 | 20 | printf("Enter the cofficient of X :"); 21 | scanf("%d",&b); // input b 22 | 23 | printf("Enter the constant term :"); 24 | scanf("%d",&c); // input c 25 | 26 | x1 = (-b + sqrt(pow(b,2)-4*a*c))/2*a ; // calculating the roots of the equation 27 | x2 = (-b - sqrt(pow(b,2)-4*a*c))/2*a ; 28 | 29 | printf("The roots of the equation %dX^2 + %dX + %d is : %f and %f",a,b,c,x1,x2); // output 30 | } 31 | -------------------------------------------------------------------------------- /codes/reverse.c: -------------------------------------------------------------------------------- 1 | // This is the program for finding the reverse of the number without using loop 2 | /* Sample Input : 3 | Enter the 3 digit number : 123 4 | Sample Output : 5 | The reverse of the number is : 321 6 | */ 7 | #include 8 | 9 | void main() 10 | { 11 | int num ,n,reverse=0; // variable declaration 12 | 13 | printf("Enter the 3 digit number :"); 14 | scanf("%d",&num); // input number 15 | 16 | n = num % 10; // separate the unit place and store it in variable 'n' 17 | reverse = reverse*10 + n ; // add it to variable reverse after multiplying it by 10 so that it add at 10's place 18 | num = num/10; // divide the number by 10 to convert it into 2 digit. 19 | 20 | // For 3 digit number repeat this process for 3 times 21 | 22 | n = num % 10; 23 | reverse = reverse*10 + n ; 24 | num = num/10; 25 | 26 | n = num % 10; 27 | reverse = reverse*10 + n ; 28 | num = num/10; 29 | 30 | printf("The reverse of the number is : %d",reverse); // output 31 | 32 | } 33 | -------------------------------------------------------------------------------- /codes/simple_intrest.c: -------------------------------------------------------------------------------- 1 | // This is the program to calculate the simple interest rate . 2 | 3 | /* Sample Input : 4 | Enter the principle amount : 1000 5 | Enter the interest rate: 12 6 | Enter the time period : 2 7 | 8 | Sample Output : 9 | The simple_interest is : 240.0000 10 | */ 11 | #include 12 | 13 | void main() 14 | { 15 | float principle , interest , time , simple_interest ; // Variable declaration 16 | 17 | printf("Enter the principle amount :"); 18 | scanf("%f",&principle); // Input Principle 19 | 20 | printf("Enter the interest rate:"); 21 | scanf("%f",&interest); // Input interest 22 | 23 | printf("Enter the time period :"); 24 | scanf("%f",&time); // Input time 25 | 26 | simple_interest = (principle * interest * time)/100 ; // Calculation of Simple interest 27 | 28 | printf(" The simple_interest is : %f",simple_interest); // Output 29 | 30 | 31 | } 32 | -------------------------------------------------------------------------------- /codes/st_line.c: -------------------------------------------------------------------------------- 1 | // This is the program for calculation of equation of straight line passing through 2 points (X1,Y1) & (X2,Y2) 2 | /* Sample Input : 3 | Enter the point X1 , Y1 : 2 3 4 | Enter the point X2 , Y2 : 4 5 5 | Sample Output : 6 | The equation of straight line is : Y = 1.000000X + 1.500000 7 | */ 8 | 9 | #include 10 | 11 | void main() 12 | { 13 | int x1 , x2 , y1 , y2 ; // Variable declaration 14 | float m , c ; 15 | 16 | printf("Enter the point X1 , Y1 :"); 17 | scanf("%d%d",&x1,&y1); // Input X1 Y1 18 | 19 | printf("Enter the point X2 , Y2 :"); 20 | scanf("%d%d",&x2,&y2); // Input X2 Y2 21 | 22 | m = (y2-y1)/(x2-x1); // calculation of slope 23 | 24 | c = y1/(m*x1); // calculation of constant 25 | 26 | printf(" The equation of straight line is : Y = %fX + %f",m,c); // Output 27 | 28 | 29 | } 30 | -------------------------------------------------------------------------------- /codes/swaping.c: -------------------------------------------------------------------------------- 1 | // this is program for swaping of two variable without using 3rd varialbe. 2 | 3 | # include 4 | 5 | void main() 6 | { 7 | int var1 , var2 ; // declaration of variables 8 | 9 | printf("Enter the variable 1 :"); 10 | scanf("%d",&var1); // input first variable 11 | 12 | printf("Enter the variable 2 :"); 13 | scanf("%d",&var2); // input second variable 14 | 15 | var1 = var1 ^ var2; 16 | var2 = var1 ^ var2; // swaping of variable using XOR operator 17 | var1 = var1 ^ var2; 18 | 19 | printf("The values after swaping are : %d %d ",var1,var2); // after swaping 20 | } 21 | -------------------------------------------------------------------------------- /codes/swaping_3rd_var.c: -------------------------------------------------------------------------------- 1 | // this is program for swaping of two variable using 3rd varialbe. 2 | 3 | # include 4 | 5 | void main() 6 | { 7 | int var1 , var2 , var3; // declaration of variables 8 | 9 | printf("Enter the variable 1 :"); 10 | scanf("%d",&var1); // input first variable 11 | 12 | printf("Enter the variable 2 :"); 13 | scanf("%d",&var2); // input second variable 14 | 15 | var3 = var1; 16 | var1 = var2; // swaping of variable 17 | var2 = var3; 18 | 19 | printf("The values after swaping are : %d %d ",var1,var2); // after swaping 20 | } 21 | -------------------------------------------------------------------------------- /codes/swping_add.c: -------------------------------------------------------------------------------- 1 | // this is program for swaping of two variable without using 3rd varialbe. 2 | 3 | # include 4 | 5 | void main() 6 | { 7 | int var1 , var2 ; // declaration of variables 8 | 9 | printf("Enter the variable 1 :"); 10 | scanf("%d",&var1); // input first variable 11 | 12 | printf("Enter the variable 2 :"); 13 | scanf("%d",&var2); // input second variable 14 | 15 | var1 = var1 + var2; 16 | var2 = var1 - var2; // swaping of variable using sum. 17 | var1 = var1 - var2; 18 | 19 | printf("The values after swaping are : %d %d ",var1,var2); // after swaping 20 | } 21 | -------------------------------------------------------------------------------- /codes/uppercase_lower.c: -------------------------------------------------------------------------------- 1 | // This is the program for conversion of upper case charecter to lower case 2 | /* Sample Input : 3 | Enter the Upper case Charecter : A 4 | Sample Output : 5 | The Lower case charecter is : a 6 | */ 7 | #include 8 | 9 | void main() 10 | { 11 | char charecter ; 12 | int lowercase ; // declaration of variable 13 | 14 | printf("Enter the Upper case Charecter :"); 15 | scanf("%c",&charecter); // Input upper case charecter 16 | 17 | lowercase = charecter + 32 ; // conversion of charecter to lower case 18 | 19 | printf("The Lower case charecter is : %c",lowercase); // Output 20 | } 21 | -------------------------------------------------------------------------------- /codes/velocity.c: -------------------------------------------------------------------------------- 1 | // This is the program to convert the velocity from the km/he to m/s. 2 | 3 | /* Sample Input : 4 | Enter the velocity in km/hr : 72 5 | 6 | Sample Output : 7 | The velocity in m/s is : 20.0000 8 | */ 9 | 10 | #include 11 | 12 | void main() 13 | { 14 | float km , ms; //Variable declaration 15 | 16 | printf("Enter the velocity in km/hr :"); 17 | scanf("%f",&km); // Input the velocity 18 | 19 | ms = km * 5/18 ; // Velocity conversion 20 | 21 | printf("The velocity in m/s is : %f",ms); // Output 22 | } 23 | -------------------------------------------------------------------------------- /codes/velocity1.c: -------------------------------------------------------------------------------- 1 | // This is the program to convert the velocity from the m/s to km/hr. 2 | 3 | /* Sample Input : 4 | Enter the velocity in m/s : 20 5 | 6 | Sample Output : 7 | The velocity in km/hr is : 72.0000 8 | */ 9 | 10 | #include 11 | 12 | void main() 13 | { 14 | float km , ms; //Variable declaration 15 | 16 | printf("Enter the velocity in m/s :"); 17 | scanf("%f",&ms); // Input the velocity 18 | 19 | km = ms * 18/5 ; // Velocity conversion 20 | 21 | printf("The velocity in km/hr is : %f",km); // Output 22 | } 23 | --------------------------------------------------------------------------------