C Program to Find Maximum of Two Numbers

C program to find maximum of two numbers using ternary operator
  • Write a C program to read two numbers and find maximum numbers using if else statement.
  • Wap in C to find largest number using ternary operator.

Required Knowledge

We will first take two numbers as input from user using scanf function. Then we print the maximum number on screen.

C program to find maximum of two numbers using If Else statement

C program to find maximum of two numbers using If Else statement

/** 
 * C program to print maximum or largest of two numbers 
 */ 
   
#include <stdio.h>  
   
int main() {  
    int a, b;  
    /* 
     * Take two integer as input from user 
     */ 
    printf("Enter Two Integers\n");  
    scanf("%d %d", &a, &b);  
    
    if(a > b) {
 /* a is greater than b */
        printf("%d is Largest\n", a);          
    } else if (b > a){ 
 /* b is greater than a*/
        printf("%d is Largest\n", b);  
    } else {
 printf("Both Equal\n");
    }
   
    return 0;  
}

Output

Enter Two Integers
3 6
6 is Largest
Enter Two Integers
7 2
7 is Largest
Enter Two Integers
5 5
Both Equal

C program to find maximum of two numbers using ternary operator

C program to find maximum of two numbers using ternary operator

/** 
 * C program to print maximum or largest of two numbers 
 * using ternary Operator
 */ 
   
#include <stdio.h>  
   
int main() {  
    int a, b, max;  
    /* 
     * Take two integer as input from user 
     */ 
    printf("Enter Two Integers\n");  
    scanf("%d %d", &a, &b);  
    
    if(a == b){
        printf("Both Equal\n");
    }
     
    max = (a > b) ? a : b ;
    printf("%d is Largest\n", max);
    
    return 0;  
}

Output

Enter Two Integers
5 6
6 is Largest
Enter Two Integers
5 5
Both Equal

C Program for Input/Output of Integer, Character and Floating point numbers

  • Write a program in c to take an Integer, Character and Float as input using scanf and print them using printf function.

To understand this program, you should have knowledge of Input and Output in C

Input/Output in C can be achieved using scanf() and printf() functions. The printf and scanf are two of the many functions found in the C standard library. These functions are declared and related macros are defined in stdio.h header file. The printf function is used to write information from a program to the standard output device whereas scanf function is used to read information into a program from the standard input device.

Function Prototype of printf and scanf in C

Function name Function prototype
printf int printf(const char* format, …);
scanf int scanf(const char* format, …);

Format Specifier of printf and scanf Functions

Format specifier Description
%d Signed decimal integer
%u Unsigned decimal integer
%f Floating point numbers
%c Character
%s Character String terminated by ‘\0’
%p Pointer address

C Program to read and print an Integer, Character and Float using scanf and printf function

This program takes an integer, character and floating point number as input from user using scanf function and stores them in ‘inputInteger’, ‘inputCharacter’ and ‘inputFloat’ variables respectively. Then it uses printf function with %d, %c and %f format specifier to print integer, character and floating point number on screen respectively.

C Program to read and print an Integer, Character and Float using scanf and printf function 1

/*
* C program to take Integer, Character, Float as inputs using scanf 
* and then prints it using printf
*/
#include <stdio.h>
#include <conio.h>
 
int main(){
    int inputInteger;
    char inputCharacter;
    float inputFloat;
     
    /* Take input from user using scanf function */
    printf("Enter an Integer, Character and Floating point number\n");
    scanf("%d %c %f", &inputInteger, &inputCharacter,
        &inputFloat);
     
    /* Print Integer, Character and Float using printf function */
    printf("\nInteger you entered is : %d", inputInteger);
    printf("\nCharacter you entered is : %c", inputCharacter);
    printf("\nFloating point number you entered is : %f",
        inputFloat);
     
    getch();
    return 0;
}

Program Output

Enter an Integer, Character and Floating point number
5 A 2.542

Integer you entered is : 5
Character you entered is : A
Floating point number you entered is : 2.542000

