C Program to Check Whether an Alphabet is Vowel or Consonant using Switch Case Statement

Required Knowledge

A vowel is the alphabets that represents a speech sound created by the relatively free passage of breath through the larynx and oral cavity. Letters that are not vowels are consonants. English has five proper vowel letters (A, E, I, O, U) all alphabets except these characters are consonants.

C program to check whether a character is vowel or consonant using switch statement

C program to check whether a character is vowel or consonant using switch statement

#include <stdio.h>  
   
int main() {  
    char c;  
   
    /* 
     * Take a character as input form user 
     */ 
    printf("Enter an Alphabet\n");  
    scanf("%c", &c);  
     
    /* Check If input alphabet is vowel or not 
    using switch statement */
    switch(c) {  
        case 'a':    
        case 'A':
        case 'e':  
        case 'E':
        case 'i':  
        case 'I':  
        case 'o':  
        case 'O':  
        case 'u':  
        case 'U': printf("%c is VOWEL", c);  
            break;  
        default: printf("%c is CONSONANT", c);  
    }  
   
    return 0;  
}

Output

Enter an Alphabet
e
e is VOWEL
Enter an Alphabet
Z
Z is CONSONANT

C Program to Add Two Numbers

  • Write a C program to add two numbers and print sum on screen.

Before this program, you should read Arithmetic Operators in C

This program takes two numbers as input from user and add them using ‘+’ arithmetic operator and prints the sum on screen. Addition operator in C correspond literally to their respective mathematical operators. If user enters 2 and 3 as input numbers then 5(2 + 3) will be printed as sum on screen.

C program to add two numbers using ‘+’ operator

In this program, we first take two numbers as input from user using scanf function and stores them in integer variable firstNumber and secondNumber. Then we add firstNumber and secondNumber using ‘+’ operator and stores the result in variable ‘sum’. Finally, we print the sum on screen using printf function.

C program to add two numbers using '+' operator 1

/*
* C Program to print sum of two numbers
*/
#include <stdio.h>
#include <conio.h>
 
int main(){
    /* Integer variable declation */
    int firstNumber, secondNumber, sum;
     
    /* Taking input from user and storing it in firstNumber 
       and secondNumber */
    printf("Enter First Number: ");
    scanf("%d", &firstNumber);
    printf("Enter Second Number: ");
    scanf("%d", &secondNumber);
     
    /* Adding two numbers and storing the result in variable "sum" */
    sum = firstNumber + secondNumber;
    printf("Sum of %d and %d is %d", firstNumber, secondNumber, sum);
    getch();
    return 0;
}
</conio.h></stdio.h>

Program Output

Enter First Number: 2
Enter Second Number: 4
Sum of 2 and 4 is 6

C program to add two numbers using function

This program takes two numbers as input from user and pass it to a user defined function ‘getSum’. Function ‘getSum’ takes two numbers as input parameter and returns sum of the input arguments.

C program to add two numbers using function 1

/*
* C Program to Add two numbers using function 
*/
#include <stdio.h>
#include <conio.h>
 
int getSum(int num1, int num2);
int main(){
    /* Integer variable declation */
    int firstNumber, secondNumber, sum;
     
    /* Taking input from user and storing it in firstNumber and secondNumber */
    printf("Enter First Number: ");
    scanf("%d", &firstNumber);
    printf("Enter Second Number: ");
    scanf("%d", &secondNumber);
     
    /* Adding two numbers by calling getSum function 
    and storing the result in variable "sum" */
    sum = getSum(firstNumber, secondNumber);
    printf("Sum of %d and %d is %d", firstNumber, secondNumber, sum);
    getch();
    return 0;
}
/*
* Function to add two numbers
*/
int getSum(int num1, int num2){
    int sum;
    sum = num1 + num2;
    return sum;
}

Program Output

Enter First Number: 4
Enter Second Number: 5
Sum of 2 and 4 is 9

C Program to add two numbers using pointers

