ScholarQuill logoScholarQuillUniversity Notes
  • Notes
  • Past Papers
  • Blogs
  • Todo
Login
ScholarQuill logoScholarQuillUniversity Notes
Login
NotesPast PapersBlogsTodo
More
SubjectsDiscussionCGPA CalculatorGPA CalculatorStudent PortalCourse Outline
About
About usPrivacy PolicyReportContact
Notes
Past Papers
Blogs
Todo
Analytics
    Current Subject
    🧩
    Programming Fundamentals
    CC-112
    Progress0 / 39 topics
    Topics
    1. Introduction to Problem Solving, Algorithms, Programming, and C Language2. Problem Solving, a brief review of Von-Neumann Architecture3. The C Programming Language, Pseudo-code, Concept of Variable4. Data types in Pseudo-code, The C Standard Library and Open Source5. Input/Output, Arithmetic expressions, Assignment statement, Operator precedence6. Concept of Integer division, Flowchart and its notations7. Typical C Program Development Environment, Role of Compiler and Linker8. Test Driving C Application9. Introduction to C Programming: A Simple C Program: Printing Text, Adding Two Integer10. Memory Concepts, Arithmetic in C, Operators11. Decision Making: Equality and Relational Operators12. Structured Program Development: The if, if...else, while Nested Control Statements13. Program Control: for, switch, do...while, break, continue, Logical Operators14. Functions: Modularizing Program in C, Math Library Functions15. Function Definitions and Prototypes, Function-Call Stack and Stack Frames16. Stack rolling and unrolling, Headers, Passing Arguments by Value and by Reference17. Random Number Generation, Scope Rules, Recursion, Recursion vs Iteration18. Arrays: Defining Arrays, Character Arrays, Static and Automatic Local Arrays19. Passing Arrays to Function, Sorting and Searching Arrays20. Multidimensional and Variable Length Arrays21. Pointers: Pointer Definitions and Initialization, Pointer Operators22. Passing Arguments to Function by Reference, Using the const and sizeof Operator23. Pointer Expressions and Arithmetic, Pointers and Arrays, Array of Pointers24. Function Pointers25. Characters and Strings: Strings and Characters, Character Handling Library26. String Functions, Library Functions27. Formatted Input/Output: Streams, Formatted Output with printf, Formatted Input with scanf28. Structures: Defining Structures, Accessing Structure Member, Structures and Functions29. typedef, Unions30. Bit Manipulation and Enumeration: Bitwise Operators, Bit Fields, Enumeration Constants31. File Processing: Files and Streams, Creating, Reading and Writing data to a Sequential and a Random-Access File32. Preprocessor: #include, #define, Conditional Compilation, #error and #pragma33. # and ## Operators, Predefined Symbolic Constants, Assertions34. Other Topics: Variable Length Argument List, Using Command Line Arguments35. Compiling Multiple-Source-File Programs, Program Termination with exit and atexit36. Suffixes for Integer and Floating-Point Literals, Signal Handling37. Dynamic Memory Allocation: calloc and realloc, goto38. Advance Topics: Self-Referential Structures, Linked Lists39. Efficiency of Algorithms, Selection and Insertion Sort
    CC-112›Introduction to C Programming: A Simple C Program: Printing Text, Adding Two Integer
    Programming FundamentalsTopic 9 of 39

    Introduction to C Programming: A Simple C Program: Printing Text, Adding Two Integer

    5 minread
    804words
    Beginnerlevel

    Introduction to C Programming

    C programming is one of the most widely used and foundational programming languages. Developed in the 1970s by Dennis Ritchie at Bell Labs, C has influenced many other modern programming languages, including C++, Java, and Python. It's a general-purpose language that provides a good balance between high-level functionality and low-level memory manipulation.

    C is commonly used for system-level programming (e.g., operating systems, embedded systems) due to its close proximity to hardware and its efficient performance.


    A Simple C Program

    A simple C program typically starts with the inclusion of necessary header files, followed by the definition of a main() function. The main() function is the entry point of any C program, and it’s where the program starts its execution.

    Below are two very simple tasks often used in C programming for beginners:

    1. Printing Text to the screen.
    2. Adding Two Integers and printing the result.

    1. Printing Text in C

    Printing text or outputting information to the console is one of the most fundamental actions in any programming language. In C, you can use the printf() function to display text or values.

    Here’s an example of a C program that prints a message:

    #include <stdio.h>  // Preprocessor directive to include standard I/O library
    
    int main() {
        // Print a message to the screen
        printf("Hello, World!\n");
        return 0;  // Return 0 to indicate successful execution
    }
    

    Explanation:

    • #include <stdio.h>: This line includes the standard input/output library which contains the printf() function, used for printing text to the screen.
    • main() function: Every C program starts execution from the main() function.
    • printf() function: This function is used to print the output. The text "Hello, World!" is displayed on the screen. The \n at the end of the string is a newline character, which moves the cursor to the next line after printing.
    • return 0;: This line returns 0 from the main() function, indicating the program finished successfully.

    Output:

    Hello, World!
    

    2. Adding Two Integers

    Now let’s write a simple program to add two integers and print the result. In this program, we will:

    • Declare two integer variables.
    • Accept input for those variables from the user.
    • Perform addition and print the result.
    #include <stdio.h>  // Include the standard input/output library
    
    int main() {
        int num1, num2, sum;  // Declare three integer variables: num1, num2, and sum
        
        // Prompt the user for input
        printf("Enter first integer: ");
        scanf("%d", &num1);  // Read the first integer from the user
    
        printf("Enter second integer: ");
        scanf("%d", &num2);  // Read the second integer from the user
        
        sum = num1 + num2;  // Add the two integers and store the result in 'sum'
        
        // Output the result
        printf("The sum of %d and %d is %d\n", num1, num2, sum);
        
        return 0;  // Indicate that the program has ended successfully
    }
    

    Explanation:

    • int num1, num2, sum;: Declares three integer variables. num1 and num2 will store the two input integers, and sum will store their sum.
    • scanf("%d", &num1);: This function reads the user's input and stores it in the variable num1. %d is the format specifier for integers.
    • sum = num1 + num2;: This performs the addition of the two integers and stores the result in the sum variable.
    • printf("The sum of %d and %d is %d\n", num1, num2, sum);: This prints the result of the addition using the printf() function. The format specifiers %d are replaced with the values of num1, num2, and sum.

    Example Output:

    Enter first integer: 5
    Enter second integer: 10
    The sum of 5 and 10 is 15
    

    How It Works Step-by-Step:

    1. The program starts and displays a prompt for the user to enter two integers.
    2. The program uses the scanf() function to accept input from the user and stores the values in num1 and num2.
    3. The program calculates the sum of the two integers and stores it in the sum variable.
    4. Finally, it prints the sum using the printf() function, displaying the result to the user.

    Summary of Key Concepts in the Program:

    1. Preprocessor Directives: #include <stdio.h> includes the standard input/output library necessary for using printf() and scanf().
    2. Variables: We declared integer variables (num1, num2, and sum) to hold the values.
    3. Input/Output: scanf() reads input from the user, and printf() displays output to the user.
    4. Arithmetic: We performed a simple arithmetic operation (+) to add the two integers.
    5. Return Statement: return 0; signals the successful completion of the program.

    This is the foundation of C programming — working with input, output, and arithmetic operations to create simple programs.

    Previous topic 8
    Test Driving C Application
    Next topic 10
    Memory Concepts, Arithmetic in C, Operators

    Past Papers

    Open this section to load past papers

    Click on Show Past Papers to see past papers.
    On This Page
      Reading Stats
      Est. reading time5 min
      Word count804
      Code examples0
      DifficultyBeginner