Points to Remember

  • We use “\n” in printf() to generate a newline.
  • C language is case sensitive. So, printf() and scanf() are different from Printf() and Scanf().
  • You can use as many format specifier as you wish in your format string. You must provide a value for each one separated by commas.
  • Program stops running at each scanf call until user enters a value.
  • Ampersand is used before variable name “var” in scanf() function as &var. It is just like in a pointer which is used to point to the variable.

C Program to Print Days of Week in Words using If Else Ladder Statement

C program to print day of week name
  • Write a C program to print days of week using if else ladder statement.

Required Knowledge

In this program, we will take a number between 1 to 7 as input from user, where 1 corresponds to Monday, 2 corresponds to Tuesday and so on. We will use if else ladder statement to print name of day in words.

C program to print days of week in words

C program to print day of week name

/*
 * C program to print day of week name 
 */ 
   
#include <stdio.h> 
   
int main() {  
    int day;   
    /* 
     * Take the Day number as input form user  
     */ 
    printf("Enter Day Number (1 = Monday ..... 7 = Sunday)\n");  
    scanf("%d", &day);  
 
    /* Input Validation */
    if(day < 1 || day > 7){
     printf("Invalid Input !!!!\n");
     return 0;
    }
  
    if(day == 1) {  
        printf("Monday\n");  
    } else if(day == 2) {  
        printf("Tuesday\n");  
    } else if (day == 3) {  
        printf("Wednesday\n");  
    } else if(day == 4) {  
        printf("Thursday\n");  
    } else if(day == 5) {  
        printf("Friday\n");  
    } else if(day == 6) {  
        printf("Saturday\n");  
    } else {  
        printf("Sunday\n");  
    }
   
    return 0;  
}

Output

Enter Day Number (1 = Monday ..... 7 = Sunday)
4
Thursday
Enter Day Number (1 = Monday ..... 7 = Sunday)
7
Sunday
Enter Day Number (1 = Monday ..... 7 = Sunday)
12
Invalid Input !!!!

C Program to Find Maximum of Two Numbers using Conditional Operator

  • Write a C program to find maximum of the two numbers using conditional or ternary operator.
  • How to find largest of the two numbers using conditional statement.

Required Knowledge

In this program, we will use conditional operator to find maximum of two numbers.

C program to find maximum of two numbers using conditional operator

C program to find maximum of two numbers using conditional operator

#include <stdio.h>  
   
int main() {  
    int a, b, maximum;  
   
    /* Take two numbers as input from user
  using scanf function */
    printf("Enter Two Integers\n");  
    scanf("%d %d", &a, &b);  
   
    if(a == b){
        printf("Both Equal\n");
        return 0;
    }
    /* Finds maximum using Ternary Operator */ 
    maximum = (a > b) ? a : b;  
   
    printf("%d is Maximum\n", maximum);  
   
    return 0;  
}

 

Advanced Java Notes | Download Advanced Java Notes and Study Material PDF

Advanced Java Notes 

Advanced Java Notes: Students searching for advanced Java notes can find sufficient study material and notes here on the subject.

Here the Advanced Java notes can act as primary guides for participants studying the subject as it covers most of the important topics on the subject which can help students to get a brief overview of the subject. These notes can help any aspiring students to enhance their preparation so that they can get better grades.

Students will find in this article different Lecture Notes on the subject which are free, recommended reference books and a list of important questions that will help students be more prepared for their exams.

These notes are prepared to mainly help students to get a thorough preparation for their exam and so that they can achieve better scores in Advanced Java.

Introduction to Advanced Java Notes

Advanced Java covers everything that core java does like the APIs that are defined in JAVA Enterprise, including web services, the persistence API, Selvet programming etc.

Here in this programming language, it allows users to be platform-independent, which allows them to develop applications on any operating system. In Advanced Java, you will be able to work on web and Application servers which will allow you to understand the communication over HTTP protocol unlike in core Java.

Advanced Java has another advantage over core Java, and that is it provides a library that helps you better understand client servers architecture.

B.Tech Advanced Java Notes and Study Material PDF Free Download

Students studying their Bachelor in technology will find the following article helpful in their preparation for the subject. The subject gives students a detailed look into how Advanced Java can help bring in better Web applications and how easier they are to run on various operating systems.