This program uses two integer pointer to store the memory address of two operands. It first takes two integers as input from user using scanf function and stores them in firstNumber and secondNumber integer variable. Next step is to assign the addresses of these two input variables to integer pointers. Then value of operator is used to access the data stored in the memory location pointed by these pointer to find the sum.

C Program to add two numbers using pointers 1

/*
* C Program to Add two numbers using pointers
*/
#include <stdio.h>
#include <conio.h>
  
int main(){
    
    int firstNumber, secondNumber, sum;
    /* Pointers declaration */
    int *firstNumberPointer, *secondNumberPointer;
    printf("Enter two numbers \n");
    scanf("%d %d", &firstNumber, &secondNumber);
    /* Pointer assignment*/
    firstNumberPointer = &firstNumber;
    secondNumberPointer = &secondNumber;
    
    sum = *firstNumberPointer + *secondNumberPointer;
    printf("SUM = %d", sum);
    getch();
    return 0;
}

Program Output

Enter two numbers 
3 8
SUM = 11

Problem Solving and Programming In C Notes and Study Material PDF Free Download

problem-solving-and-programming-in-c-notes

Problem Solving and Programming in C Notes: C is one of the popular programming languages that are simple and flexible. It is a general-purpose programming language that is widely used in different kinds of applications. Operating Systems like Windows and many others are written in C language. Git, Python Interpreter, and Oracle Database are also written in C. This language is often called the base knowledge of programming. If you know this language, it becomes easier for you to learn any other programming language. This is a simple language which can provide faster execution. The demand for C developers is very high in the job market. This programming language can extend itself. It contains various kinds of functions that are part of the library. In this article, you will find complete details about problem-solving and programming of C language Lecture Notes.

Introduction to Problem Solving And Programming In C

Ritchie first developed this language in 1972. It is a structured language that is widely used in the software development field. For every software developer, it is important to know the C language. This language can handle low-level activities and can be compiled easily. This language is primarily used in UNIX. This language is the successor of the B language. C language is used in databases, utilities, text editors, assemblers, operating systems, and language compilers. In C programming course, you will learn this programming language from scratch. You will find all the study materials of this widely used language from this article.

Problem Solving And Programming In C Notes and Study Material PDF Free Download

Anyone interested in making a career in software development should learn C programming. It is because this language is considered as the base language of every other programming language. If you plan to do a course on C programming, you can find the right study material through this article. We have made a list of some important study materials on C programming. You can check out computer programming terminologies once before starting C programming course.

Problem Solving And Programming In C textbook pdf Download
Problem Solving And Programming In C note & Study material Download
Problem Solving And Programming In C notes Download
Introduction to C programming Download

Problem Solving And Programming In C Reference Books

It is a relatively small language, but it is very useful. You need to learn some simple things in C programming. This language was mainly discovered so that programmers can interact with the machines efficiently. To learn this language, you must read the right set of books. We have made a list of some important books on C language.

  • C Programming Absolute Beginner’s Guide.
  • C Programming Language.
  • The C Programming Language 2nd Edition.
  • C Programming: A Modern Approach.
  • Expert C Programming: Deep Secrets.
  • C: The Complete Reference.
  • Head First C: A Brain-Friendly Guide.
  • Computer Fundamentals and Programming in C.
  • Low-Level Programming by Igor Zhirkov
  • C in a Nutshell by Peter Prinz & Tony Crawford

Problem Solving And Programming In C Curriculum

Before starting the course on C programming, you must know the syllabus. It is crucial to understand the syllabus. The syllabus of C programming varies depending on the type of course and institution. However, the basic structure of the C programming’s syllabus remains the same. In this article, you will get to know about the necessary details taught in C programming.

C Programming Language Syllabus

Fundamentals of C Language

About C tutorial

Important points about C

Why Use C

Applications of C

C Language and English Language

Features of C

C, C++ and Java

Overview of C Language

History of C

First Program in C Hello World

Basic Structure of C Programming

Tokens in C

Keywords in C

Identifiers in C

Format Specifiers

Format Specifiers Examples

Data Types in C Language

Introduction to Data Types in C

int Data Type in C

float Data Type in C

double Data Type in C

char Data Type in C

Variable in C Language

