Computer Programming C: UNIT I: Introduction to C

Problem Solving Through Algorithms, Flowcharts and Pseudocodes

C Programming

C Programs - Problem Solving Through Algorithms, Flowcharts and Pseudocodes

PROBLEM SOLVING THROUGH ALGORITHMS, FLOWCHARTS AND PSEUDOCODES

 

Example 1: Write a program to find the area and circumference of the circle.

Algorithm

Step 1: Start

Step 2: Input the radius of the circle

Step 3: Find the area and circumference of the circle using the formula Area ←3.14 * r * r

circumference ← 2* 3.14 * r

Step 4: Print the area and circumference of the circle

Step 5: Stop

Pseudocode

Set initial zero to Area, Circumference


READ the radius of the circle Find the area and circumference of the circle using formula

Area = 3.14 * r * r

Circumference = 2 * 3.14 * r

WRITE output of area and circumference of the circle

 

Example 2: Write a program to find the roots of the quadratic equation.

Algorithm

Step 1: Start

Step 2: Enter the value of a,b,c

Step 3: Find the value of 'D' of using the formula

D ← b * b ‒ 4 * a * c.

Step 4: If D is greater than or equal to zero then find the two roots are root 1 ← (‒b + sqrt(d)) / (2 * a)

root 2 ← (‒b‒sqrt(d)) / (2 * a)

Step 5: Print the two roots, root1, root2

Step 6: If D.is not greater than or equal to zero, then print the roots are imaginary

Step 7: Stop

Flow chart


Pseudocode

Set initial zero to rootl, root2

READ the value of a,b,c

Find discriminant

D = b * b ‒ 4 * a * c

IF D > = 0 THEN

calculate root1 = (‒b + sqrt(D)) / (2 * a)

               root2 = (‒b ‒ sqrt(D)) / (2 * a)

ELSE

     Roots are imaginary

ENDIF

WRITE root1, root2

 

Example 3:  Write a program to find the factorial of the given number.

Algorithm

Step 1: Start

Step 2: Read the value of n

Step 3: Set initial values to Fact ← i ← 1

Step 4: Is i<= n else Goto Step 6

          Step. 4.1 Fact ← Fact*i

          Step 4.2 i ← i + 1

Step 5: Goto Step 4

Step 6: Print Fact

Step 7: Stop

Flow chart


Pseudocode

Set initial one to Fact, i

READ n value to find Factorial

IF (i<=n) THEN

       Fact = Fact * i

       i = i + 1

ENDIF

 

Example 4: Write a program to find the sum of the digits of a positive number.

Algorithm

Step 1: Start

Step 2: Enter the value of n

Step 3: Assign r ← 0, sum ← 0

Step 4: IF n>0 ELSE Goto step 6

      Step 4: r←n mod 10

       Step 4.2: sum ← sum + r

       Step 4.3: n ← n div 10

Step 5: Goto Step 4

Step 7: Stop

Flowchart


Pseudocode

Set initial zero to r, sum

Read the value of n

WHILE (n > 0)

      r = n mod 10

     sum = sum + r

      n = n div10

ENDWHILE

Repeat while until the condition fail

WRITE sum

 

Example 5: Write a program to find the given number is an Armstrong number or not.

Algorithm

Step 1: Start

Step 2: Enter the value of n

Step 3: Assign a ←n, r = 0, sum = 0

Step 4: IF n>0 ELSE Goto Step 6

          Step 4.1: r ← n mod 10

          Step 4.2: sum ← sum + r * r * r

          Step 4.3: n ← n div 10

Step 5: Goto Step 4

Step 6: IF a = sum THEN print Armstrong

          ELSE print Not Armstrong

Step 7: Stop

Flow chart


Pseudocode

Set initial a=n, sum=0, r=0

READ the value of n

WHILE (n>0)

         r = n % 10

        sum = sum+r*r*r

        n = n/10

ENDWHILE

Repeat while until the condition fail

IF (sum = = a) THEN

      WRITE the result is Armstrong

ELSE

      WRITE the result is not Armstrong

ENDIF

 

Example 6: Write a program to print the Reverse of a Number.

Algorithm

Step 1: Start

Step 2: Enter the value of n

Step 3: Assign r = 0, sum = 0

Step 4: IF n>0 ELSE Goto Step 6

         Step 4.1: r ← n mod 10

         Step 4.2: sum ← sum * 10 + r

         Step 4.3: n ← n div 10

Step 5: Goto Step 4

Step 6 Print Sum

Step 7: Stop

Flow chart


Pseudocode

Set initial sum=0, r=0

READ the value of n

WHILE (n>0)

        r = n % 10

       sum = sum * 10 + r

       n = n/10

ENDWHILE

Repeat while until the condition fail

WRITE reverse number is Sum

 

Example 7: Write a program to find whether the number is prime or not.

Algorithm

Step 1: Start

Step 2: Assign i← 2

Step 3: READ n