So instead of using different tutorials online students studying B.Tech can use the notes provided in these articles to understand better different concepts and they can enhance their preparation with these topics. These notes can act as a reference when preparing for the subject and also can help during revision.

The following are a list of important notes for Advanced Java that are available online for free and can be downloaded any time during the preparation of the subject

  • ADVANCED JAVA PROGRAMMING NOTES
  • ADVANCED java lecture notes
  • Advanced java programming notes PDF
  • Advanced Java Programming lecture notes PDf free
  • Advanced java and core Java notes

Advanced Java Reference Books

Books allow its readers to materialize the concepts better it goes over so that readers firstly get a more in-depth view of the subject and help them go over the specifics. Here students can avail the best-recommended books on Advanced Java and use them to their advantage by preparing better for any exam.

Here the books that students can use to refer to for Advanced Java are recommended by subject experts. Students can use the books and other study material to prepare for Advanced Java.

The following are the list of highly recommended books for students pursuing to study Advanced Java-

  • Core Java Volume II: Advanced Features
  • Java Performance: The Definitive Guide, O Reilly
  • Key Java: Advanced Tips and Techniques
  • Java Concurrency in Practice
  • The Well-Grounded Java Developer
  • Thinking in Java by Bruce Eckel
  • Java 8 in Action: Lambdas, Streams, and functional-style programming by Raoul-Gabriel Urma
  • Optimizing Java
  • Effective Java by Joshua Bloch
  • Java Concurrency in Practice by Brian Goetz
  • Java By Comparison: Become a Java Craftsman in 70 Examples
  • Head First Design Pattern
  • Refactoring by Martin Fowler
  • Test-Driven
  • Functional Programming in Java

Advanced Java curriculum

Students need to have a structure when preparing for their exams, keeping in mind every student’s requirements, we have provided a detailed view of the Computer Network curriculum.

UNIT TOPIC
Unit 1
  • CORE JAVA
  • Introduction to Java
  •  Data types
  •  Variables
  •  Operators
  •  Arrays
  •  Control Statements
  •  Classes & Method
  •  Inheritance
  •  Exception Handling
  •  Multithreading
  • Collections
  •   I/O streams
Unit 2
  • Connecting to a Server
  •  Implementing Servers
  •  Sending E-Mail
  •  Making URL Connections
  •  Advanced Socket Programming DATABASE NETWORKING: The Design of JDBC. The Structured Query Language
  • JDBC Installation
  •  Basic JDBC Programming Concepts,
  • Query Execution
  •  Scrollable and Updatable Result Sets
  • Metadata
  • Row Sets
  •  Transactions.
Unit 3
  • Lists
  •  Tree
  •  Tables
  •  Styled Text Components
  •  Progress Indicators
  •  Component Organizers The Rendering Pipeline
  • Shapes, Areas
  • Strokes, Paint, Coordinate Transformations
  • Clipping
  • Transparency and Composition
  •  Rendering Hints
  •  Readers and Writers for Images
  •  Image Manipulation Printing.
  • The Clipboard, Drag and Drop.
Unit 4
  • Beans
  •  The Bean-Writing Process
  •  Using Beans to Build an Application
  • Naming Patterns for Bean
  •  Components and Events Bean Property
  •  Tubes Bean info Classes
  •  Property
  •  Editors, Customizes.
Unit 5

List of Important Questions for Advanced Java

  1. List different services provided by JNDI. Explain how basic lookup is performed in JNDI.
  2. Explain about lookup operations in LDAP with examples.
  3. Explain different layers in RMI architecture
  4. Discuss parameter passing in RMI, with examples
  5. What is introspection in java beans? Explain how BeanInfo interface helps in introspection of beans
  6. List and briefly explain any four classes in Java Beans API.
  7. What is an EJB container? Explain how EJB invocation happens.
  8. What is a stateless EJB? Explain with an example
  9. Present and explain the life cycle of a servlet
  10. Discuss different security issues with web servers
  11. Write the procedure for the deployment of JSP in the Tomcat server.
  12. Discuss JSP error handling and debugging.
  13. Explain how to deploy java beans in a JSP page, with an example.
  14. What is the structs framework? How is it different from other frameworks?
  15. What are horizontal web services? Explain with examples. Also, list other types of web services.