Variable Introduction in C

Variable Declaration and Initialization

Variable types and Scope in C

Local Variable in C

static Variable in C

Global variables in C

Storage Class in C

Constant in C Language

Constants in C

Operators and Enums in C Language

Introduction to Operator

Arithmetic Operators in C

Relational Operators in C

Bit-wise Operators in C

Logical Operators in C

Assignment Operators in C

Conditional Operator in C

size of() Operator in C

Operator Precedence

Decision Making of C Language

Decision Making in C Introduction

if Statement

if-else Statement

Nested if Statement

if-else if Ladder

switch case

Loop control in C Language

Loop Introduction in C

while loop in C

do-while Loop In C

for Loop in C

Control Flow in C Programming

break Statement in C

continue Statement in C

goto statement in C

Array in C Language

Single Dimensional Array

Multi-Dimensional Array in C

String in C Language

Introduction to String

Function in C Language

Function in C

Function Calling in C

return type in Function

Call by Value in C

User Define Function

Predefined Functions

String functions in C

All String Functions

strcat() function

strncat() function

strcpy() function

strncpy() function

strlen() function

strcmp() function

strcmpi() function

strchr() function

strrchr() function

strstr() function

strrstr() function

strdup() function

strlwr() function

strupr() function

strrev() function

strset() function

strnset() function

strtok() function

Recursion in c

Introduction to Recursion

Direct and Indirect Recursion

Pointer in C Language

Pointer in C

types of pointer

NULL pointer

Dangling Pointer

Void/Generic Pointers

Wild Pointer

Near, Far and Huge Pointer

Pointer Expressions and Arithmetic

Pointer and Array

Strings as pointers

Pointer to Function

Call by Reference in C

Structure in C Language

Structure in C

Nested Structure in C

The array of Structures in C

Pointer to Structure

Structure to Function in C

typedef in C

typedef vs #define in C

Union in C Language

Union in C

File Input/Output

Introduction to File

File Operation in c

Dynamic Memory Allocation

Introduction to DMA

calloc() and free() function

realloc() and free() function

C Pre-processor

Introduction about Pre-processor

List of Problem Solving And Programming In C Important questions

  • What is the difference between ++i and i++?
  • Give a brief note on the volatile keyword.
  • What are the basic data types related to C?
  • Explain syntax errors.
  • How can you create a decrement and increment statement in C?
  • Explain dangling pointer in C.
  • What is called the prototype function in C?
  • What is a header file? Explain its usage in C programming.
  • Explain pointer on a pointer in C language.
  • How can you save data in a stack data structure type?

FAQs on Problem Solving and Programming in C Notes

Question 1.
What is called the C language?

Answer:
C is one of the popular programming languages that are simple and flexible. It is a general-purpose programming language that is widely used in different kinds of applications.

Question 2.
What kind of software is written in the C language?

Answer:
Operating Systems like Windows and many others are written in C language. Git, Python Interpreter, and Oracle Database are also written in C.

Question 3.
When was C language developed?

Answer:

Ritchie first developed the C language in 1972. It is a structured language that is widely used in the software development field.

Question 4.
Is it tough to learn the C language?

Answer:
It is not that difficult to learn the C language. C language is often called the base language in programming. After learning the C language, it becomes easier to learn other programming languages like C++, Java, C# etc.

Conclusion

The information provided above regarding the syllabus and study materials for C programming will help in your study. If you have any other questions regarding C programming study materials, please let us know in the comment section.

C Program to Print Natural Numbers from 1 to N using For, While and Do While Loop

C Program to Print Natural Numbers from 1 to N using For, While and Do While Loop
  • Write a C program to print natural numbers from 1 to N using for loop.
  • Write a C program to print numbers from 1 to 10 using while loop.
  • Write a C program to print numbers from 1 to 100 using do while loop.

Required Knowledge

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

C Program to Print Natural Numbers from 1 to N using For, While and 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 1 to %d\n", N);  
    /* 
     * Initialize the value of counter to 1 and keep on 
     * incrementing it's value in every iteration till
     * counter <= N 
     */
    for(counter = 1; counter <= N; counter++) {  
        printf("%d \n", counter);  
    }
     
    return 0;  
}