Step 4: REPEAT Steps 4.1, 4.2 UNTIL i <= n‒1

          Step 4.1: IF (n mod i=0) THEN

                    Step 4.1.1: Print Not Prime

                    Step 4.1.2: Exit

        Step 4.2: I ← i + 1

Step 5: IF (i=n) Then

Step 6: Print Prime

Step 7: Stop

Flow chart


Pseudocode

Set initial 2 to i

READ n

IF (i <= n‒1)

     IF (n mod i=0)

          WRITE "Not Prime".

          EXIT

ENDIF

i = i + 1

IF (i=n)

         WRITE "Prime"

     ENDIF

ENDIF

 

Example 8: Write a program to find the given year is a leap year or not.

Algorithm

Step 1: Start

Step 2: Read the year.

Step 3: IF (Year mod 4) = 0 THEN Print "it is a leap year"

             ELSE Print "It is not leap year"

Step 5: Stop

Flow chart


Pseudocode

READ the year

IF (year % 4 = 0) THEN

      WRITE the year is leap year

ELSE

     WRITE the year is not a leap year

ENDIF

 

Example 9: Write a program to find the largest of three numbers.

Algorithm

Step 1: Start

Step 2: READ a,b,c

Step 3: IF (a>b) and (a>c) Then

        Step 3.1: Print 'A is Big'

            ELSE

Step 4: IF (b>c) Then

         Step 4.1: Print 'B is Big'

               ELSE

         Step 4.2 Print 'C is Big'

Step 5: Stop

Flow Chart


Pseudocode

READ the value for a, b, с

IF (a>b and a>c) THEN

       WRITE 'A is Big'

ELSE IF (b>c) THEN

       WRITE 'B is Big'

ELSE

      WRITE 'C is Big'

ENDIF

 

Example 10: Write a program to find area of the triangle.

Algorithm

Step 1: Start

Step 2: Read the value of a,b,c

Step 3: To calculate three sides of the triangle using formula

                s ← (a+b+c)/2

Step 4: To find area of a triangle apply formula

           area ← sqrt (s*(s‒a)*(s‒b)*(s‒c))

Step 5: Print the area

Step 6: Stop

Flow chart


Pseudocode

READ the value of a,b,c

To calculate three sides of triangle using formula

      s = (a+b+c)/2

To find area of a triangle using formula

     area=sqrt (s * (s‒a) * (s‒b) * (s‒c))

WRITE output area

 

Example 11: Write a program to convert the Celsius into Fahrenheit.

Algorithm

Step 1: Start

Step 2: Read the Celsius value

Step 3: Calculate the Fahrenheit value by using the formula

           Fahrenheit ← (1.8* Celsius) + 32.

Step 4: Print the Fahrenheit value

Step 5: Stop

Flow chart


Pseudocode

READ the value of Celsius

Calculate Faren = (1.8* Celsius) + 32

WRITE the output Fahrenheit

 

Example 12. Write a program to generate the Fibonacci series.

Algorithm

Step 1: Start

Step 2: Assign F1←0, F2 ← 1, F ← 0

Step 3: Print F1, F2

Step 4: F ← F1+F2

Step 5: READ n

Step 6: IF (F<n) ELSE Goto Step 8

        Step 6.1: F ← F1 + F2

        Step 6.2: F1 ← F2

        Step 6.3: F2← Ƒ

        Step 6.1: Print F

Step 7: Goto Step 6

Step 8: Stop

Flow Chart


Pseudocode

Set inital zero to F1, F, one to F2

WRITE F1, F2

F = F1+F2

READ n

WHILE (F<N)

         F = F1 + F2

         F1 = F2

         F2 = F

        WRITE F

Repeat while until the condition fail

ENDWHILE

 

Example 13: Write a program to find the sum of all odd integers between 1 and n.

Algorithm

Step 1: Start

Step 2: Read the value of n

Step 3: Assign sum←0 and initial i<1

Step 4: IF i <= n ELSE Goto Step 6

     Step 4.1: Sum←sum+i

     Step 4.2: i←i + 2

Step 5: Goto Step 4

Step 6: Print sum

Step 7: Stop

Flow Chart


Pseudocode

Set initial to sum=0, i=1

READ the value of n

WHILE (i <= n)

       sum = sum+i

       i= i+2

ENDWHILE

Repeat while until the condition fail

WRITE the result sum

 

Example 14: Write a program to solve the series s = x ‒ x3/3! + x5/5! + x7/7! + xn/n!.

Algorithm

Step 1: Start

Step 2: Read the value of x, n

Step 3: Assign s←0, term←x, i←l

Step 4: The value of the term incremented to get next term and the term is added to s

Step 5: s←s+ term

Step 6: term = term * x *x(‒1) / (i+1) (i+2)

Step 7: i ← i+2

Step 8: Repeat step 5 to step 7 WHILE (i <= n)

Step 9: Stop

Flow Chart


Pseudocode