Present the features of SOAP and also write how to develop web services with SOAP.

FAQS on Advanced Java Notes

Question 1
What is Advanced Java?

Answer
Advanced Java covers everything that core java does like the APIs that are defined in JAVA Enterprise, including web services, the persistence API, Selvet programming etc.

Here in this programming language, it allows users to be platform-independent, which allows them to develop applications on any operating system. In Advanced Java, you will be able to work on web and Application servers which will allow you to understand the communication over HTTP protocol unlike in core Java.

Question 2
What are good books to study Advance Java from?

Answer

  • Core Java Volume II: Advanced Features
  • Java Performance: The Definitive Guide, O Reilly
  • Key Java: Advanced Tips and Techniques
  • Java Concurrency in Practice
  • The Well-Grounded Java Developer
  • Thinking in Java by Bruce Eckel
  • Java 8 in Action: Lambdas, Streams, and functional-style programming by Raoul-Gabriel Urma

Question 3
What are the most frequently asked questions in Advanced Java?

Answer

  1. List different services provided by JNDI. Explain how basic lookup is performed in JNDI.
  2. Explain about lookup operations in LDAP with examples.
  3. List and briefly explain any four classes in Java Beans API.
  4. What is an EJB container? Explain how EJB invocation happens.
  5. Explain different layers in RMI architecture
  6. Discuss parameter passing in RMI, with examples
  7. What is introspection in java beans? Explain how the BeanInfo interface helps in introspection of beans?

Advanced Java Notes Conclusion

So in these notes on Advanced Java, the information provided is reliable and genuine, and the notes and books mentioned above are provided to help enhance students performance in the subject. Therefore students can use this article to help prepare for any upcoming exam on the subject.

Python Interview Questions and Answers for Freshers & Experienced

Python Interview Questions

Python is a vast subject and if you have to prepare for an interview in a short span of time you may feel a bit lost or overwhelmed about how to go about preparing for the day. Not to worry at all as BTech Geeks have come up with the best collection of commonly asked & basic Python Interview Questions for Freshers & Experienced candidates in this tutorial.

We all know that Programming language interviews can be tricky and so having strong foundations is very important. A technical interview starts as a simple discussion and then you would be asked questions randomly from different topics of python. The best way to prepare for such an interview is to follow a systematic approach and practice more with these basic to advanced concepts of Python Programming Interview Questions for Beginners.

Also Check: 

Python Programming Interview Questions and Answers for Freshers & Experienced

Here is the topic-wise list of Python Interview Questions for Freshers & Expert developers that helps you all to prepare well for a number of interviews in top companies. Take a look at them and press the pdf links for better preparation in no time.

Basic Python Interview Questions for Freshers

  1. What are the key features of Python?
  2. Differentiate between lists and tuples.
  3. Explain the ternary operator in Python.
  4. What are negative indices?
  5. How long can an identifier be in Python?
  6. What is the pass statement in Python?
  7. Is Python case-sensitive?
  8. How would you convert a string into lowercase?
  9. Explain help() and dir() functions in Python.
  10. How do you get a list of all the keys in a dictionary?
  11. How will you check if all characters in a string are alphanumeric?
  12. How would you declare a comment in Python?
  13. What is PEP 8?
  14. What are Python decorators?
  15. How is Python interpreted?

Frequently Asked Python Programming Interview Questions for Beginners

  1. What is Python good for?
  2. What is the Python interpreter prompt?
  3. How will you capitalize the first letter of a string?
  4. With Python, how do you find out which directory you are currently in?
  5. How do you insert an object at a given index in Python?
  6. How does a function return values?
  7. Will the do-while loop work if you don’t end it with a semicolon?
  8. Why do we need break and continue in Python?
  9. Can you name ten built-in functions in Python and explain each in brief?
  10. How will you convert a list into a string?
  11. Can you explain the life cycle of a thread?
  12. What is a dictionary in Python?
  13. What do you know about relational operators in Python?
  14. What are assignment operators in Python?
  15. What are membership operators?
  16. Explain identity operators in Python.
  17. What data types does Python support?