Output

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

C program to print numbers from 1 to N using while loop

C program to print numbers from 1 to N 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 1 to %d\n", N);  
    /* 
     * Initialize the value of counter to 1 and keep on 
     * incrementing it's value inside while loop body 
     * in every iteration 
     */
    counter = 1;
    while(counter <= N) {  
        printf("%d \n", counter);  
        counter++;
    }
     
    return 0;  
}

Output

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

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

C program to print numbers from 1 to N 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 1 to %d\n", N);  
    /* 
     * Initialize the value of counter to 1 and keep on 
     * incrementing it's value inside do-while loop body 
     * in every iteration 
     */
    counter = 1;
    do {  
        printf("%d \n", counter);  
        counter++;
    } while(counter <= N);
     
    return 0;  
}

Output

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

C Program to Calculate Area and Perimeter of a Rhombus

C Program to Calculate Area and Perimeter of a Rhombus
  • Write a C program to find the area and perimeter of a rhombus.

A rhombus is quadrilaterals(having four sides) with all sides equal in length and opposites sides parallel. Opposite angles of a rhombus are also equal. A rhombus is a special case of parallelogram where all sides are equal in length.

  • Diagonals of a rhombus are perpendicular and divides each other in two equal half.
  • Opposite sides of a rhombus are parallel and all sides are equal in length.
  • Opposite angles of a rhombus are equal.
  • The sum of any two adjacent angles of a rhombus are 180 degrees.
  • The diagonal of rhombus bisects the interior angle.

To calculate the area of rhombus we need length of Base and Height of length of both diagonals.

Base : We can choose any side of a rhombus as base to calculate area of rhombus.
Height : Height of a rhombus is the perpendicular distance between the base and it’s opposite side.
Diagonals : A line segment joining opposite vertices of a rhombus.

C Program Area Of Rhombus
Area of Rhombus A Rhombus is also a parallelogram. Hence, If we know the length of Base and Height then we can calculate area of rhombus by multiplying Base and Height.

  • Area of Rhombus = B X H

Where, B is the length of base of Rhombus.
H is the length of height of Rhombus.
(Base and Height are perpendicular on each other)

If we know the length of both diagonals of a rhombus the, it’s area can be calculated by multiplying length of both diagonals and then dividing it by 2.

  • Area of Rhombus = (Product of diagonals)/2 = (A X B)/2

Where A and B are the length of diagonals of rhombus

C Program to find the area of the rhombus

To calculate the area of a rhombus we need the length of both diagonals of a rhombus. Below program first takes the length of diagonals as input from user and stores it in two floating point numbers. Now, to find the area of rhombus we take semi product of diagonals. It finally prints the area of rhombus on screen using printf function.

C Program to Calculate Area and Perimeter of a Rhombus

/*
* C Program to calculate area of rhombus
*/
#include <stdio.h>
#include <conio.h>
 
int main(){
    float diagonalOne, diagonalTwo, area;
    printf("Enter the length of diagonals of rhombus\n");
    scanf("%f %f", &diagonalOne, &diagonalTwo);
    /* Area of rhombus = (product of diagonals)/2 
                       = (diagonalOne X diagonalTwo)/2 */
    area = (diagonalOne * diagonalTwo)/2;
    printf("Area of rhombus : %0.4f\n", area);
     
    getch();
    return 0;
}

Program Output

Enter the length of diagonals of rhombus
3.5 4
Area of rhombus : 7.0000

C Program to find the perimeter of rhombus

The perimeter of a rhombus is the linear distance around the boundary of the rhombus. In other words, we can think of perimeter of a rhombus as the length of fence needed to enclose a rhombus.

Perimeter of Rhombus The perimeter of a Rhombus can be calculated by adding the length of all four sides of Rhombus. As we know the length of all sides of rhombus are equal, so perimeter of rhombus is equal to four times side of rhombus.

  • Perimeter of Rhombus = 4 X S

Where, S is the length of any side of rhombus.