Set initial to s, term=x, i=1

WHILE (i <= n)

      s=s+term

      term (term*x*x(‒1)/(i+1)*(i+2))

      i = = i+2

ENDWHILE

Repeat while until the condition fail

WRITE the Result

 

Example 15: Write a program to convert a binary number to decimal number.

Algorithm

Step 1: Start

Step 2: Read the binary value

Step 3: Initialise q←n, S←0, k←0

Step 4: Check whether (q>0)

Step 5: Calculate q=q % 10,

           S=S+r* Pow (2,k), q=q/10, k++

Step 6: Print the value of s

Step 7: Stop

Flow Chart


Pseudocode

Set initial q=n, s=0, k=0

READ the binary value

WHILE (q>0)

       r = q mod 10

       s = s+r * Pow(2, k)

      q = q div 10

      k = k+1

ENDWHILE

Repeat while until the condition fail

WRITE the Result

 

Example 16: Write a program to convert the string into upper case.

Algorithm

Step 1: Start

Step 2: Enter the string

Step 3: Set a loop up to the null character

Step 4: Print the character of the string in the upper case using to upper function

Step 5: After the execution of the loop and the program

Step 6: Stop

Flow chart


Pseudocode

READ the string

WHILE (Str[i]! = '\0')

          WRITE to upper case

           i++

ENDWHILE

 

Example 17: Write a program to find the Greatest Common Division (GCD) of two given numbers.

Algorithm

Step 1: Start

Step 2: READ data into variable i,j

Step 3: Assign highest value to i and smallest to j

Step 4: If j equal to zero then i value is the GCD. Otherwise divide the i until j equal to zero

Step 5: Print the resulted value as GCD

Step 6: Stop

Flow chart


Pseudocode

Set initial i, j

READ the value for i, j

IF (j<i)

        k=i

        i=j

        j=k

ENDIF

ELSEIF (j==0)

        WRITE the GCD value

ELSE

         k = i % j

         i=j

         j=k

ENDIF

 

Example 18: Write a program to find minimum and maximum number from the list.

Algorithm

Step 1: Start

Step 2: READ the upper limit of the array 'n'

Step 3: READ an array a[] of 'n' numbers

Step 4: Assign first array value to

           MAX ← a[0] and MIN←a[1]

Step 5: FOR I = 2 to n

Step 6: if a[i] > MAX then MAX = a[i]

Step 7:  if a[i] < MIN then MIN = a[i]

Step 8: Repeat Step 5 to Step 7 until loop reached to 'n'

Step 9: Print MAX, MIN

Step 10: Stop

Flow chart


Pseudocode

Set initial i

READ n

READ an array a[] of 'n' numbers

Set MAX = a[0], MIN=a[1]

FOR i = 2 to n

        IF a[i] > MAX then MAX=a[i]

        IF a[i] < MIN then MIN=a[i]

end‒for

Print MAX, MIN

 

Computer Programming C: UNIT I: Introduction to C : Tag: Computer Science : C Programming - Problem Solving Through Algorithms, Flowcharts and Pseudocodes


Computer Programming C: UNIT I: Introduction to C



Under Subject


Computer Programming C

CS25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation



Related Subjects


English Essentials I

EN25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


தமிழர் மரபு - Heritage of Tamils

UC25H01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Applied Calculus

MA25C01 Maths 1 M1 - 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Applied Physics I

PH25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Applied Chemistry I

CY25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Makerspace

ME25C04 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Computer Programming C

CS25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Computer Programming Python

CS25C02 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Fundamentals of Electrical and Electronics Engineering

EE25C03 1st Semester EEE Depart | 2025 Regulation | 1st Semester 2025 Regulation


Introduction to Mechanical Engineering

ME25C03 1st Semester Mechanical Dept | 2025 Regulation | 1st Semester 2025 Regulation


Introduction to Civil Engineering

CE25C01 1st Semester Civil, Agri Departments | 2025 Regulation | 1st Semester 2025 Regulation


Essentials of Computing

CS25C03 1st Semester - AIDS, CSE, CSE(CY), IT Department | 2025 Regulation | 1st Semester 2025 Regulation


Applied Physics I Laboratory

PH25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Applied Chemistry I Laboratory

CY25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Computer Programming C Laboratory

CS25C01 1st Semester EEE, ECE, CSE, CSE(CY), AIDS, IT practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Computer Programming Python Laboratory

CS25C02 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Engineering Drawing

ME25C01 EEE, Mech, Agri, EEE Depts | 2025 Regulation | 2nd Semester 2025 Regulation


Basic Electronics and Electrical Engineering

EE25C04 1st Semester ECE Dept | 2025 Regulation | 1st Semester 2025 Regulation


Essentials of Computing - Laboratory

CS25C03 1st Semester AIDS, CSE, CSE(CY), IT Depts | practical Laboratory Manual | 2025 Regulation | 1st Semester 2025 Regulation