Basic to Advanced Python Coding Interview Questions 2021 for Freshers

  1. What is NumPy array?
  2. How do you debug a Python program?
  3. What is <Yield> Keyword in Python?
  4. How to convert a list into a string?
  5. What is a negative index in Python?
  6. How to convert a list into a tuple?
  7. How can you create Empty NumPy Array In Python?
  8. How to convert a list into a set?
  9. How do you Concatenate Strings in Python?
  10. How to count the occurrences of a particular element in the list?
  11. How to generate random numbers in Python?
  12. Write a Python Program to Find the Second Largest Number in a List?
  13. Write a Python Program to Check if a Number is a Prime Number?
  14. How to print sum of the numbers starting from 1 to 100?
  15. Write a Python Program to Count the Number of Digits in a Number?
  16. What is the output when we execute list(“hello”)?
  17. Write a program to find the sum of the digits of a number in Python?
  18. Write a program to reverse a number in Python?
  19. Write a Python Program to Count the Number of Vowels in a String?
  20. What is the output of the below program?
>>>names = ['Chris', 'Jack', 'John', 'Daman']
>>>print(names[-1][-1])

Interviews are very different from academics. In an interview, apart from the textbook knowledge and practical understanding, the approach to solving the problem is very crucial. To prepare for a Python interview, it is critical that your knowledge of the subject is effectively communicated to the interviewer.

This page has been written with the objective of helping readers to prepare for an exam or an interview. It contains probable questions and their solutions. We have compiled Python Interview Questions and Answers for Freshers & Experts to prepare for an exam or an interview. Over preparation can be overwhelming especially for students who are preparing for exams or interviewing for their first job. This is your guide to success !!

C Hello World Program

  • A simple C program to print Hello World string on screen. It is often the first C program of new programmers used to illustrate the basic syntax of a C programming language.

We are going to learn a simple “Hello World” C program which will give us a brief overview of how to write and compile a c program. Before that, we have to understand the structure and fundamental essential components of a bare minimum C program.

Components of a C Program

  • Preprocessor Commands : The preprocessor step comes before compilation of c program and it instruct the compiler to do required pre-processing before actual compilation.
  • Main Function : This is the function from where execution of any C program starts.
  • Comments : You can add comments and documentation in your source code, which will not be executed as the part of program. It helps others to better understand the logic of your code.
  • Variables : A variable in C is a named memory location where a program can store and modify the data.
  • Statements & Expressions : Statements and Expressions are used to implement the core logic of the C program(For Example: Sum = A+B;).

C Program to Print “Hello World”

Printing “Hello World” program is one of the simplest programs in C programming languages. It became the traditional first program that many people write while learning a new programming language.

/* Hello world Program in C */
#include <stdio.h>
 
int main(){
    printf("Hello World");
    return 0;
}

Output

Hello World

How to Write and Compile a C Program

  1. Write
    • Open a text editor and type the above mentioned “Hello World” code.
    • Save this file as HelloWorld.c.
  2. Compile
    • Open command prompt and go to your current working directory where you saved your HelloWorld.c file.
    • Compile your code by typing gcc HelloWorld.c in command prompt. Your program will compile successfully, If your program doesn’t contain any syntax error.
    • It will generate an a.out file.
  1. Execute
    • Now run your program by typing a.out in command prompt.
  1. Output
    • You will see “Hello World” printed on your console.