C Program to find the perimeter of rhombus

/*
* C Program to calculate perimeter of rhombus
*/
#include <stdio.h>
#include <conio.h>
 
int main(){
 float side, perimeter;
 printf("Enter the length of side of rhombus\n");
 scanf("%f", &side);
 /* Perimeter of rhombus = 4 X Side */
 perimeter = 4 * side;
 printf("Perimeter of rhombus : %0.4f\n", perimeter);
  
 getch();
 return 0;
}

Program Output

Enter the length of side of rhombus
6.5
Perimeter of rhombus : 26.0000

To calculate the perimeter of rhombus, we need length of side of rhombus. Above program, first takes length of any side of rhombus as input from user and stores it in a floating-point variable. Then, we multiply length of side by 4 and store the result in a floating point variable called ‘perimeter’. Finally, it prints the perimeter of Rhombus on screen using printf function.

Interesting Facts about Rhombus

  • A rhombus has rotational symmetry.
  • The shape of basketball ground is rhombus.
  • A square is also a rhombus, having equal sides and all interior angles as 90 degrees.
  • A rectangle is also a rhombus, having opposites sides equal parallel and all interior angles as 90 degrees.
  • A rhombus is a special case of parallelogram, where all sides are equal.
  • The diagonals of rhombus intersect at right angle.

C Program to Check Whether a Triangle is Valid or Not given Sides of Triangle

C program to check whether a triangle is valid, given sides of triangle 1
  • Write a C program to enter three sides of a triangle and check whether a triangle is valid or not.

Required Knowledge

A triangle is a valid triangle, If and only If, the sum of any two sides of a triangle is greater than the third side.

For Example, let A, B and C are three sides of a triangle. Then, A + B > C, B + C > A and C + A > B.

C program to check whether a triangle is valid, given sides of triangle

C program to check whether a triangle is valid, given sides of triangle 1

/*
 * Given three sides of a triangle, Write a c program to 
 * check whether it is a valid triangle or not 
 */ 
   
#include <stdio.h>  
   
int main() {  
    int side1, side2, side3;  
   
    /* 
     * Take length of three sides of triangle as input 
     * from user using scanf 
     */ 
    printf("Enter Length of Three Sides of a Triangle\n");  
    scanf("%d %d %d", &side1, &side2, &side3);     
   
    if((side1 + side2 > side3)&&(side2 + side3 > side1)
            &&(side3 + side1 > side2)) {  
        printf("It is a Valid Triangle\n");  
    } else {  
        printf("It is an invalid Triangle");  
    }  
   
    return 0;  
}

Output

Enter Length of Three Sides of a Triangle
10 20 20
It is a Valid Triangle
Enter Length of Three Sides of a Triangle
10 20 40
It is an invalid Triangle

Decision Making in C Programming

The decision making statements in C language are used to perform operations on the basis of condition and when program encounters the situation to choose a particular statement among many statements.

Decision making statements lets you evaluate one or more conditions and then take decision whether to execute a set of statements or not.

