├── .gitignore ├── TOPICS ├── Chapter 1 │ ├── Data Types + Input & Output.md │ ├── Introduction to C Programming.md │ ├── Practice Program.c.txt │ └── Variables.md ├── Chapter 10 │ ├── File Input & Output.md │ ├── odd.txt │ ├── question1.c │ ├── question2.c │ ├── question3.c │ ├── question4.c │ ├── student.txt │ └── sum.txt ├── Chapter 11 │ ├── Dynamic Memory Allocation.md │ ├── question1.c │ ├── question2.c │ ├── question3.c │ └── question4.c ├── Chapter 2 │ ├── Instructions.md │ ├── Operators.md │ └── Practice Code 2.c.txt ├── Chapter 3 │ ├── Conditional Statements.md │ └── Practice Code 3.c.txt ├── Chapter 4 │ ├── BreakStatement1.c │ ├── BreakStatement2.c │ ├── ContinueStatement1.c │ ├── ContinueStatement2.c │ ├── ForLoop1.c │ ├── ForLoop2.c │ ├── Loop Control Statements.md │ ├── WhileLoop.c │ └── do-whileLoop.c ├── Chapter 5 │ ├── ArgumentSum.c │ ├── Function.md │ ├── Function1.c │ ├── Function2.c │ ├── Function3.c │ ├── Recursion.md │ ├── Recursion1.c │ ├── Recursion2.c │ └── Recursion3.c ├── Chapter 6 │ ├── Pointers.md │ ├── ptr to ptr.c │ ├── question1.c │ └── question2.c ├── Chapter 7 │ ├── Arrays.md │ ├── question1.c │ ├── question2.c │ ├── question3.c │ └── question4.c ├── Chapter 8 │ ├── Strings.md │ ├── question1.c │ ├── question2.c │ ├── question3.c │ └── question4.c ├── Chapter 9 │ ├── Structures.md │ ├── question1.c │ ├── question2.c │ ├── question3.c │ └── question4.c └── Images │ ├── FunctionCall.png │ ├── Recursion.png │ ├── function.png │ ├── functionsquare.png │ ├── ptr Syntax.png │ └── whileloop.png └── readme.md /.gitignore: -------------------------------------------------------------------------------- 1 | *.exe -------------------------------------------------------------------------------- /TOPICS/Chapter 1/Data Types + Input & Output.md: -------------------------------------------------------------------------------- 1 | # 1) Data Types: 2 | - "Data" refers to any information that is processed by the program. 3 | - This can include values, variables, arrays, and structures. 4 | ## Some of the commonly used data types in C include: 5 | 6 | - int: used to store integer values 7 | - float: used to store floating-point values (decimal numbers) 8 | - double: used to store double-precision floating-point values 9 | - char: used to store single character values 10 | - bool: used to store Boolean values (true/false) 11 | 12 | # 2) Input/Output Function: 13 | - Input/output (I/O) functions are used to interact with the user and the computer. 14 | ## The most commonly used I/O functions in C are: 15 | - printf(): used to display output on the screen 16 | - scanf(): used to read input from the user 17 | 18 | # Image: 19 | 20 | ![image](https://user-images.githubusercontent.com/117765637/231194401-ca0e6612-cc3d-4443-b377-0a7a03d2ff30.png) 21 | -------------------------------------------------------------------------------- /TOPICS/Chapter 1/Introduction to C Programming.md: -------------------------------------------------------------------------------- 1 | # Introduction: 2 | - C programming is a widely-used language for writing computer programs. It was first developed in the 1970s and has since become one of the most popular programming languages in the world. 3 | 4 | - At its core, C is a programming language that allows you to create software that interacts with a computer's hardware, operating system, and other software. This makes it ideal for creating applications that need to interact with the underlying system or need to be highly optimized for performance. 5 | 6 | - One of the key features of C is its low-level control over memory and hardware. This means that you can write programs that are very efficient and fast, but also require a greater level of expertise to program compared to higher-level languages. 7 | 8 | - C is a procedural language, meaning that it follows a step-by-step approach to executing code. It's also a compiled language, which means that you write your code in a text editor and then use a compiler to translate it into machine code that the computer can understand. 9 | 10 | - Overall, C is a powerful and versatile language that is still widely used today, especially in fields such as systems programming, embedded systems, and high-performance computing. 11 | -------------------------------------------------------------------------------- /TOPICS/Chapter 1/Practice Program.c.txt: -------------------------------------------------------------------------------- 1 | 1) Area of Square:(Side is given)- 2 | 3 | #include 4 | //area of square 5 | int main() { 6 | int side; 7 | printf("enter side"); 8 | scanf("%d", &side); 9 | printf("area is :%d", side*side); 10 | return 0; 11 | } 12 | 13 | 14 | 2) Area of Circle:(Radius is given)- 15 | 16 | #include 17 | //area of circle 18 | int main() { 19 | int radius; 20 | printf("enter radius"); 21 | scanf("%d", &radius); 22 | printf("area is :%d", 3.14*radius*radius); 23 | return 0; 24 | } 25 | 26 | 27 | 3) Converting Temperature Celsius Into Fahrenheit: 28 | 29 | #include 30 | int main(){ 31 | float cel, fah; 32 | printf("\nEnter Temperature in Celsius : "); 33 | scanf("%f", &cel); 34 | fah = (1.8 * cel) + 32; 35 | printf("\nTemperature in Fahrenheit : %f ", fah); 36 | return (0); 37 | } 38 | 39 | 40 | 4) Find Area of Triangle: 41 | 42 | #include 43 | 44 | int main(){ 45 | float b,h,area; 46 | printf("Enter Height and Base Of Triangle : "); 47 | scanf("%f %f",&h,&b); 48 | area = (h*b)/2; 49 | printf("Area of Triangle is: %f\n",area); 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /TOPICS/Chapter 1/Variables.md: -------------------------------------------------------------------------------- 1 | # Variables: 2 | - Variables is the name of a memory location which stores some data. 3 | - When you create a variable, you give it a name, a data type, and an initial value. 4 | - The name of the variable is used to refer to it in your program. 5 | - The data type of the variable determines what kind of values can be stored in it (e.g. integer, floating-point, character, etc.). 6 | 7 | 8 | # Rules: 9 | - a. Variables are case sensitive. 10 | - b. 1st character is alphabet or '_' 11 | - c. No comma/blank space 12 | - d. No other symbol other than '_' 13 | 14 | 15 | # Image: 16 | - ![image](https://user-images.githubusercontent.com/117765637/231188650-a0a3a0e7-93e1-4150-9b91-af6a90c7d0ed.png) 17 | -------------------------------------------------------------------------------- /TOPICS/Chapter 10/File Input & Output.md: -------------------------------------------------------------------------------- 1 | # File I/0 : 2 | 3 | - Container is storage device to store data. 4 | 5 | - RAM is volatile. 6 | - Contents are lost when program terminates. 7 | - Files are used to persist the data. 8 | 9 | 10 | ## Operations on Files : 11 | 12 | 1) create a file 13 | 2) open a file 14 | 3) close a file 15 | 4) read from a file 16 | 5) write in a file 17 | --- 18 | 19 | ## Types of Files : 20 | 21 | 1) Text files- 22 | - textual data 23 | - e.g==> .txt, .c, .java 24 | 25 | 2) Binary files- 26 | - binary data 27 | - e.g==> .exe, .mp3, .jpg 28 | ---- 29 | 30 | ## File Pointer : 31 | 32 | - FILE is a structure that needs to be created for opening a file. 33 | 34 | - A FILE ptr that points to this structure & is used to access the file. 35 | 36 | - SYNTAX==> FILE *fptr; 37 | 38 | 39 | ## Opening a file: 40 | 41 | FILE *fptr; 42 | 43 | fptr=fopen ("filename", mode); 44 | 45 | ## Closing a file: 46 | 47 | fclose(fptr); 48 | 49 | --- 50 | ## File opening modes : 51 | 52 | 1) "r" ==> open to read 53 | 2) "rb" ==> open to read in binary 54 | 3) "w" ==> open to write 55 | 4) "wb" ==> open to write in binary 56 | 5) "a" ==> open to append 57 | --- 58 | 59 | ## Reading from a file : 60 | 61 | char ch; 62 | 63 | fscanf(fptr, "%c", &ch); 64 | 65 | --- 66 | 67 | ## Writing to a file : 68 | 69 | char ch ='A'; 70 | 71 | fprintf(fptr, "%c", ch); 72 | 73 | --- 74 | 75 | ## End of file : 76 | 77 | - fgetc returns end of file to show that file has ended. 78 | -------------------------------------------------------------------------------- /TOPICS/Chapter 10/odd.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 3 3 | 5 4 | 7 5 | 9 6 | -------------------------------------------------------------------------------- /TOPICS/Chapter 10/question1.c: -------------------------------------------------------------------------------- 1 | // Question ==> Check if file exists before reading from it. 2 | 3 | 4 | # include 5 | 6 | int main(){ 7 | FILE *fptr; 8 | fptr = fopen("NewTest.txt", "r"); 9 | if(fptr == NULL){ 10 | printf("file doesn't exist\n"); 11 | } else{ 12 | fclose(fptr); 13 | } 14 | return 0; 15 | } -------------------------------------------------------------------------------- /TOPICS/Chapter 10/question2.c: -------------------------------------------------------------------------------- 1 | // Question ==> Make program to input student information from user & enter it to a file. 2 | 3 | 4 | #include 5 | 6 | int main(){ 7 | FILE *fptr; 8 | fptr = fopen("student.txt", "w"); 9 | 10 | char name [100]; 11 | int age; 12 | float cgpa; 13 | 14 | printf("enter name:"); 15 | scanf("%s", name); 16 | printf("enter age:"); 17 | scanf("%d", &age); 18 | printf("enter cgpa:"); 19 | scanf("%f", &cgpa); 20 | 21 | fprintf(fptr, "student name: %s\n", name); 22 | fprintf(fptr, "student age: %d\n", age); 23 | fprintf(fptr, "student cgpa: %f", cgpa); 24 | 25 | fclose(fptr); 26 | return 0; 27 | } -------------------------------------------------------------------------------- /TOPICS/Chapter 10/question3.c: -------------------------------------------------------------------------------- 1 | // Question ==> Write program to write all the odd numbers from 1 to n in file. 2 | 3 | #include 4 | 5 | int main(){ 6 | FILE *fptr; 7 | fptr = fopen("odd.txt", "w"); 8 | 9 | int n; 10 | printf("enter n:"); 11 | scanf("%d",&n); 12 | 13 | for (int i=1; i<=n; i++){ 14 | if (i%2 !=0){ 15 | fprintf(fptr, "%d\n", i); 16 | } 17 | } 18 | fclose(fptr); 19 | return 0; 20 | } -------------------------------------------------------------------------------- /TOPICS/Chapter 10/question4.c: -------------------------------------------------------------------------------- 1 | // Question ==> Two numbers a&b, are written in file, write program to replace them with their sum. 2 | 3 | #include 4 | int main(){ 5 | FILE *fptr; 6 | fptr = fopen("sum.txt", "r"); 7 | 8 | int a; 9 | fscanf(fptr, "%d", & a); 10 | int b; 11 | fscanf(fptr, "%d", & b); 12 | 13 | fclose(fptr); 14 | 15 | fptr= fopen("sum.txt", "w"); 16 | fprintf(fptr, "%d", a + b); 17 | fclose(fptr); 18 | return 0; 19 | 20 | } -------------------------------------------------------------------------------- /TOPICS/Chapter 10/student.txt: -------------------------------------------------------------------------------- 1 | student name: shubham 2 | student age: 21 3 | student cgpa: 8.590000 -------------------------------------------------------------------------------- /TOPICS/Chapter 10/sum.txt: -------------------------------------------------------------------------------- 1 | 5 -------------------------------------------------------------------------------- /TOPICS/Chapter 11/Dynamic Memory Allocation.md: -------------------------------------------------------------------------------- 1 | 2 | # Dynamic memory Allocation [DMA]: 3 | 4 | - It is way to allocate memory to a data structure during the runtime. 5 | 6 | - We need some functions to allocate & free memory dynamically. 7 | 8 | 9 | ## Functions for DMA: 10 | 11 | 1) malloc() 12 | 2) calloc() 13 | 3) free() 14 | 4) realloc() 15 | 16 | ## 1. malloc()- 17 | - takes number of bytes to be allocated & returns a pointer of type void. 18 | 19 | - ptr= (int*)malloc(5*size of(int)); 20 | 21 | ## 2. calloc()- 22 | - initializes with 0 23 | - ptr=(*int) calloc(5, size of(int)); 24 | 25 | ## 3. free()- 26 | - We use it to free memory that is allocated using malloc & calloc. 27 | - free(ptr); 28 | 29 | ## 4. realloc()- 30 | - reallocate (increase or decrease) memory using the same pointer & size. 31 | - ptr= realloc(ptr, newSize); -------------------------------------------------------------------------------- /TOPICS/Chapter 11/question1.c: -------------------------------------------------------------------------------- 1 | // Question ==> Write program to allocate memory to store 5 prices. 2 | 3 | #include 4 | #include 5 | 6 | int main(){ 7 | float *ptr; 8 | ptr = (float *) malloc(5 * sizeof(float)); 9 | 10 | ptr[0]=1; 11 | ptr[1]=3; 12 | ptr[2]=5; 13 | ptr[3]=7; 14 | ptr[4]=9; 15 | 16 | for (int i=0; i<5; i++){ 17 | printf("%f\n", ptr[i]); 18 | } 19 | return 0; 20 | } -------------------------------------------------------------------------------- /TOPICS/Chapter 11/question2.c: -------------------------------------------------------------------------------- 1 | // Question ==> Write program to allocate memory of size n, where n is entered by the user. 2 | 3 | #include 4 | #include 5 | 6 | int main(){ 7 | int *ptr; 8 | int n; 9 | printf("enter n:"); 10 | scanf("%d", &n); 11 | 12 | ptr=(int *) calloc (n, sizeof(int)); 13 | for (int i=0; i Allocate memory for 5 numbers then dynamically increase it to 8 numbers. 2 | 3 | #include 4 | #include 5 | 6 | int main(){ 7 | int *ptr; 8 | ptr = (int *) calloc(5, sizeof(int)); 9 | 10 | printf("enter numbers(5):"); 11 | for (int i=0; i<5; i++){ 12 | scanf("%d", &ptr[i]); 13 | } 14 | ptr= realloc(ptr,8); 15 | printf("enter numbers(8):"); 16 | for (int i=0; i<8; i++){ 17 | scanf("%d\n", &ptr[i]); 18 | } 19 | 20 | //print 21 | for(int i=0; i<8; i++){ 22 | printf("number %d is %d", i, ptr[i]); 23 | } 24 | return 0; 25 | } -------------------------------------------------------------------------------- /TOPICS/Chapter 11/question4.c: -------------------------------------------------------------------------------- 1 | // Question ==> Allocate memory to store first 5 odd numbers, then reallocate it to store first 6 even numbers. 2 | 3 | #include 4 | #include 5 | 6 | int main(){ 7 | int *ptr; 8 | ptr =(int *) calloc(5, sizeof(int)); 9 | ptr[0] =1; 10 | ptr[1] =3; 11 | ptr[2] =5; 12 | ptr[3] =7; 13 | ptr[4] =9; 14 | 15 | for (int i=0; i<5; i++){ 16 | printf("%d\n", ptr[i]); 17 | } 18 | 19 | 20 | ptr= realloc (ptr, 6); 21 | ptr[0] =2; 22 | ptr[1] =4; 23 | ptr[2] =6; 24 | ptr[3] =8; 25 | ptr[4] =10; 26 | ptr[5] =12; 27 | 28 | for (int i=0; i<6; i++){ 29 | printf("%d\n", ptr[i]); 30 | } 31 | return 0; 32 | } -------------------------------------------------------------------------------- /TOPICS/Chapter 2/Instructions.md: -------------------------------------------------------------------------------- 1 | # Instructions: 2 | - These are statements in program. 3 | - There are 3 types: 4 | 1) Type Declaration Instruction 5 | 2) Arithmetic Instruction 6 | 3) Control Instruction 7 | 8 | ## 1) Type Declaration Instruction: 9 | - Declare var before using it. 10 | - For example: if you want to declare an integer variable named "myNumber", you would use the Type Declaration Instruction "int myNumber;". This tells the compiler to allocate enough memory to store an integer value in the variable "myNumber". 11 | 12 | - Practice Code: 13 | - ![image](https://user-images.githubusercontent.com/117765637/231962558-9c943bfc-a9cf-4c72-bcf2-0783173d8d71.png) 14 | 15 | 16 | 17 | ## 2) Arithmetic Instruction: 18 | - Arithmetic Instruction is a statement that performs a mathematical operation on one or more variables. 19 | - These operations include addition, subtraction, multiplication, and division. 20 | - For example: 1) subtract the value of variable "y" from variable "x", you would use the Arithmetic Instruction "x - y". 21 | - 2)To multiply variable "x" by variable "y", you would use the Arithmetic Instruction "x * y". 22 | - 3)divide variable "x" by variable "y", you would use the Arithmetic Instruction "x / y". 23 | 24 | - Practice Code: 25 | - 1) 26 | - ![image](https://user-images.githubusercontent.com/117765637/231962990-8e9a8814-a8f3-486c-bd0d-b69da34925ff.png) 27 | - 2) 28 | - ![image](https://user-images.githubusercontent.com/117765637/231964694-ca4f2f58-4577-426f-b329-b3949c41b148.png) 29 | 30 | 31 | 32 | ## 3) Control Instruction: 33 | - Control Instruction is a statement that controls the flow of execution in a program. 34 | - These instructions are used to determine which statements are executed and in what order, based on certain conditions. 35 | - There are three main types of Control Instructions in C programming: Conditional Statements, Loops, and Jump Statements. 36 | - Foe example: 1) If you want to execute a certain set of instructions only if a variable is greater than a certain value, you would use an "if" statement. 37 | - 2) If you want to print the numbers from 1 to 10, you could use a "for" loop. 38 | - 3) If you want to exit a loop, you could use a "break" or "continue" statement. 39 | 40 | - Practice Code: 41 | - ![image](https://user-images.githubusercontent.com/117765637/231963883-06ee4f37-c750-469f-836f-ac2342575bd8.png) 42 | 43 | -------------------------------------------------------------------------------- /TOPICS/Chapter 2/Operators.md: -------------------------------------------------------------------------------- 1 | # Operators: 2 | - There are several types: 3 | 1) Arithmetic Operators 4 | 2) Relational Operators 5 | 3) Logical Operators 6 | 4) Bitwise Operator 7 | 5) Assignment Operator 8 | 6) Ternary Operator (Conditional) 9 | - Here We have learn some types: 10 | ## 1) Relational Operator: 11 | - Relational Operators compare two values and determine the relationship between them. The result of the comparison is always a boolean value, either true or false. 12 | - There are six relational operators in C: 13 | 1) Greater than (>): This operator returns true if the value on the left is greater than the value on the right. 14 | 2) Less than (<): This operator returns true if the value on the left is less than the value on the right. 15 | 3) Greater than or equal to (>=): This operator returns true if the value on the left is greater than or equal to the value on the right. 16 | 4) Less than or equal to (<=): This operator returns true if the value on the left is less than or equal to the value on the right. 17 | 5) Equal to (==): This operator returns true if the value on the left is equal to the value on the right. 18 | 6) Not equal to (!=): This operator returns true if the value on the left is not equal to the value on the right. 19 | - For Example: 20 | - ![image](https://user-images.githubusercontent.com/117765637/232187256-38952882-fe7b-483e-8b55-a7fa289a8a86.png) 21 | 22 | 23 | ## 2) Logical Operator: 24 | - Logical operators are symbols used in the C programming language to combine and manipulate Boolean expressions. 25 | - A Boolean expression is an expression that evaluates to either true or false. 26 | - There are three logical operators in C: 27 | 1) AND (&&): This operator returns true if both the operands (expressions) are true. Otherwise, it returns false. 28 | 2) OR (||): This operator returns true if at least one of the operands (expressions) is true. Otherwise, it returns false. 29 | 3) NOT (!): This operator reverses the truth value of its operand (expression). If the operand is true, it returns false, and if it's false, it returns true. 30 | - For Example: 31 | - ![image](https://user-images.githubusercontent.com/117765637/232187431-313f974d-5ea7-47d6-962c-c9f428dcd49e.png) 32 | 33 | 34 | ## 3) Assignment Operator: 35 | - The assignment operator is a symbol used in the C programming language to assign a value to a variable. 36 | - It is denoted by the equals sign (=). 37 | - There are several types: 38 | 1) Simple assignment operator (=) 39 | 2) Addition assignment operator (+=) 40 | 3) Subtraction assignment operator (-=) 41 | 4) Multiplication assignment operator (*=) 42 | 5) Division assignment operator (/=) 43 | 6) Modulo assignment operator (%=) 44 | 7) Bitwise AND assignment operator (&=) 45 | 8) Bitwise OR assignment operator (|=) 46 | 47 | - For Example: 48 | - ![image](https://user-images.githubusercontent.com/117765637/232188891-3f2d5c02-fd4c-4c78-8b63-245b4973c133.png) 49 | -------------------------------------------------------------------------------- /TOPICS/Chapter 2/Practice Code 2.c.txt: -------------------------------------------------------------------------------- 1 | 1) Write program to check if number is divisible by 2 or not? 2 | 3 | #include 4 | #include 5 | int main() { 6 | int x; 7 | printf("enter a number:"); 8 | scanf("%d", &x); 9 | printf("%d", x%2==0); 10 | return 0; 11 | } 12 | 13 | 14 | 2)Write program to check if number is odd or even? 15 | 16 | #include 17 | #include 18 | int main() { 19 | // even ->1 20 | // odd ->0 21 | int x; 22 | printf("enter a number:"); 23 | scanf("%d", &x); 24 | printf("%d", x%2==0); 25 | return 0; 26 | } 27 | 28 | 3) If a number is greater than 9 and less than 100-> true 29 | [2 digit number] 30 | 31 | #include 32 | #include 33 | int main() { 34 | int x; 35 | printf("enter a number:"); 36 | scanf("%d", &x); 37 | printf("%d \n", x>9 && x<100); 38 | return 0; 39 | } 40 | 41 | 4) Print 1(true) or 0(false) for following statements: 42 | a) If it's sunday and it's snowing -> true 43 | 44 | #include 45 | #include 46 | int main() { 47 | int isSunday=1; 48 | int isSnowing=1; 49 | printf("%d \n", isSunday && isSnowing); 50 | return 0; 51 | } -------------------------------------------------------------------------------- /TOPICS/Chapter 3/Conditional Statements.md: -------------------------------------------------------------------------------- 1 | # Conditional Satements: 2 | - Statements that allow the computer to make decisions based on a certain condition. 3 | - They allow you to write programs that perform different actions depending on whether a particular condition is true or false. 4 | 5 | ## Types: 6 | 7 | - 1) if statement: It allows you to execute a certain block of code if a condition is true. 8 | 9 | - 2) else statement: It allows you to execute a certain block of code if a condition is false. 10 | 11 | - 3) Switch statement: It allows you to choose from a list of options based on the value of a variable. 12 | 13 | ## Examples: 14 | 1) if-else statements: 15 | 16 | ![image](https://user-images.githubusercontent.com/117765637/232549038-365ad346-c47a-4eae-a075-083ef86cc637.png) 17 | 18 | 2) else-if: 19 | 20 | ![image](https://user-images.githubusercontent.com/117765637/232549453-767229d5-f721-42cc-8337-c4c33b3c689c.png) 21 | 22 | ## Ternary Operator: 23 | - The ternary operator is a shorthand way of writing an if-else statement in C programming. 24 | - It takes three operands, hence the name "ternary". The format of the ternary operator is: condition ? expression1 : expression2 25 | - e.g: 26 | 27 | ![image](https://user-images.githubusercontent.com/117765637/232551329-fe05e6ea-3ca3-4d26-9e52-3a46ff4f4232.png) 28 | 29 | ## Switch: 30 | - The switch statement in C programming is a control statement that allows you to select one of several code blocks to execute based on the value of a variable or an expression. 31 | - The syntax of the switch statement is as follows: 32 | - 33 | ![image](https://user-images.githubusercontent.com/117765637/232552454-2647ff8e-eab7-4475-b19d-8a6f144131c4.png) 34 | - example: 35 | - 1) 36 | ![image](https://user-images.githubusercontent.com/117765637/232553070-d8966c52-18d3-4535-ba8b-2eb40e962f65.png) 37 | - 2) 38 | ![image](https://user-images.githubusercontent.com/117765637/232553834-d4c93184-26de-47fb-831d-1ba967d4775c.png) 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /TOPICS/Chapter 3/Practice Code 3.c.txt: -------------------------------------------------------------------------------- 1 | 1) Write program to check if a student passed or failed 2 | marks >30 is PASS 3 | marks <=30 is FAIL 4 | 5 | Ans: 6 | 7 | #include 8 | int main(){ 9 | int marks; 10 | printf("enter number(0-100):"); 11 | scanf("%d", & marks); 12 | 13 | if (marks>=0 && marks<=30){ 14 | printf("fail \n"); 15 | }else if (marks>30 && marks<=100){ 16 | printf("pass \n"); 17 | }else{ 18 | printf("wrong marks"); 19 | } 20 | return 0; 21 | } 22 | 23 | 24 | 2) Write program to give grades to a students marks <30 is C 25 | 30 <= marks <70 is B 26 | 70 <= marks <90 is A 27 | 90 <= marks <=100 is A+ 28 | 29 | Ans: 30 | 31 | #include 32 | int main(){ 33 | int marks; 34 | printf("enter number(0-100):"); 35 | scanf("%d", & marks); 36 | 37 | if(marks <30){ 38 | printf("C \n"); 39 | } else if (marks>=30 && marks<70){ 40 | printf("B \n"); 41 | }else if (marks>=70 && marks<90){ 42 | printf("A \n"); 43 | }else{ 44 | printf("A+ \n"); 45 | } 46 | return 0; 47 | } 48 | 49 | 50 | 3) Write program to find if character entered by user is upper case or not. 51 | 52 | Ans: 53 | 54 | #include 55 | int main(){ 56 | char ch; 57 | printf("enter character:"); 58 | scanf("%c", & ch); 59 | 60 | if(ch >= 'A'&& ch <='Z'){ 61 | printf("upper case \n"); 62 | } else if (ch>='a' && ch<='z'){ 63 | printf("lower case \n"); 64 | } 65 | else{ 66 | printf("not english letter \n"); 67 | } 68 | return 0; 69 | } 70 | -------------------------------------------------------------------------------- /TOPICS/Chapter 4/BreakStatement1.c: -------------------------------------------------------------------------------- 1 | // Question ==> Keep taking numbers as input from user until user enters an odd number.? 2 | 3 | 4 | #include 5 | int main(){ 6 | int n; 7 | do{ 8 | printf("enter number:"); 9 | scanf("%d", &n); 10 | printf("%d \n", n); 11 | 12 | if (n%2 !=0){ 13 | break; 14 | } 15 | } while(1); 16 | printf("Thank You"); 17 | return 0; 18 | } -------------------------------------------------------------------------------- /TOPICS/Chapter 4/BreakStatement2.c: -------------------------------------------------------------------------------- 1 | // Question ==> Keep taking numbers as input from user until user enters numbers which is multiple of 7? 2 | 3 | 4 | #include 5 | int main(){ 6 | int n; 7 | do{ 8 | printf("enter number:"); 9 | scanf("%d", &n); 10 | printf("%d \n", n); 11 | 12 | if (n%7==0){ //multiple of 7 13 | break; 14 | } 15 | } while(1); 16 | printf("Thank You \n"); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /TOPICS/Chapter 4/ContinueStatement1.c: -------------------------------------------------------------------------------- 1 | // Question ==> Print all numbers from 1 to 10 except for 6. 2 | 3 | 4 | #include 5 | int main(){ 6 | for(int i=1; i<=10; i++){ 7 | 8 | if(i==6){ 9 | continue; 10 | } 11 | printf("%d \n", i); 12 | } 13 | return 0; 14 | } -------------------------------------------------------------------------------- /TOPICS/Chapter 4/ContinueStatement2.c: -------------------------------------------------------------------------------- 1 | // Question ==> Print the factorial of a number n. 2 | 3 | 4 | #include 5 | int main(){ 6 | int n; 7 | printf("enter number:"); 8 | scanf("%d", &n); 9 | 10 | int fact=1; 11 | for (int i=1; i<=n; i++){ 12 | fact=fact*i; 13 | } 14 | printf("final factorial is %d", fact); 15 | 16 | return 0; 17 | } -------------------------------------------------------------------------------- /TOPICS/Chapter 4/ForLoop1.c: -------------------------------------------------------------------------------- 1 | /* 2 | Question ==> Print Number from 0 to 10 using for loop 3 | */ 4 | 5 | #include 6 | int main(){ 7 | for(int i=0; i<=10;i++){ 8 | printf("%d \n",i); 9 | 10 | } 11 | return 0; 12 | } -------------------------------------------------------------------------------- /TOPICS/Chapter 4/ForLoop2.c: -------------------------------------------------------------------------------- 1 | // Question==> Print the table of number input by the user? 2 | 3 | #include 4 | int main(){ 5 | int n; 6 | printf("enter number:"); 7 | scanf("%d", &n); 8 | 9 | for (int i=1; i<=10; i++){ 10 | printf("%d \n", n*1); 11 | } 12 | return 0; 13 | } -------------------------------------------------------------------------------- /TOPICS/Chapter 4/Loop Control Statements.md: -------------------------------------------------------------------------------- 1 | # Loop Control Instructions: 2 | 3 | - loop control instructions are used to control the flow of execution within loops. 4 | - These instructions allow you to alter the normal behavior of loops and provide more fine-grained control over the loop's execution. 5 | 6 | ## Types of Loop: 7 | 1) for loop 8 | 2) while loop 9 | 3) do while loop 10 | 11 | ## 1) For Loop: 12 | - The for loop is used when you know exactly how many times you want to repeat a block of code. 13 | - It consists of an initialization statement, a conditional expression, and an increment statement, and it continues to execute the code block until the conditional expression becomes false. 14 | 15 | ## 2) While Loop: 16 | - The while loop is used when you want to repeat a block of code while a certain condition is true. 17 | - It consists of a conditional expression, and the code block continues to execute as long as the expression is true. 18 | 19 | 20 | ![image](../Images/whileloop.png) 21 | 22 | ## 3) Do-while Loop: 23 | - The do-while loop is similar to the while loop, except that the code block is executed at least once, regardless of whether the conditional expression is true or false. 24 | - It consists of the do keyword, followed by the code block, and then the while keyword and the conditional expression. 25 | 26 | ## Syntax of 3 loops: 27 | - ![image](https://user-images.githubusercontent.com/117765637/233289954-867618b1-9674-4b6d-8305-8a7653850270.png) 28 | 29 | 30 | # Special Things: 31 | 32 | ## 1] Increment Operator: 33 | - 2 operators: 1) ++i (Pre Increment) 34 | 2) i++ (Post Increment) 35 | 36 | ## 2] Decrement Operator: 37 | - 2 operators: 1) --i (Pre Decrement) 38 | 2) i-- (Post Decrement) 39 | 40 | ## 3] Loop counter cab be float or even character: 41 | - It is possible to use float or character data types as loop counters. 42 | 43 | ## 4] Infinite Loop: 44 | - infinite loop is a loop that continues to run indefinitely or until interrupted by an external action. 45 | 46 | 47 | # Statements: 48 | 49 | ## 1) Break Statement: 50 | - break statement is a control statement used to terminate a loop. 51 | - The break statement is commonly used with a conditional statement to exit a loop early if a certain condition is met. 52 | - Example: 53 | - ![image](https://user-images.githubusercontent.com/117765637/233294067-0a6d5cf0-7332-446c-af78-d03b8e344d04.png) 54 | 55 | ## 2) Continue Statement: 56 | - continue statement is a control statement used to skip the current iteration of a loop and continue with the next iteration. 57 | - The continue statement is commonly used with a conditional statement to skip iterations that do not meet a certain condition. 58 | - Example: 59 | - ![image](https://user-images.githubusercontent.com/117765637/233294654-bb548ca1-18f2-411c-a685-6870faef9b78.png) 60 | -------------------------------------------------------------------------------- /TOPICS/Chapter 4/WhileLoop.c: -------------------------------------------------------------------------------- 1 | // Question ==> Print Numbers From 0 to n(User Input) using While Loop 2 | 3 | #include 4 | int main(){ 5 | int n; 6 | printf("enter number:"); 7 | scanf("%d" , &n); 8 | 9 | int i=0; 10 | while(i<=n){ 11 | printf("%d \n", i); 12 | i++; 13 | } 14 | return 0; 15 | } -------------------------------------------------------------------------------- /TOPICS/Chapter 4/do-whileLoop.c: -------------------------------------------------------------------------------- 1 | // do-while loop example 2 | 3 | #include 4 | int main(){ 5 | int i=5; 6 | do{ 7 | printf("%d \n", i); 8 | i--; 9 | } 10 | while (i>=1); 11 | return 0; 12 | } -------------------------------------------------------------------------------- /TOPICS/Chapter 5/ArgumentSum.c: -------------------------------------------------------------------------------- 1 | // Question==> Sum of two integers. 2 | 3 | 4 | #include 5 | int sum (int a, int b); 6 | 7 | int main(){ 8 | int a, b; 9 | printf("enter first number :"); 10 | scanf("%d", &a); 11 | printf("enter second number :"); 12 | scanf("%d", &b); 13 | 14 | int s=sum(a,b); 15 | printf("sum is: %d \n", s); 16 | return 0; 17 | } 18 | 19 | int sum(int x, int y){ 20 | return x+y; 21 | } -------------------------------------------------------------------------------- /TOPICS/Chapter 5/Function.md: -------------------------------------------------------------------------------- 1 | # Function: 2 | 3 | - Block of code that performs particular task. 4 | - It can be used multiple times. 5 | - Increase code reusability. 6 | 7 | 8 | ## Syntax 1: 9 | - Function prototype (Declaration)- 10 | - void printHello(); 11 | 12 | ## Syntax 2: 13 | - Function Definition- 14 | - void printHello(){ 15 | printf("Hello"); 16 | } 17 | 18 | ## Syntax 3: 19 | - Function Call- 20 | - int main(){ 21 | printHello(); 22 | return 0; 23 | } 24 | --- 25 | ![image](../Images/function.png) 26 | --- 27 | 28 | # Properties: 29 | - Execution always starts from main. 30 | - A function gets called directly or indirectly from main. 31 | - There can be multiple functions in a program. 32 | --- 33 | # Function Types: 34 | 35 | 1} Library Functions: 36 | - Special functions inbuilt in C 37 | - e.g. ==> scanf(), printf() 38 | 39 | 2} User-Defined: 40 | - Declared and defined by programmer. 41 | 42 | --- 43 | ## Passing Arguments: 44 | 45 | function can take value and give some value. 46 | 47 | - void printHello(); 48 | 49 | - void printTable(int n); 50 | 51 | - int sum (int a, int b); 52 | 53 | ## Example: 54 | 55 | ![Image](../Images/functionsquare.png) -------------------------------------------------------------------------------- /TOPICS/Chapter 5/Function1.c: -------------------------------------------------------------------------------- 1 | // Question ==> Write 2 function - one to print "Hello" & second to print "good bye". 2 | 3 | 4 | #include 5 | void printHello(); 6 | void printGoodbye(); 7 | 8 | int main(){ 9 | printHello(); 10 | printGoodbye(); 11 | return 0; 12 | } 13 | 14 | void printHello(){ 15 | printf("Hello! \n"); 16 | } 17 | void printGoodbye(){ 18 | printf("Goodbye! \n"); 19 | } -------------------------------------------------------------------------------- /TOPICS/Chapter 5/Function2.c: -------------------------------------------------------------------------------- 1 | // Question ==> Use library functions to calculate the square of number given by user. 2 | 3 | 4 | #include 5 | #include 6 | 7 | void calculatePrice (float value); 8 | 9 | int main(){ 10 | int n=4; 11 | printf("%f", pow(n,2)); 12 | return 0; 13 | } -------------------------------------------------------------------------------- /TOPICS/Chapter 5/Function3.c: -------------------------------------------------------------------------------- 1 | // Question ==> To calculate area of square, a circle & a rectangle. 2 | 3 | 4 | #include 5 | #include 6 | 7 | float squareArea(float side); 8 | float circleArea(float rad); 9 | float rectangleArea(float a, float b); 10 | 11 | int main(){ 12 | float a=5.0; 13 | float b=10.0; 14 | 15 | printf("area is:%f", rectangleArea(a,b)); 16 | return 0; 17 | } 18 | 19 | float squareArea (float side){ 20 | return side*side; 21 | } 22 | 23 | float circleArea (float rad){ 24 | return 3.14*rad*rad; 25 | } 26 | 27 | float rectangleArea (float a, float b){ 28 | return a*b; 29 | } -------------------------------------------------------------------------------- /TOPICS/Chapter 5/Recursion.md: -------------------------------------------------------------------------------- 1 | 2 | # Recursion: 3 | 4 | - When function calls itself, it's called recursion. 5 | 6 | ## Properties of Recursion: 7 | 8 | - Anything that can be done with Iteration, can be done with recursion and vice-versa. 9 | 10 | - Recursion can sometimes give the most simple solution. 11 | 12 | - Base case is condition which stops recursion. 13 | 14 | - Iteration has infinite loop and Recursion has stack overflow. 15 | 16 | ## Example: 17 | - ![Image](../Images/Recursion.png) -------------------------------------------------------------------------------- /TOPICS/Chapter 5/Recursion1.c: -------------------------------------------------------------------------------- 1 | // Question ==> Sum of first n natural numbers. 2 | 3 | 4 | #include 5 | 6 | int sum(int n); 7 | 8 | int main(){ 9 | printf("sum is :%d", sum(5)); 10 | return 0; 11 | } 12 | 13 | //Recursive function 14 | int sum(int n){ 15 | if(n==1){ 16 | return 1; 17 | } 18 | int sumNm1=sum(n-1);//sum of 1 to n 19 | int sumN= sumNm1+n; 20 | return sumN; 21 | } -------------------------------------------------------------------------------- /TOPICS/Chapter 5/Recursion2.c: -------------------------------------------------------------------------------- 1 | // Question ==> Calculate factorial of n. 2 | 3 | 4 | #include 5 | int fact(int n); 6 | 7 | int main(){ 8 | printf("factorial is:%d", fact(4)); 9 | return 0; 10 | } 11 | 12 | int fact (int n){ 13 | if(n==0){ 14 | return 1; 15 | } 16 | int factNm1=fact(n-1); 17 | int factN=factNm1*n; 18 | return factN; 19 | } -------------------------------------------------------------------------------- /TOPICS/Chapter 5/Recursion3.c: -------------------------------------------------------------------------------- 1 | // Question ==> Print "Hello World" 5 times. 2 | 3 | 4 | #include 5 | 6 | void printHW(int count); 7 | 8 | int main(){ 9 | printHW(5); 10 | return 0; 11 | } 12 | 13 | //recursive function 14 | void printHW (int count){ 15 | if (count==0){ 16 | return; 17 | } 18 | printf("Hello World \n"); 19 | printHW (count -1); 20 | } -------------------------------------------------------------------------------- /TOPICS/Chapter 6/Pointers.md: -------------------------------------------------------------------------------- 1 | # Pointers [ptr]: 2 | 3 | - A variable that stores the memory address of another variable. 4 | 5 | ## Syntax: 6 | 7 | ![image](https://user-images.githubusercontent.com/117765637/235034776-c2159b5b-90df-48a1-9d7b-4a06e4516b01.png) 8 | 9 | 10 | 11 | 12 | --- 13 | ## Pointer to Pointer: 14 | - A variable that stores the memory address of another pointer. 15 | 16 | ## Syntax: 17 | 1) int **pptr; 18 | 2) char **pptr; 19 | 3) float **pptr; 20 | 21 | --- 22 | 23 | ## Pointers in Function Call: 24 | 25 | ![image](https://user-images.githubusercontent.com/117765637/235034649-03a6d7c9-da2a-4425-a848-79aaf86187da.png) 26 | -------------------------------------------------------------------------------- /TOPICS/Chapter 6/ptr to ptr.c: -------------------------------------------------------------------------------- 1 | // Question==> Print value of 'i' from its pointer to pointer. 2 | 3 | #include 4 | int main(){ 5 | int i=5; 6 | int *ptr= &i; 7 | int **pptr= &ptr; 8 | 9 | printf("%d \n", **pptr); 10 | 11 | return 0; 12 | } -------------------------------------------------------------------------------- /TOPICS/Chapter 6/question1.c: -------------------------------------------------------------------------------- 1 | // Question ==> Swap (exchange) 2 numbers a&b. 2 | 3 | #include 4 | 5 | int main(){ 6 | int x=3, y=5; 7 | _swap (&x, &y); 8 | printf("x=%d & y=%d\n", x,y); 9 | return 0; 10 | } 11 | 12 | //call by reference 13 | void _swap (int *a, int *b){ 14 | int t=*a; 15 | *a=*b; 16 | *b=t; 17 | } 18 | 19 | //call by value 20 | void swap (int a, int b){ 21 | int t=a; 22 | a=b; 23 | b=t; 24 | printf("a=%d & b=%d\n", a,b); 25 | } -------------------------------------------------------------------------------- /TOPICS/Chapter 6/question2.c: -------------------------------------------------------------------------------- 1 | // Question==> Write function to calculate sum, product & average of 2 numbers. Print that average in the main function. 2 | 3 | 4 | #include 5 | 6 | void doWork(int a, int b, int *sum, int *prod, int *avg); 7 | 8 | int main(){ 9 | int a=3, b=5; 10 | int sum, prod, avg; 11 | doWork(a,b, &sum, &prod, &avg); 12 | 13 | printf("sum=%d, prod=%d, avg=%d\n", sum, prod, avg); 14 | return 0; 15 | } 16 | 17 | void doWork(int a, int b, int *sum, int*prod, int *avg){ 18 | *sum=a+b; 19 | *prod=a*b; 20 | *avg=(a+b)/2; 21 | } -------------------------------------------------------------------------------- /TOPICS/Chapter 7/Arrays.md: -------------------------------------------------------------------------------- 1 | # Array: 2 | 3 | - Collection of similar data types stored at continuous memory location. 4 | 5 | --- 6 | ## Syntax: 7 | 1) int marks [3]; 8 | 2) char name [10]; 9 | 3) float price [2]; 10 | 11 | ---- 12 | 13 | 14 | ## Input & Output: 15 | 16 | 1) Input: scanf("%d", &marks[0]); 17 | 18 | 2) Output: printf("%d", marks[0]); 19 | 20 | --- 21 | 22 | ## Pointer Arithmetic: 23 | - Pointer can be incremented & decremented. 24 | - We can also subtract one pointer from another. 25 | - We can also compare 2 pointers. 26 | 27 | 28 | 1) Case 1: int age=22; int *ptr = & age; ptr++; 29 | 30 | 2) Case 2: float price =20.00; float *ptr = & price; ptr++; 31 | 32 | 3) Case 3: char star='*'; char *ptr= & star; ptr++; 33 | 34 | --- 35 | ## Array is a Pointer: 36 | 1) int *ptr= & arr[0]; 37 | 38 | 2) int *ptr = arr; 39 | 40 | 41 | ## Multidimensional Arrays: 42 | 2D Arrays 43 | 44 | int arr[][]={{1,2},{3,4}}; 45 | -------------------------------------------------------------------------------- /TOPICS/Chapter 7/question1.c: -------------------------------------------------------------------------------- 1 | // Question ==> Write program to enter price of 3 items & print their final cost with GST. 2 | 3 | 4 | #include 5 | 6 | int main(){ 7 | float price[3]; 8 | printf("enter 3 prices:"); 9 | scanf("%f", & price [0]); 10 | scanf("%f", & price [1]); 11 | scanf("%f", & price [2]); 12 | 13 | printf("total price 1: %f\n", price[0]+(0.18 *price[0])); 14 | printf("total price 2: %f\n", price[1]+(0.18 *price[1])); 15 | printf("total price 3: %f\n", price[2]+(0.18 *price[2])); 16 | 17 | return 0; 18 | } -------------------------------------------------------------------------------- /TOPICS/Chapter 7/question2.c: -------------------------------------------------------------------------------- 1 | // Question ==> Count the numbers of odd numbers in an array. 2 | 3 | 4 | #include 5 | 6 | int countOdd (int arr[], int n); 7 | int main(){ 8 | int arr[]={1,2,3,4,5,6}; 9 | printf("%d",countOdd(arr, 6)); 10 | return 0; 11 | } 12 | 13 | int countOdd(int arr[], int n){ 14 | int count=0; 15 | for(int i=0; i Store first n fibonacci numbers. 2 | 3 | 4 | #include 5 | 6 | int main(){ 7 | int n; 8 | printf("enter n (n>2):"); 9 | scanf("%d", &n); 10 | 11 | int fib[n]; 12 | fib[0]=0; 13 | fib[1]=1; 14 | 15 | for (int i=2; i Create 2D array, storing tables of 2 & 3. 2 | 3 | 4 | #include 5 | 6 | void storeTable (int arr[] [10], int n, int m, int number); 7 | 8 | int main(){ 9 | int tables [2] [10]; 10 | storeTable(tables, 0,10,2); 11 | storeTable(tables, 1,10,3); 12 | 13 | for (int i=0; i<10; i++){ 14 | printf("%d\t",tables[0] [i] ); 15 | } 16 | printf("\n"); 17 | for (int i=0; i<10; i++){ 18 | printf("%d\t",tables[1] [i] ); 19 | } 20 | return 0; 21 | } 22 | 23 | void storeTable (int arr [][10], int n, int m, int number){ 24 | 25 | for (int i=0; i char name[]={'S','H','U','B','H','A','M','\0'}; 9 | 10 | 11 | ## Initialising Strings: 12 | 1) char name[]={'S','H','U','B','H','A','M','\0'}; 13 | 14 | char name[]="SHUBHAM"; 15 | --- 16 | ## String format specifier: 17 | - "%S" ==> string 18 | 19 | ## Important: 20 | - scanf() cannot input multi-word string with spaces. 21 | - here, gets() & puts() come into picture. 22 | --- 23 | ## String Functions: 24 | 25 | 1) gets(str): input string 26 | 2) puts(str): output string 27 | 3) fgets(str, n, stdin): stops when n-1 chars input or new line is entered. 28 | --- 29 | 30 | ## String using Pointers: 31 | 32 | 1) char *str = "Hello World"; 33 | 34 | 2) char *str = "Hello World"; 35 | 36 | 3) char str[] ="Hello World"; 37 | --- 38 | 39 | ## Standard Library Functions: 40 | 41 | 1) strlen (str): 42 | - count number of characters excluding '\0'. 43 | 44 | 2) strcpy(newStr, oldStr): 45 | - copies value of old string to new string. 46 | 47 | 3) strcat(firstStr, secStr): 48 | - concatenates first string with second string. 49 | 50 | 4) strCmp(firstStr, secStr): 51 | - compares 2 strings & return a value. -------------------------------------------------------------------------------- /TOPICS/Chapter 8/question1.c: -------------------------------------------------------------------------------- 1 | // Question ==> Create string firstName & lastName to store details of user & print all the characters using a loop? 2 | 3 | 4 | #include 5 | 6 | void printstring(char arr[]); 7 | 8 | int main(){ 9 | char firstName[]="Shubham"; 10 | char lastName[]="Bhoite"; 11 | 12 | printstring (firstName); 13 | printstring (lastName); 14 | return 0; 15 | } 16 | 17 | void printstring (char arr[]){ 18 | for (int i=0; arr[i] !='\0'; i++){ 19 | printf("%c", arr[i]); 20 | } 21 | printf("\n"); 22 | } -------------------------------------------------------------------------------- /TOPICS/Chapter 8/question2.c: -------------------------------------------------------------------------------- 1 | // Question ==> Make program that inputs users name & prints its length. 2 | 3 | 4 | #include 5 | 6 | void printstring(char arr[]); 7 | int countlength(char arr[]); 8 | 9 | int main(){ 10 | char name [100]; 11 | fgets(name, 100, stdin); 12 | printf("length is:%d", countlength(name)); 13 | return 0; 14 | } 15 | 16 | int countlength(char arr[]){ 17 | int count=0; 18 | for(int i=0; arr[i] !='\0'; i++){ 19 | count++; 20 | } 21 | return count-1; 22 | } 23 | 24 | void printstring(char arr[]){ 25 | for (int i=0; arr[i] !='\0'; i++){ 26 | printf("%c", arr[i]); 27 | } 28 | printf("\n"); 29 | } -------------------------------------------------------------------------------- /TOPICS/Chapter 8/question3.c: -------------------------------------------------------------------------------- 1 | // Question ==> Write function to count the occurrence of vowels in a string. 2 | 3 | 4 | #include 5 | #include 6 | 7 | int countvowels (char str[]); 8 | 9 | int main(){ 10 | char str[]="HelloWorld"; 11 | printf("vowels are : %d", countvowels(str)); 12 | } 13 | int countvowels(char str[]){ 14 | int count =0; 15 | for (int i=0; str[i] !='\0'; i++){ 16 | if (str[i]=='a'|| str[i]=='e'|| str[i]=='i'|| str[i]=='o' || str[i]=='u'){ 17 | count++; 18 | } 19 | } 20 | return count; 21 | } -------------------------------------------------------------------------------- /TOPICS/Chapter 8/question4.c: -------------------------------------------------------------------------------- 1 | // Question ==> Check if given character is present in string or not. 2 | 3 | 4 | #include 5 | #include 6 | 7 | void checkchar(char str[], char ch); 8 | 9 | int main(){ 10 | char str[]="ParikramaCollege"; 11 | char ch='m'; 12 | checkchar(str,ch); 13 | } 14 | 15 | void checkchar(char str[], char ch){ 16 | for (int i=0; str[i] !='\0'; i++){ 17 | if (str[i]==ch){ 18 | printf("character is present !"); 19 | return ; 20 | } 21 | } 22 | printf("character is NOT present"); 23 | } -------------------------------------------------------------------------------- /TOPICS/Chapter 9/Structures.md: -------------------------------------------------------------------------------- 1 | # Structures: 2 | 3 | - A collection of values of different data types. 4 | 5 | - E.g- name(string), roll no(integer), cgpa(float) 6 | 7 | ## Syntax: 8 | 9 | struct student{ 10 | char name[100]; 11 | int roll; 12 | float cgpa; 13 | }; 14 | 15 | --- 16 | ## Structures in Memory: 17 | 18 | - Structures are stored in contiguous memory location. 19 | ---- 20 | 21 | ## Array of structures: 22 | 23 | 1) struct student ECE[100]; 24 | 2) struct student COE[100]; 25 | 3)struct student IT[100]; 26 | 27 | //ACCESS: 28 | - IT[0].roll=200; 29 | - IT[0].cgpa=7.6; 30 | --- 31 | 32 | ## Pointers to structures: 33 | - struct student s1; 34 | struct student *ptr; 35 | ptr= &s1; 36 | --- 37 | 38 | ## Arrow operator: 39 | (*ptr).code <======> ptr->code 40 | 41 | --- 42 | ## Passing structure to function: 43 | 44 | - void printInfo(struct student S1); 45 | 46 | 47 | ## typedef keyword: 48 | - used to create alias(alternative name) for data type. 49 | 50 | -------------------------------------------------------------------------------- /TOPICS/Chapter 9/question1.c: -------------------------------------------------------------------------------- 1 | // Question ==> Write program to store data of student. 2 | 3 | 4 | #include 5 | #include 6 | 7 | //user defined 8 | struct student { 9 | int roll; 10 | float cgpa; 11 | char name [100]; 12 | }; 13 | 14 | int main (){ 15 | struct student s1; 16 | s1.roll =1664; 17 | s1.cgpa =9.2; 18 | strcpy(s1.name, "shubham"); 19 | 20 | printf("student name = %s \n",s1.name); 21 | printf("student roll no = %d \n",s1.roll); 22 | printf("student cgpa = %f\n",s1.cgpa); 23 | return 0; 24 | } -------------------------------------------------------------------------------- /TOPICS/Chapter 9/question2.c: -------------------------------------------------------------------------------- 1 | // Question ==> Enter address (house no, block, city, state) of 5 people. 2 | 3 | #include 4 | #include 5 | 6 | struct address{ 7 | int house No; 8 | int block; 9 | char city[100]; 10 | char state[100]; 11 | }; 12 | 13 | void printAdd(struct address add); 14 | 15 | int main(){ 16 | struct address adds[5]; 17 | //input 18 | printf("enter info for person 1:"); 19 | scanf("%d", & adds[0].houseNo); 20 | scanf("%d", & adds[0].block); 21 | scanf("%s", adds[0].city); 22 | scanf("%s", adds[0].state); 23 | 24 | printf("enter info for person 2:"); 25 | scanf("%d", & adds[1].houseNo); 26 | scanf("%d", & adds[1].block); 27 | scanf("%s", adds[1].city); 28 | scanf("%s", adds[1].state); 29 | 30 | printf("enter info for person 3:"); 31 | scanf("%d", & adds[2].houseNo); 32 | scanf("%d", & adds[2].block); 33 | scanf("%s", adds[2].city); 34 | scanf("%s", adds[2].state); 35 | 36 | printf("enter info for person 4:"); 37 | scanf("%d", & adds[3].houseNo); 38 | scanf("%d", & adds[3].block); 39 | scanf("%s", adds[3].city); 40 | scanf("%s", adds[3].state); 41 | 42 | printf("enter info for person 5:"); 43 | scanf("%d", & adds[4].houseNo); 44 | scanf("%d", & adds[4].block); 45 | scanf("%s", adds[4].city); 46 | scanf("%s", adds[4].state); 47 | 48 | printAdd (adds[0]); 49 | printAdd (adds[1]); 50 | printAdd (adds[2]); 51 | printAdd (adds[3]); 52 | printAdd (adds[4]); 53 | return 0; 54 | } 55 | 56 | void printAdd(struct address add){ 57 | printf("address is: %d, %d, %s, %s\n", add.houseNo , add.block, add.city, add.state); 58 | } -------------------------------------------------------------------------------- /TOPICS/Chapter 9/question3.c: -------------------------------------------------------------------------------- 1 | // Question ==> Create structure to store complex numbers. 2 | 3 | #include 4 | #include 5 | 6 | struct complex{ 7 | int real; 8 | int img; 9 | }; 10 | 11 | int main(){ 12 | struct complex number= {5,8}; 13 | struct complex *ptr = & number1; 14 | printf("real part=%d\n", ptr->real); 15 | printf("img part= %d\n", ptr->img); 16 | return 0; 17 | } -------------------------------------------------------------------------------- /TOPICS/Chapter 9/question4.c: -------------------------------------------------------------------------------- 1 | // Question ==> Make structure to store bank account information of customer of ABC bank . also, make an alias for it. 2 | 3 | 4 | #include 5 | #include 6 | 7 | typedef struct bankaccount{ 8 | int accountno; 9 | char name[100]; 10 | } acc; 11 | 12 | int main(){ 13 | acc acc1 = {123,"shubham"}; 14 | 15 | printf("acc no= %d", acc1.accountno); 16 | printf("name= %s", acc1.name); 17 | return 0; 18 | } -------------------------------------------------------------------------------- /TOPICS/Images/FunctionCall.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shubham-Bhoite/C-Programming/9fda4df494094dede09f3de91e637d19aa3023f5/TOPICS/Images/FunctionCall.png -------------------------------------------------------------------------------- /TOPICS/Images/Recursion.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shubham-Bhoite/C-Programming/9fda4df494094dede09f3de91e637d19aa3023f5/TOPICS/Images/Recursion.png -------------------------------------------------------------------------------- /TOPICS/Images/function.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shubham-Bhoite/C-Programming/9fda4df494094dede09f3de91e637d19aa3023f5/TOPICS/Images/function.png -------------------------------------------------------------------------------- /TOPICS/Images/functionsquare.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shubham-Bhoite/C-Programming/9fda4df494094dede09f3de91e637d19aa3023f5/TOPICS/Images/functionsquare.png -------------------------------------------------------------------------------- /TOPICS/Images/ptr Syntax.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shubham-Bhoite/C-Programming/9fda4df494094dede09f3de91e637d19aa3023f5/TOPICS/Images/ptr Syntax.png -------------------------------------------------------------------------------- /TOPICS/Images/whileloop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shubham-Bhoite/C-Programming/9fda4df494094dede09f3de91e637d19aa3023f5/TOPICS/Images/whileloop.png -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # C Language Tutorial 2 | ## (Basic to Advanced) 3 | - - - - 4 | ## TOPICS 5 | - - - 6 | ## [Chapter 1](https://github.com/Shubham-Bhoite/C-Programming/tree/main/TOPICS/Chapter%201) 7 | - [Introduction to C](https://github.com/Shubham-Bhoite/C-Programming/blob/main/TOPICS/Chapter%201/Introduction%20to%20C%20Programming.md) 8 | - [Variables](https://github.com/Shubham-Bhoite/C-Programming/blob/main/TOPICS/Chapter%201/Variables.md) 9 | - [Data types + Input/Output](https://github.com/Shubham-Bhoite/C-Programming/blob/main/TOPICS/Chapter%201/Data%20Types%20%2B%20Input%20%26%20Output.md) 10 | - - - - 11 | 12 | ## [Chapter 2](https://github.com/Shubham-Bhoite/C-Programming/tree/main/TOPICS/Chapter%202) 13 | - [Instructions](https://github.com/Shubham-Bhoite/C-Programming/blob/main/TOPICS/Chapter%202/Instructions.md) 14 | - [Operators](https://github.com/Shubham-Bhoite/C-Programming/blob/main/TOPICS/Chapter%202/Operators.md) 15 | - - - - 16 | 17 | ## [Chapter 3](https://github.com/Shubham-Bhoite/C-Programming/tree/main/TOPICS/Chapter%203) 18 | - [Conditional Statements](https://github.com/Shubham-Bhoite/C-Programming/blob/main/TOPICS/Chapter%203/Conditional%20Statements.md) 19 | - - - 20 | ## [Chapter 4](TOPICS/Chapter%204/) 21 | - [Loop Control Statements](TOPICS/Chapter%204/Loop%20Control%20Statements.md) 22 | - - - 23 | 24 | ## [Chapter 5](https://github.com/Shubham-Bhoite/C-Programming/tree/main/TOPICS/Chapter%205) 25 | - [Functions](https://github.com/Shubham-Bhoite/C-Programming/blob/main/TOPICS/Chapter%205/Function.md) 26 | - [Recursion](https://github.com/Shubham-Bhoite/C-Programming/blob/main/TOPICS/Chapter%205/Recursion.md) 27 | - - - 28 | 29 | ## [Chapter 6](https://github.com/Shubham-Bhoite/C-Programming/tree/main/TOPICS/Chapter%206) 30 | - [Pointers](https://github.com/Shubham-Bhoite/C-Programming/blob/main/TOPICS/Chapter%206/Pointers.md) 31 | - - - 32 | 33 | ## [Chapter 7](https://github.com/Shubham-Bhoite/C-Programming/tree/main/TOPICS/Chapter%207) 34 | - [Arrays](https://github.com/Shubham-Bhoite/C-Programming/blob/main/TOPICS/Chapter%207/Arrays.md) 35 | - - - 36 | 37 | ## [Chapter 8](https://github.com/Shubham-Bhoite/C-Programming/tree/main/TOPICS/Chapter%208) 38 | - [Strings](https://github.com/Shubham-Bhoite/C-Programming/blob/main/TOPICS/Chapter%208/Strings.md) 39 | - - - 40 | 41 | ## [Chapter 9](https://github.com/Shubham-Bhoite/C-Programming/tree/main/TOPICS/Chapter%209) 42 | - [Structures](https://github.com/Shubham-Bhoite/C-Programming/blob/main/TOPICS/Chapter%209/Structures.md) 43 | - - - 44 | 45 | ## [Chapter 10](https://github.com/Shubham-Bhoite/C-Programming/tree/main/TOPICS/Chapter%2010) 46 | - [File I/O](https://github.com/Shubham-Bhoite/C-Programming/blob/main/TOPICS/Chapter%2010/File%20Input%20%26%20Output.md) 47 | - - - - 48 | 49 | ## [Chapter 11](https://github.com/Shubham-Bhoite/C-Programming/tree/main/TOPICS/Chapter%2011) 50 | - [Dynamic Memory Allocation](https://github.com/Shubham-Bhoite/C-Programming/blob/main/TOPICS/Chapter%2011/Dynamic%20Memory%20Allocation.md) 51 | --------------------------------------------------------------------------------