Description of Hello World program

  • First line is program is a comment placed between /* and */. Comments are used in a C program to write an explanation or for documentation purpose. When a program becomes very complex, we need to write comments to mark different parts in the program. These comments will be ignored by the compiler at compilation time.
  • The next line #include is a preprocessor directive to load the stdio.h(Standard Input/Output header file) library. This library provides some macros and functions for input or output which we can use in our program(like printf and scanf). We need stdio for printing “Hello World” using printf function.
  • The next line is int main(){.The int is what is called the return value. Every C program must have a main() function, and every C program can only have one main() function where program execution begins. The two curly brackets {} are used to group all statements together.
  • The next line is printf(“Hello World”) which is used for printing “Hello World” string on the screen.
  • The next line is return 0. int main() declares that main must return an integer. Returning 0 means informing operating system that program successfully completed, whereas returning 1 means error while running program.

Points to Remember

  • A comment starts with /*, and ends with */.
  • Some header files must be included at the beginning of your C program.
  • Every C program should have only one main() function where program execution starts.
  • All variables must be declared with respective data types before their first use.
  • Every statement must end with a semicolon.
  • Main returns an integer to Operating system informing about it’s termination state. Whether program executed successfully or an error has occurred.

C Programming Language Tutorial

This C programming language tutorial is designed for beginner programmers, that gives enough understanding on fundamental concepts of C programming language.

This C programming tutorial explains the fundamental concepts in C language like history of C language, identifiers and keywords, data types, storage classes, variables, decision making, functions, control statements, string, structures, preprocessor directives etc with c programs and sample input output.

C language is a general-purpose, imperative popular computer programming language. It supports structured programming, variable scope, recursion, provide low-level access to memory etc. C language become one of the most widely used programming languages of all time.

C programming language is the mother for all programming languages.

C Programming Tutorial Topics

C Introduction

  • C Introduction
  • C Programming History
  • C First Program
  • C Identifiers and Keywords
  • C Data Types
  • C Variables
  • C Constants and Literals
  • C printf and scanf Function

C Operators

  • C Operators Introduction
  • C Arithmetic Operator
  • C Assignment Operator
  • C Relational Operator
  • C Logical Operator
  • C Bitwise Operator
  • C Conditional Operator
  • C Type Casting in C

C Decision Making

  • C Decision Making Introduction
  • C if Statement
  • C if…else Statement
  • C Nested if Statement
  • C if-else Ladder
  • C switch case

C Flow Control

  • C Loop and Jump Introduction
  • C for loop
  • C while loop
  • C do..while loop
  • C break statement
  • C continue statement

C Functions

  • C Programming Function Introduction
  • C Function Declaration
  • C Function Definition
  • C Calling a Function
  • C Passing Function Arguments
  • C Important Facts about Functions
  • C Variable Scope Rules
  • C Storage Classes

C Arrays And Strings

  • C Programming Array
  • C Array Initialization
  • C Accessing Array Elements
  • C Multi Dimensional Array
  • C Passing Array to Function
  • C Returning Array from Function
  • C Programming Strings

C Pointers

  • C Programming Pointers
  • C Pointer Arithmetic
  • C Passing Pointer to Function
  • C Returning Pointer from Function
  • C Array of Pointers
  • C Pointer to a Pointer

C Structure And Union

C Standard Library

  • C ctype.h header file
  • C math.h header file
  • C string.h header file
  • C stdlib.h header file
  • C stdio.h header file
  • C errno.h header file
  • C assert.h header file

Additional Topics

  • C Input Output Library Functions
  • C Typedef
  • C File Handling
  • C Preprocessor Directives
  • C Header Files
  • C Program Examples
  • Graphics Programming in C
  • Pattern Printing C Programs
  • C Interview Questions and Answers
  • Puzzles and Tricky Questions

Brief History of C Language

  • C programming language was originally developed by Dennis Ritchie between 1969 and 1973 at AT&T Bell Labs in USA.
  • B was the precursor language of C. B was created by Ken Thompson at Bell Labs and was an interpreted language used in early versions of the UNIX. Over the time, they improved B language and created its logical successor C which is a compiled programming language.
  • The development of C programming language was closely tied to the development of the Unix operating system. Unix kernel was one of the first operating system kernels to be implemented in C.
  • The portability and architecture neutrality of UNIX was the main reason for the initial success of both C and UNIX.
  • In 1978, Dennis Ritchie and Brian Kernighan published the first edition of The C Programming Language.
  • In 1990, the ANSI C standard was adopted by the International Organization for Standardization.

Advantages of C Programming Language

  • Easy to learn
    C is a very easy to learn middle level language for expressing ideas in programming in a way that most people are comfortable with.
  • Structured programming language
    A structured programming language breaks and abstract a program into small logical components which are responsible for performing a specific task. C’s main structural components are functions or subroutines. It makes the program easier to understand and modify.
  • Powerful programming language
    C language provides a wide variety of inbuilt data types and ability to create custom data types using structs. It also provides a large set of commonly used Input/Output, Mathematical, String etc, related functions as C standard library. C has a rich set of control statements, arithmetic operators, loops etc which provides a powerful tool for programmer to implement his logic as a C program.
  • Low-level Language Support
    C language is reasonably close to assembly machine. It support features like pointers, bytes and bit level manipulation. C allows the programmer to write directly to memory. C structures, pointers and arrays are designed to structure and manipulate memory in an efficient, machine-independent fashion. It is generally used to create hardware devices, OS, drivers, kernels etc.
  • Produces portable programs
    C language produces portable programs, they can be run on any compiler with little or no modifications. One of the main strengths of C is that it combines universality and portability across various computer architectures.
  • Memory Management
    C language provide support for dynamic memory allocation. In C, we can allocate and free the allocated memory at any time by calling library functions like malloc, calloc and free.
  • Produces efficient programs
    C language is a compiled programming language, which creates fast and efficient executable files. It also provides a set of library functions for common utilities. C provides a lot of inbuilt functions that makes the development fast.

Disadvantages of C Programming Language

  • C Programming Language doesn’t support Object Oriented Programming(OOP) features like Inheritance, Encapsulation, Polymorphism etc. It is a procedure oriented language. In C, we have to implement any algorithms as a set of function calls.
  • C doesn’t perform Run Time Type Checking. It only does compile time type checking. At run time, C doesn’t ensure whether correct data type is used instead it perform automatic type conversion.
  • C does not provides support for namespace like C++. Without Namespace, we cannot declare two variables of same name.

C is a Middle Level Programming Language

C is often called a middle level programming language because it supports the feature of both high level and low level language. C being a mid level language doesn’t mean that, it is less powerful or harder to use than any high level language.

C combines the best elements of high level language with the control and flexibility of low-level language(assembly language).

Like assembly language, C provide support for manipulation of bits, bytes and memory pointers at the same time it provides abstraction over hardware access

Uses of C Programming Language

C is one of the most popular languages out there for programming lower level things like operating systems and device drivers, as well as implementing programming languages.
C was originally developed for creating system applications that direct interacts to the hardware devices. Below are some examples of uses of C programming language.

  • Operating System Kernel
  • Programming Language Compilers
  • Assemblers
  • Text Editors and Word processors
  • Print Spoolers
  • Network Drivers
  • Modern Softwares
  • Database and File systems
  • Embedded systems
  • Real Time softwares

Your First C Program

Printing “Hello World” program is one of the simplest programs in C programming languages. It became the traditional first program that many people write while learning a new programming language.

/* Hello world Program in C */
#include <stdio.h>
 
int main(){
    printf("Hello World");
    return 0;
}

Output

Hello World

How to Write and Compile a C Program

    1. Write
      • Open a text editor and type the above mentioned “Hello World” code.
      • Save this file as HelloWorld.c.
    1. Compile
      • Open command prompt and go to your current working directory where you saved your HelloWorld.c file.
      • Compile your code by typing gcc HelloWorld.c in command prompt. Your program will compile successfully, If your program doesn’t contain any syntax error.
      • It will generate an a.out file.
    1. Execute
      • Now run your program by typing a.out in command prompt.
    1. Output
      • You will see “Hello World” printed on your console.

Description of Hello World program

  • First line is program is a comment placed between /* and */. Comments are used in a C program to write an explanation or for documentation purpose. When a program becomes very complex, we need to write comments to mark different parts in the program. These comments will be ignored by the compiler at compilation time.
  • The next line #include is a preprocessor directive to load the stdio.h(Standard Input/Output header file) library. This library provides some macros and functions for input or output which we can use in our program(like printf and scanf). We need stdio for printing “Hello World” using printf function.
  • The next line is int main(){.The int is what is called the return value. Every C program must have a main() function, and every C program can only have one main() function where program execution begins. The two curly brackets {} are used to group all statements together.
  • The next line is printf(“Hello World”) which is used for printing “Hello World” string on the screen.
  • The next line is return 0. int main() declares that main must return an integer. Returning 0 means informing operating system that program successfully completed, whereas returning 1 means error while running program.

C Program to Print Number of Days in a Month using If Else Ladder Statement

C program to print number of days in months
  • Write a C program to print number of days in a month using if else ladder statement.

Required Knowledge

In this program, we will take a number between 1 to 12 as input from user, where 1 corresponds to January, 2 corresponds to February and so on. We will use if else ladder statement to print number of days in any month in words.

C program to print number of days in months

C program to print number of days in months

/*
 * C program to print Number of Days in any Month 
 */ 
   
#include <stdio.h> 
   
int main() {  
    int month;  
    /* 
     * Take the Month number as input form user  
     */ 
    printf("Enter Month Number (1 = January ..... 12 = December)\n");  
    scanf("%d", &month);  
 
    /* Input Validation */
    if(month < 1 || month > 12){
     printf("Invalid Input !!!!\n");
     return 0;
    }
  
    if(month == 2) {  
        printf("28 or 29 Days in Month\n");  
    } else if(month == 4 || month == 6 || month == 9 || month == 11) {  
        printf("30 Days in Month\n");  
    } else if (month == 1 || month == 3 || month == 5 || month == 7 
     || month == 8 || month == 10 || month == 12) {  
        printf("31 Days in Month\n");  
    }
   
    return 0;  
}

Output

Enter Month Number (1 = January ..... 12 = December)
2
28 or 29 Days in Month
Enter Month Number (1 = January ..... 12 = December)
12
31 Days in Month
Enter Month Number (1 = January ..... 12 = December)
9
30 Days in Month
Enter Month Number (1 = January ..... 12 = December)
15
Invalid Input !!!!

C Program to Print Natural Numbers in Reverse Order from 1 to N using For, While and Do-while Loop

C Program to Print Natural Numbers in Reverse Order from 1 to N using For, While and Do-while Loop
  • Write a C program to print natural numbers in reverse order from N to 1 using for loop.
  • Wap in C to print numbers in reverse order using while and do-while loop

Required Knowledge

C program to print natural numbers from N to 1 in reverse order using for loop

C program to print natural numbers from N to 1 in reverse order using for loop

#include <stdio.h>  
   
int main() {  
    int counter, N;  
    /* 
     * Take a positive number as input form user 
     */ 
    printf("Enter a Positive Number\n");  
    scanf("%d", &N);  
   
    printf("Printing Numbers form %d to 1\n", N);  
    /* 
     * Initialize the value of counter to N and keep on 
     * decrementing it's value in every iteration till 
     * counter > 0 
     */
    for(counter = N; counter > 0; counter--) {  
        printf("%d \n", counter);  
    }
     
    return 0;  
}

Output

Enter a Positive Number
10
Printing Numbers form 10 to 1
10
9
8
7
6
5
4
3
2
1

C program to print numbers in reverse order from 10 to 1 using while loop

C program to print numbers in reverse order from 10 to 1 using while loop

#include <stdio.h>  
   
int main() {  
    int counter, N;  
    /* 
     * Take a positive number as input form user 
     */
    printf("Enter a Positive Number\n");  
    scanf("%d", &N);  
   
    printf("Printing Numbers form %d to 1\n", N);  
    /* 
     * Initialize the value of counter to N and keep on 
     * decrementing it's value in every iteration till 
     * counter > 0 
     */
    counter = N;
    while(counter > 0) {  
        printf("%d \n", counter);  
        counter--;
    }
     
    return 0;  
}

Output

Enter a Positive Number
6
Printing Numbers form 6 to 1
6
5
4
3
2
1

C program to print numbers in reverse from N to 1 using do while loop

C program to print numbers in reverse from N to 1 using do while loop

#include <stdio.h>  
   
int main() {  
    int counter, N;  
    /* 
     * Take a positive number as input form user 
     */ 
    printf("Enter a Positive Number\n");  
    scanf("%d", &N);  
   
    printf("Printing Numbers form %d to 1\n", N);  
    /* 
     * Initialize the value of counter to N and keep on 
     * decrementing it's value in every iteration till 
     * counter > 0 
     */
    counter = N;
    do {  
        printf("%d \n", counter);  
        counter--;
    } while(counter > 0);
     
    return 0;  
}

Output

Enter a Positive Number
6
Printing Numbers form 6 to 1
6
5
4
3
2
1