By using decision making statements you can execute statements or select some statements to be executed base on outcome of condition(whether it is true or false). The outcome of conditional statement must be either true(In C, all non-zero and non-null values are considered as true) or false((In C, zero and null value is considered as false).

C-Decision-Making

Types of Decision Making statements in C

Click on the links below to check detailed description of control statements.

Control Statements Description.
If statements If statement is used to execute the code if condition is true
If else statements If else statement is used to execute a code when condition is true otherwise it execute another code in else section
Nested if statements We can use if statement inside another if statement, if we want to execute a code when multiple conditions become true
If else if ladder If else ladder is used, If we want to check for multiple conditions one after another
Switch statement Switch statement allows us to perform equality test of value of a variable against a list of possible values.

C Program to Add Two Numbers Using Pointers

  • Write a program in c to add two numbers using pointers.

A variable in C is the name given to a memory location, where a program can store data. Instead of referring a variable’s data with it’s identifier we can also use memory address to access it using ‘*'(value of) operator. To get the memory address of any variable we can use ‘&'(Address Of) Operator.

This program does addition of two numbers using pointers. First, we take two integers as input form user and store it in firstNumber and secondNumber integer variables then we assign addresses of firstNumber and secondNumber in firstNumberPointer and secondNumberPointer integer pointer variable respectively using Address operator(&). Now we add the values pointed by firstNumberPointer and secondNumberPointer using Value at operator (*) and store sum in variable sum. At last, prints the sum on screen using printf function.

Pointer Operators in C

Operator Operator name Description
* Value at Operator Returns the value of the variable located at the address specified by the pointer
& Address of operator Returns the memory address of a variable

C Program to Add Two Numbers using Pointer

C Program to Add Two Numbers using Pointer 1

/*
* C Program to Add two numbers using pointers
*/
#include <stdio.h>
#include <conio.h>
 
int main(){
     
    int firstNumber, secondNumber, sum;
    /* Pointers declaration */
    int *firstNumberPointer, *secondNumberPointer;
    printf("Enter two numbers \n");
    scanf("%d %d", &firstNumber, &secondNumber);
    /* Pointer assignment*/
    firstNumberPointer = &firstNumber;
    secondNumberPointer = &secondNumber;
     
    sum = *firstNumberPointer + *secondNumberPointer;
    printf("SUM = %d", sum);
    getch();
    return 0;
}

Program Output

Enter two numbers 
4 6
SUM = 10

C Program to Check Whether a Triangle is Valid or Not given Angles of Triangle

C Program to Check Whether a Triangle is Valid or Not given Angles of Triangle
  • Write a C program to read three angles of a triangle and check whether a triangle is valid or not.

Required Knowledge

A triangle is a valid triangle, If and only If the sum of all internal angles is equal to 180. This is known as angle sum property of triangle. We will use this triangle property to check whether three given angles can form a valid triangle.

C program to check whether a triangle is valid, given angles of triangle

C Program to Check Whether a Triangle is Valid or Not given Angles of Triangle

/*
 * Given three angles of a triangle, Write a c program to 
 * check whether it is a valid triangle or not 
 */ 
   
#include <stdio.h>  
   
int main() {  
    int angle1, angle2, angle3;  
   
    /* 
     * Take three angles of triangle as input 
     * from user using scanf 
     */ 
    printf("Enter Three Angles of a Triangle\n");  
    scanf("%d %d %d", &angle1, &angle2, &angle3);     
   
    /* 
     *Sum of all three angles of any triangle is 180 degree 
     */ 
    if( angle1 + angle2 + angle3 == 180) {  
        printf("It is a Valid Triangle\n");  
    } else {  
        printf("It is an invalid Triangle");  
    }  
   
    return 0;  
}

Output

Enter Three Angles of a Triangle
30 60 90
It is a Valid Triangle
Enter Three Angles of a Triangle
60 70 80
It is an invalid Triangle

C Program to Check Whether a Character is Decimal Digit or Not using Conditional Operator

C Program to Check Whether a Character is Decimal Digit or Not using Conditional Operator
  • Write a C program to check a character is decimal digit or not using conditional or ternary operator.

Required Knowledge

In this program, we will check whether the ASCII value of input character(C)is in between the ASCII value of ‘0’ and ‘9’ decimal digit character(including ‘0’ and ‘9’).

In other words, If ‘0’ <= C <= ‘9’ is true, then C is a decimal digit character.

C program to check for decimal digit characters using conditional operator

C program to check for decimal digit characters using conditional operator

#include <stdio.h>  
   
int main() {  
    char c;
    int isDigit;  
   
    /* Take a character as input from user
  using scanf function */
    printf("Enter a Character\n");  
    scanf("%c", &c); 
     
    /* Check, If input character is digit */ 
    isDigit =  ((c >= '0') && (c <= '9'))? 1 : 0;  
     
    if(isDigit == 1)
        printf("%c is Decimal Digit Character\n", c);
    else
        printf("%c is Not a Digit Character\n", c);
   
    return 0;  
}

Output

Enter a Character
7
7 is Decimal Digit Character
Enter a Character
A
A is Not a Digit Character