├── 2D-Array.c ├── AddressOfVariable.c ├── AreaCircle.c ├── AreaRectangle.c ├── AreaSquare.c ├── ArithmeticOperationPointer.c ├── ArrayAsFunction.c ├── ArrayInitialization.c ├── ArrayInput.c ├── ArraysWithPointer.c ├── AverageFunction.c ├── BasicInput.c ├── Break.c ├── CallByReference.c ├── CallByValue.c ├── Continue.c ├── DoWhileLoop.c ├── ExectutionPrintf.c ├── FactorialLoop.c ├── FactorialRecursion.c ├── FibonacciSeries.c ├── ForLoop.c ├── ForceCalculation.c ├── FunctionSum.c ├── Grading.c ├── GreatestAmongFour.c ├── HelloWorld.c ├── IfElse.c ├── LeapYear.c ├── LowerCase.c ├── MultiplicationTable.c ├── PointerArithmetic.c ├── PointerBasics.c ├── PrimeNumber.c ├── Problem1.c ├── Problem2.c ├── Problem3.c ├── Problem4.c ├── Problem5.c ├── Problem6.c ├── Problem7.c ├── Problem8.c ├── README.md ├── SimpleInterest.c ├── StarPattern.c ├── SumMultiplication.c ├── SumNaturalNumber.c ├── SwitchCase.c ├── TaxPayCalculator.c ├── TemperatureCovertor.c ├── TernaryOperator.c ├── Variable.c ├── WhileLoop.c ├── armStrongNumber.c └── cube_of_a_number /2D-Array.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | 6 | int rows; 7 | int columns; 8 | int marks[rows][columns]; 9 | int i=0; 10 | int j=0; 11 | int k=0; 12 | int l=0; 13 | printf("Enter the number of rows: "); 14 | scanf("%d", &rows); 15 | printf("Enter the number of columns: "); 16 | scanf("%d", &columns); 17 | 18 | 19 | 20 | for(i=0;i < rows;i++) 21 | { 22 | for(j=0; j < columns; j++) 23 | { 24 | printf("\nEnter the marks of the student %d in subject %d:", i + 1, j + 1); 25 | scanf("%d", &marks[i][j]); 26 | } 27 | } 28 | 29 | for(k=0; k 3 | 4 | int main(void) 5 | { 6 | int a = 42; 7 | int *ptr_to_int = &a; 8 | printf("\nThe value of variable a is %d\n", a); //42 9 | printf("The address of variable a is %d\n", ptr_to_int); //address 10 | printf("The value of variable a is %d\n\n", *ptr_to_int); //42 11 | return 0; 12 | } -------------------------------------------------------------------------------- /AreaCircle.c: -------------------------------------------------------------------------------- 1 | #include 2 | define PI 3.14; 3 | int main() 4 | { 5 | //Area of circle 6 | float radius = 0.0, height = 0.0; 7 | printf("\nEnter the radius of circle: "); 8 | scanf("%f", &radius); 9 | printf("The area of the circle is %.3f sq. units\n", PI * radius * radius); 10 | 11 | /*Now calculating the volume of the cylinder attached to some height of the above circle data.*/ 12 | 13 | printf("Enter the height of cylinder connected to the circle: "); 14 | scanf("%f", &height); 15 | printf("The volume of the cylinder is %.3f cubic units\n\n", PI * radius * radius * height); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /AreaRectangle.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | float length = 0.0, breadth = 0.0; 6 | printf("\nEnter the length of rectangle: "); 7 | scanf("%f", &length); 8 | printf("Enter the breadth of rectangle: "); 9 | scanf("%f", &breadth); 10 | printf("The area of the rectangle is %.3f sq. units\n\n", length * breadth); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /AreaSquare.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | double side; 7 | printf("Enter the side of the square: "); 8 | scanf("%lf", &side); 9 | printf("Area of the square is %lf", pow(side, 2)); 10 | return 0; 11 | } -------------------------------------------------------------------------------- /ArithmeticOperationPointer.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | int number_1, number_2; 6 | int *ptr_to_number_1 = &number_1; 7 | int *ptr_to_number_2 = &number_2; 8 | 9 | printf("\nEnter two number: "); 10 | scanf("%d %d", &number_1, &number_2); 11 | 12 | printf("Addition = %d\n", number_1 + *(ptr_to_number_2)); 13 | printf("Subtraction = %d\n", *(ptr_to_number_1)-number_2); 14 | printf("Multiplication = %d\n", *(ptr_to_number_1) * *(ptr_to_number_2)); 15 | printf("Comparision = %d\n\n", (*(ptr_to_number_1) == *(ptr_to_number_2))); 16 | return 0; 17 | } -------------------------------------------------------------------------------- /ArrayAsFunction.c: -------------------------------------------------------------------------------- 1 | #include 2 | /* 3 | void print_array(int *ptr_to_arr, int n) 4 | { 5 | for (int i = 0; i < n; i++) 6 | { 7 | printf("The value of element %d is %d.\n", i + 1, *(ptr_to_arr + i)); 8 | } 9 | } 10 | */ 11 | void print_array(int array[], int n) 12 | { 13 | for (int i = 0; i < n; i++) 14 | { 15 | printf("The value of element %d is %d.\n", i + 1, array[i]); 16 | } 17 | }; 18 | 19 | int main(void) 20 | { 21 | int arr[] = {51, 56, 165, 163, 321, 516, 849}; 22 | print_array(arr, 7); 23 | return 0; 24 | }; -------------------------------------------------------------------------------- /ArrayInitialization.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | printf("\n\n"); 6 | 7 | int marks[] = {50, 60, 70, 80, 90}; 8 | printf("The value of marks[0] is %d\n", marks[0]); 9 | printf("The value of marks[1] is %d\n", marks[1]); 10 | printf("The value of marks[2] is %d\n", marks[2]); 11 | printf("The value of marks[3] is %d\n", marks[3]); 12 | printf("The value of marks[4] is %d\n", marks[4]); 13 | 14 | printf("\n\n"); 15 | 16 | float floating_point_marks[] = {50, 60, 70, 80, 90}; 17 | printf("The value of marks[0] is %.3f\n", floating_point_marks[0]); 18 | printf("The value of marks[1] is %.3f\n", floating_point_marks[1]); 19 | printf("The value of marks[2] is %.3f\n", floating_point_marks[2]); 20 | printf("The value of marks[3] is %.3f\n", floating_point_marks[3]); 21 | printf("The value of marks[4] is %.3f\n", floating_point_marks[4]); 22 | 23 | printf("\n\n"); 24 | return 0; 25 | } -------------------------------------------------------------------------------- /ArrayInput.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | int marks[5]; 6 | 7 | printf("\n\n"); 8 | 9 | for (int i = 0; i < 5; i++) 10 | { 11 | printf("Enter the marks of student %d: ", i + 1); 12 | scanf("%d", &marks[i]); 13 | }; 14 | 15 | printf("\nPrinting the Input Marks by the user:\n"); 16 | 17 | for (int i = 0; i < 5; i++) 18 | { 19 | printf("Entered the marks of student %d is: %d.\n", i, marks[i]); 20 | }; 21 | 22 | printf("\n\n"); 23 | 24 | return 0; 25 | }; -------------------------------------------------------------------------------- /ArraysWithPointer.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | int marks[5]; 6 | int *ptr_to_arr = marks; 7 | 8 | printf("\n\n"); 9 | 10 | for (int i = 0; i < 5; i++) 11 | { 12 | printf("Enter the marks of student %d: ", i + 1); 13 | scanf("%d", ptr_to_arr++); 14 | // ptr_to_arr++; 15 | }; 16 | 17 | printf("\nPrinting the Input Marks by the user:\n"); 18 | 19 | for (int i = 0; i < 5; i++) 20 | { 21 | printf("Entered the marks of student %d is: %d.\n", i, marks[i]); 22 | }; 23 | 24 | printf("\n\n"); 25 | 26 | return 0; 27 | }; -------------------------------------------------------------------------------- /AverageFunction.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | float average(int a, int b, int c) 4 | { 5 | float result; 6 | result = (float)(a + b + c) / 3; 7 | return result; 8 | } 9 | int main() 10 | { 11 | int a, b, c; 12 | printf("\nEnter the value of number 1: "); 13 | scanf("%d", &a); 14 | printf("\nEnter the value of number 2: "); 15 | scanf("%d", &b); 16 | printf("\nEnter the value of number 3: "); 17 | scanf("%d", &c); 18 | printf("\nAverage = %.3f\n\n", average(a, b, c)); 19 | return 0; 20 | } -------------------------------------------------------------------------------- /BasicInput.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | float a = 0.0, b = 0.0; //Declaring & intializing varible a & b with 0. 6 | printf("Enter two numbers to get summation: "); 7 | scanf("%f%f", &a, &b); 8 | printf("The summation of the given numbers is: %.3f\n\n", a + b); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /Break.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int i = 0; 6 | do 7 | { 8 | printf("%d\n", i); 9 | if (i == 4) 10 | { 11 | break; 12 | } 13 | i++; 14 | 15 | } while (i < 10); 16 | 17 | return 0; 18 | } -------------------------------------------------------------------------------- /CallByReference.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void swap(int *x, int *y); 4 | void wrong_swap(int x, int y); 5 | 6 | int main(void) 7 | { 8 | int a = 3, b = 5; 9 | printf("\nThe value of a and b before swapping is %d and %d.\n", a, b); 10 | wrong_swap(a, b); //will not work bcoz of call by value. 11 | printf("The value of a and b after swapping is %d and %d.\n\n", a, b); 12 | 13 | printf("\nThe value of a and b before swapping is %d and %d.\n", a, b); 14 | swap(&a, &b); //will work due to call by reference 15 | printf("The value of a and b after swapping is %d and %d.\n\n", a, b); 16 | return 0; 17 | } 18 | 19 | void wrong_swap(int x, int y) //call by value 20 | { 21 | int temp; 22 | temp = x; 23 | x = y; 24 | y = temp; 25 | } 26 | 27 | void swap(int *x, int *y) //call by reference 28 | { 29 | int temp; 30 | temp = *x; 31 | *x = *y; 32 | *y = temp; 33 | } -------------------------------------------------------------------------------- /CallByValue.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int sum(int a, int b) 4 | { 5 | int sum; 6 | sum = a + b; 7 | /*Changing the value of a and b nothing happens*/ 8 | b = 10000; 9 | a = 99999; 10 | return sum; 11 | } 12 | int main(void) 13 | { 14 | int a = 4, b = 5; 15 | printf("\nThe value of a and b is %d and %d.\n", a, b); 16 | printf("The sum is %d.\n", sum(a, b)); //call by value (Passing a copy of a and b in the sum function) 17 | printf("The value of a and b is %d and %d.\n\n", a, b); // value of a and b remains same after the call by value 18 | return 0; 19 | } -------------------------------------------------------------------------------- /Continue.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int i = 0, skip = 5; 6 | while (i < 10) 7 | { 8 | i++; 9 | if (i != skip) 10 | { 11 | continue; 12 | } 13 | else 14 | { 15 | printf("%d\n", i); 16 | } 17 | } 18 | 19 | return 0; 20 | } -------------------------------------------------------------------------------- /DoWhileLoop.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int i = 0; 6 | do 7 | { 8 | printf("%d\n", i); 9 | i++; 10 | } while (i < 4); 11 | 12 | return 0; 13 | } -------------------------------------------------------------------------------- /ExectutionPrintf.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a = 5; 6 | printf("%d %d %d", a, ++a, a++); //Execution of order in C is from right to left. And it a/c to GCC, Comppiler depended 7 | return 0; 8 | } -------------------------------------------------------------------------------- /FactorialLoop.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int number; 6 | long unsigned int factorial = 1; 7 | printf("Enter the number to get the factorial: "); 8 | scanf("%d", &number); 9 | //Calculation using for loop. 10 | for (int i = 1; i <= number; i++) 11 | { 12 | factorial *= i; //factorial = fatorial * i 13 | } 14 | /* 15 | int i = 1; 16 | while (i <= number) 17 | { 18 | factorial *= i; //factorial = fatorial * i 19 | i++; 20 | } 21 | 22 | */ 23 | printf("The value of factorial %d is %d", number, factorial); 24 | return 0; 25 | } -------------------------------------------------------------------------------- /FactorialRecursion.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | //Factorial of a number = n * (n-1) * (n-2) * (n-3) ... so on. 4 | long int recursive_factorial(int n) 5 | { 6 | printf("Calling recursive_factorial (%d).\n", n); 7 | if (n == 0 || n == 1) //Base Condition to stop the recursive call. 8 | { 9 | return 1; 10 | } 11 | else 12 | { 13 | return (n * recursive_factorial(n - 1)); 14 | } 15 | } 16 | int main() 17 | { 18 | int number; 19 | printf("\nEnter the number to get the factorial: "); 20 | scanf("%d", &number); 21 | printf("\nFactorial of %d is %d\n\n", number, recursive_factorial(number)); 22 | return 0; 23 | } -------------------------------------------------------------------------------- /FibonacciSeries.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | long int recursive_fibonacci(int n) 4 | { 5 | if (n <= 1) 6 | { 7 | return n; 8 | } 9 | else 10 | { 11 | return (recursive_fibonacci(n - 1) + recursive_fibonacci(n - 2)); 12 | } 13 | } 14 | int main() 15 | { 16 | int how_many; 17 | printf("\nEnter the number to get the fibonacci: "); 18 | scanf("%d", &how_many); 19 | printf("0\t"); 20 | for (int i = 1; i <= how_many; i++) 21 | { 22 | printf("%d\t", recursive_fibonacci(i)); 23 | } 24 | printf("\n\n"); 25 | return 0; 26 | } -------------------------------------------------------------------------------- /ForLoop.c: -------------------------------------------------------------------------------- 1 | #include 2 | //First n natural number printing program using for loop. 3 | int main() 4 | { 5 | int index_value; 6 | printf("\nEnter the index value for the natural number. "); 7 | scanf("%d", &index_value); 8 | //Syntax:for (intialize; test; increment / decrement) 9 | for (int i = 1; i <= index_value; i++) 10 | { 11 | printf("%d\n", i); 12 | } 13 | printf("Now printing the numbers in reverse order:\n"); 14 | for (int i = index_value; i > 0; i--) 15 | { 16 | printf("%d\n", i); 17 | } 18 | printf("\n\n"); 19 | return 0; 20 | } -------------------------------------------------------------------------------- /ForceCalculation.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | float force_calulation(float mass) 4 | { 5 | float force; 6 | force = mass * 9.8; //Force = mass * acceleration 7 | return force; 8 | } 9 | int main() 10 | { 11 | float m; 12 | printf("\nEnter the mass of the body in Kg(s): "); 13 | scanf("%f", &m); 14 | printf("The value of force in Newton is %.3f\n\n", force_calulation(m)); 15 | 16 | return 0; 17 | } -------------------------------------------------------------------------------- /FunctionSum.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int sum(int a, int b); //Function prototype 4 | 5 | int main() 6 | { 7 | int a, b, c; 8 | printf("\nEnter the number you want to sum: "); 9 | scanf("%d%d", &a, &b); 10 | c = sum(a, b); //Function Call //Here a and b are arguments(Actual Value) 11 | printf("The sum of the given number is %d\n\n", c); 12 | return 0; 13 | } 14 | 15 | int sum(int a, int b) //Function Defination //Here a and b are parameters(Placeholders) 16 | { 17 | int result; 18 | result = a + b; 19 | return result; 20 | } -------------------------------------------------------------------------------- /Grading.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int physics, chemistry, maths; 6 | printf("\nEnter the physics marks: "); 7 | scanf("%d", &physics); 8 | 9 | printf("Enter the chemistry marks: "); 10 | scanf("%d", &chemistry); 11 | 12 | printf("Enter the maths marks: "); 13 | scanf("%d", &maths); 14 | 15 | float average = physics + chemistry + maths / 3; 16 | 17 | if ((average < 40) || (physics < 33) || (chemistry < 33) || (maths < 33)) 18 | { 19 | printf("Your total percentage is %.3f and you are fail\n\n", average); 20 | } 21 | else 22 | { 23 | printf("Your total percentage is %.3f and you are pass.\n\n", average); 24 | } 25 | 26 | return 0; 27 | } -------------------------------------------------------------------------------- /GreatestAmongFour.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a, b, c, d; 6 | printf("Enter four numbers to check which one is greater among them: "); 7 | scanf("%d%d%d%d", &a, &b, &c, &d); 8 | //Algorithm for checking the greatest number among input values. 9 | if ((a > b) && (a > c) && (a > d)) 10 | { 11 | printf("%d is greatest among them.", a); 12 | } 13 | else if ((b > c) && (b > d)) 14 | { 15 | printf("%d is greatest among them.", b); 16 | } 17 | else if (c > d) 18 | { 19 | printf("%d is greatest among them.", c); 20 | } 21 | else 22 | { 23 | printf("%d is greatest among them.", d); 24 | } 25 | 26 | return 0; 27 | } -------------------------------------------------------------------------------- /HelloWorld.c: -------------------------------------------------------------------------------- 1 | #include /*Pre-Processor Directive*/ 2 | 3 | int main() /*Main function where the execution of program starts.*/ 4 | { 5 | printf("Hello World!, I'm Avinash Kumar."); /*Printing the statement as it is.*/ 6 | return 0; 7 | } 8 | /* 9 | #. All the statement in a C-Program is terminated with a semi-colon(;) 10 | 11 | 12 | #. Manual compiling of Program: 13 | gcc hello_world.c -> a.out -> a.exe 14 | gcc hello_world.c -o hello_world.exe -> hello_world.exe 15 | 16 | #. Manual Execution of Program: 17 | .\hello_world.exe (then Press Enter) 18 | */ -------------------------------------------------------------------------------- /IfElse.c: -------------------------------------------------------------------------------- 1 | /*C program to check whether the given number is even or odd.*/ 2 | #include 3 | 4 | int main() 5 | { 6 | int a; 7 | printf("\nEnter the number to check whether it is even or odd?\n"); 8 | scanf("%d", &a); 9 | if (a % 2 == 0) 10 | { 11 | printf("The given number is even.\n\n"); 12 | } 13 | else 14 | { 15 | printf("The given number is odd.\n\n"); 16 | } 17 | return 0; 18 | } 19 | /* 20 | 21 | #. Assignment operator --> = 22 | #. To check Equality --> == 23 | #. In C Program any non-zero number is treated as true(1). 24 | 25 | */ -------------------------------------------------------------------------------- /LeapYear.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int input_year; 7 | printf("\nEnter the year you want to check whether it is leap year or not: "); 8 | scanf("%d", &input_year); 9 | 10 | if (input_year % 4 == 0) 11 | { 12 | printf("The year is a leap year.\n\n", input_year); 13 | } 14 | else if (input_year % 100 == 0) 15 | { 16 | printf("The year is a leap year.\n\n", input_year); 17 | } 18 | else if (input_year % 400 == 0) 19 | { 20 | printf("The year is a leap year.\n\n", input_year); 21 | } 22 | else 23 | { 24 | printf("The year is not a leap year.\n\n"); 25 | } 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /LowerCase.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | char character; 6 | printf("\nEnter a character: "); 7 | scanf("%c", &character); 8 | 9 | // ASCII Values for lowercase a - z is 97 - 122 10 | if (character <= 122 && character >= 97) 11 | { 12 | printf("It is lowercase."); 13 | } 14 | else 15 | { 16 | printf("It is not lowercase."); 17 | } 18 | 19 | return 0; 20 | } -------------------------------------------------------------------------------- /MultiplicationTable.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int number; 6 | printf("Enter the number to print the multiplication table: "); 7 | scanf("%d", &number); 8 | 9 | //Normal Order 10 | for (int i = 1; i < 11; i++) 11 | { 12 | printf("%d * %d = %d\n", number, i, number * i); 13 | } 14 | 15 | //Reverse Order 16 | printf("\n\n"); 17 | printf("Printing in Reverse Order:\n"); 18 | for (int i = 10; i > 0; i--) 19 | { 20 | printf("%d * %d = %d\n", number, i, number * i); 21 | } 22 | 23 | return 0; 24 | } -------------------------------------------------------------------------------- /PointerArithmetic.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | int i = 34; 6 | int *ptr_to_int = &i; 7 | printf("\nThe value of pointer is %u.\n", ptr_to_int); 8 | ptr_to_int++; // Adding 4 bytes to the address by 1 increment, because integer in 64-bit archeitecture is 4 bytes. 9 | printf("The value of pointer is %u.\n\n", ptr_to_int); 10 | 11 | char j = 'A'; 12 | char *ptr_to_char = &j; 13 | printf("\nThe value of pointer is %u.\n", ptr_to_char); 14 | ptr_to_char++; // Increment of address by 1 byte because char takes 1 byte. 15 | printf("The value of pointer is %u.\n\n", ptr_to_char); 16 | 17 | float k = 3.4; 18 | float *ptr_to_float = &k; 19 | printf("\nThe value of pointer is %u.\n", ptr_to_float); 20 | ptr_to_float++; // float also takes 4 bytes. 21 | printf("The value of pointer is %u.\n\n", ptr_to_float); 22 | 23 | return 0; 24 | } -------------------------------------------------------------------------------- /PointerBasics.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | int i = 8; 6 | int *j = &i; //pointer to integer. 7 | printf("\nThe value of i is %d\n", i); 8 | printf("The value of i is %d\n", *j); 9 | printf("The address of i is %u\n", &i); 10 | printf("The address of i is %u\n", j); 11 | printf("The address of j is %u\n", &j); 12 | printf("The value of j is %d\n\n", *(&j));//j is storing the address of varible i 13 | 14 | /* 15 | pointer to pointer: 16 | int **k; 17 | k = &j; //where j is pointer to integer 18 | */ 19 | return 0; 20 | } -------------------------------------------------------------------------------- /PrimeNumber.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int number, prime = 1; 6 | printf("Enter the number to check whether it is prime or not: "); 7 | scanf("%d", &number); 8 | 9 | for (int i = 2; i < number; i++) 10 | { 11 | if (number % i == 0) 12 | { 13 | prime = 0; 14 | break; 15 | } 16 | } 17 | if (prime == 0) 18 | { 19 | printf("The given number is not prime."); 20 | } 21 | else 22 | { 23 | printf("The given number is prime."); 24 | } 25 | 26 | return 0; 27 | } -------------------------------------------------------------------------------- /Problem1.c: -------------------------------------------------------------------------------- 1 | /* 2 | Write a program having a varible i. Print the address of i. Pass this variable to a function and print its address. Are these adddresses same? why? 3 | */ 4 | #include 5 | void print_address(int a) 6 | { 7 | printf("The address of variable i is %u\n", &a); 8 | } 9 | int main(void) 10 | { 11 | int i = 34; 12 | printf("\nThe value of variable i is %d\n", i); //34 13 | print_address(i); 14 | printf("\nThe address of variable i is %u\n\n", &i); 15 | //The address of i is not same as in main function and the print_address function, this is because a copy of i is passed. i.e, call by value. 16 | return 0; 17 | } -------------------------------------------------------------------------------- /Problem2.c: -------------------------------------------------------------------------------- 1 | /* 2 | Write a program using function which calculate the sum and average of two numbers. Use pointer and print the values of sum and average in main().*/ 3 | 4 | #include 5 | 6 | void sum_and_avg(int a, int b, int *sum, float *avg) 7 | { 8 | *sum = a + b; 9 | *avg = (float)*sum / 2; 10 | } 11 | int main(void) 12 | { 13 | int a = 456, sum = 0, b = 235; 14 | float avg = 0; 15 | sum_and_avg(a, b, &sum, &avg); 16 | printf("\nSum = %d\nAverage = %.3f\n\n", sum, avg); 17 | return 0; 18 | } -------------------------------------------------------------------------------- /Problem3.c: -------------------------------------------------------------------------------- 1 | /* 2 | Write a program to print the value of a variable i by using pointer to pointer type o variable 3 | */ 4 | #include 5 | 6 | int main(void) 7 | { 8 | int i = 234; 9 | 10 | int *ptr_to_int; 11 | int **ptr_to_ptr; 12 | 13 | ptr_to_int = &i; 14 | ptr_to_ptr = &ptr_to_int; 15 | 16 | printf("\nThe value of i is %d.\n\n", **ptr_to_ptr); 17 | 18 | return 0; 19 | } -------------------------------------------------------------------------------- /Problem4.c: -------------------------------------------------------------------------------- 1 | /* 2 | Create an array of 10 numbers. Verify using pointer arithmetic that (ptr+2) points to the 3rd element where ptr is a pointer pointing to the first elemtnt of the array. 3 | */ 4 | #include 5 | 6 | int main(void) 7 | { 8 | int arr[10]; 9 | int *ptr_to_arr = arr; 10 | ptr_to_arr += 2; //ptr + 2 11 | if (ptr_to_arr == &arr[2]) 12 | { 13 | printf("True, Hence Verified."); 14 | } 15 | else 16 | { 17 | printf("False"); 18 | } 19 | 20 | return 0; 21 | } -------------------------------------------------------------------------------- /Problem5.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | int number; 6 | printf("\nEnter the number: "); 7 | scanf("%d", &number); 8 | 9 | int multiplication[10]; 10 | 11 | for (int i = 0; i < 10; i++) 12 | { 13 | multiplication[i] = number * (i + 1); 14 | } 15 | 16 | for (int i = 0; i < 10; i++) 17 | { 18 | printf("%d * %d = %d\n", number, i + 1, multiplication[i]); 19 | } 20 | printf("\n\n"); 21 | return 0; 22 | } -------------------------------------------------------------------------------- /Problem6.c: -------------------------------------------------------------------------------- 1 | /* 2 | Write a program containing a function which reverses the array passed to it. 3 | */ 4 | #include 5 | 6 | void reverse(int *arr, int n) 7 | { 8 | int temp; 9 | for (int i = 0; i < (n / 2); i++) 10 | { 11 | //Swapping Array 12 | temp = arr[i]; 13 | arr[i] = arr[n - i - 1]; 14 | arr[n - i - 1] = temp; 15 | } 16 | } 17 | int main(void) 18 | { 19 | int arr[] = {1, 2, 3, 4, 5, 6, 7}; 20 | reverse(arr, 7); 21 | for (int i = 0; i < 7; i++) 22 | { 23 | printf("%d\t", arr[i]); 24 | }; 25 | return 0; 26 | } -------------------------------------------------------------------------------- /Problem7.c: -------------------------------------------------------------------------------- 1 | /*Write a program contaning which counts the number of positive integers in an array*/ 2 | #include 3 | 4 | int main(void) 5 | { 6 | int count = 0; 7 | int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; 8 | 9 | for (int i = 0; i < 10; i++) 10 | { 11 | if (arr[i] > 0) 12 | { 13 | count++; 14 | } 15 | }; 16 | printf("Total number of positive integers: %d", count); 17 | return 0; 18 | } -------------------------------------------------------------------------------- /Problem8.c: -------------------------------------------------------------------------------- 1 | /*Create a 3D array and print the address of its elements in increasing order.*/ 2 | #include 3 | 4 | int main(void) 5 | { 6 | int arr[2][3][4]; 7 | 8 | for (int i = 0; i < 2; i++) 9 | { 10 | for (int j = 0; j < 3; j++) 11 | { 12 | for (int k = 0; k < 4; k++) 13 | { 14 | printf("Address of arr[%d][%d][%d] is %u.\n", i, j, k, &arr[i][j][k]); 15 | } 16 | } 17 | } 18 | 19 | return 0; 20 | }; -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CprogrammingCodeWithHarry 2 | 3 | C Programming | Code With Harry 4 | this repository is best for beginner coders who wants to learn C language. 5 | All program github repository 6 | -------------------------------------------------------------------------------- /SimpleInterest.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | float principal, rate, years; 6 | printf("\nEnter the principal amount: "); 7 | scanf("%f", &principal); 8 | 9 | printf("Enter the rate of interest: "); 10 | scanf("%f", &rate); 11 | 12 | printf("Enter the time duration in years: "); 13 | scanf("%f", &years); 14 | 15 | float simpleInterest = ((principal * rate * years) / 100); //Calculation 16 | 17 | printf("The simple interest of the given data is %.3f \n\n", simpleInterest); 18 | 19 | return 0; 20 | } -------------------------------------------------------------------------------- /StarPattern.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | * 4 | *** 5 | ***** 6 | 7 | */ 8 | #include 9 | 10 | void print_pattern(int n) 11 | { 12 | if (n == 1) 13 | { 14 | printf("*\n"); 15 | return; 16 | } 17 | else 18 | { 19 | print_pattern(n - 1); 20 | for (int i = 0; i < (2 * n - 1); i++) 21 | { 22 | printf("*"); 23 | } 24 | printf("\n"); 25 | } 26 | } 27 | 28 | int main() 29 | { 30 | int n = 3; 31 | print_pattern(n); 32 | return 0; 33 | } -------------------------------------------------------------------------------- /SumMultiplication.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int number, sum = 0; 6 | 7 | printf("\nEnter the number to print the sum upto n natural number: "); 8 | scanf("%d", &number); 9 | 10 | for (int i = 1; i < 11; i++) 11 | { 12 | printf("%d * %d = %d\n", number, i, number * i); 13 | sum += number * i; 14 | } 15 | 16 | printf("The sum is %d is %d\n\n", number, sum); 17 | 18 | return 0; 19 | } -------------------------------------------------------------------------------- /SumNaturalNumber.c: -------------------------------------------------------------------------------- 1 | #include 2 | //C Program to print the sum of first n natural numbers. 3 | int main() 4 | { 5 | int number, sum = 0; 6 | printf("\nEnter the number to print the sum upto n natural number: "); 7 | scanf("%d", &number); 8 | 9 | for (int i = 1; i <= number; i++) 10 | { 11 | sum += i; //sum = sum + i 12 | } 13 | 14 | printf("The sum upto %d is %d\n\n", number, sum); 15 | 16 | return 0; 17 | } -------------------------------------------------------------------------------- /SwitchCase.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int rating; 6 | printf("\nEnter the rating b/w (1-5):\n"); 7 | scanf("%d", &rating); 8 | switch (rating) 9 | { 10 | case 1: 11 | printf("Your rating is 1.\n\n"); 12 | break; 13 | case 2: 14 | printf("Your rating is 2.\n\n"); 15 | break; 16 | case 3: 17 | printf("Your rating is 3.\n\n"); 18 | break; 19 | case 4: 20 | printf("Your rating is 4.\n\n"); 21 | break; 22 | case 5: 23 | printf("Your rating is 5.\n\n"); 24 | break; 25 | default: 26 | printf("Invalid rating."); 27 | break; 28 | } 29 | return 0; 30 | } -------------------------------------------------------------------------------- /TaxPayCalculator.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | double income, tax = 0; 6 | printf("\nEnter your income: "); 7 | scanf("%lf", &income); 8 | 9 | if (income >= 250000 && income <= 500000) 10 | { 11 | tax = tax + 0.05 * (income - 250000); //5% 12 | } 13 | if (income >= 500000 && income <= 1000000) 14 | { 15 | tax = tax + 0.20 * (income - 500000); //20% 16 | } 17 | if (income >= 1000000) 18 | { 19 | tax = tax + 0.30 * (income - 1000000); //30% 20 | } 21 | printf("Your net tax should be paid %lf", tax); 22 | 23 | return 0; 24 | } -------------------------------------------------------------------------------- /TemperatureCovertor.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | float celsius = 0.0; 6 | printf("\nEnter the value of temperatur in degree celsius: "); 7 | scanf("%f", &celsius); 8 | 9 | float farenheit = (celsius * 9 / 5) + 32; //Calculation 10 | 11 | printf("The value of the temperature in farenheit is %.3f F\n\n", farenheit); 12 | 13 | return 0; 14 | } -------------------------------------------------------------------------------- /TernaryOperator.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a; 6 | printf("\nEnter the number to check whether it is even or odd?\n"); 7 | scanf("%d", &a); 8 | (a % 2 == 0) ? printf("The given number is even.\n\n") : printf("The given number is odd.\n\n"); 9 | return 0; 10 | } -------------------------------------------------------------------------------- /Variable.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a = 4; //Integer value 6 | float b = 8.434; //Real value 7 | char c = 'a'; //Character value 8 | printf("The value of a is %d\n", a); 9 | printf("The value of b is %f\n", b); 10 | printf("The value of c is %c\n\n", c); 11 | return 0; 12 | } -------------------------------------------------------------------------------- /WhileLoop.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int i = 0; 6 | while (i <= 20) 7 | { 8 | if (i >= 10) 9 | { 10 | printf("%d\n", i); 11 | } 12 | i++; //i=i+1-->1st print then increment 13 | } 14 | 15 | return 0; 16 | } -------------------------------------------------------------------------------- /armStrongNumber.c: -------------------------------------------------------------------------------- 1 | #include 2 | /*The number which each number is cube is equal to orignial number then it's called armstrong number.*/ 3 | int main() 4 | { 5 | int n,a,sum,rem; 6 | printf("Enter the number to check where number is armstrong or not:"); 7 | scanf("%d",&n); 8 | a=n; 9 | sum=0; 10 | while(n>0) 11 | { 12 | rem=n%10; 13 | sum=sum+rem*rem*rem; 14 | n=n/10; 15 | } 16 | if(sum==a) 17 | printf("%d is armstrong number",a); 18 | else 19 | printf("%d is not armstrong number",a); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /cube_of_a_number: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int number, cube; 6 | 7 | printf(" \n Please Enter any integer Value : "); 8 | scanf("%d", &number); 9 | 10 | cube = number * number * number; 11 | 12 | printf("\n Cube of a given number %d is = %d", number, cube); 13 | 14 | return 0; 15 | } 16 | --------------------------------------------------------------------------------