0% found this document useful (0 votes)
8 views

C Language Homework Tasks

Uploaded by

Kalindu Liyanage
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

C Language Homework Tasks

Uploaded by

Kalindu Liyanage
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

C Language Basics - Homework Tasks

• In this homework, you are required to complete 10 tasks in the C language. Each
task involves writing a C program. The variables are predefined, so there is no need
to take input from the user.
• You should define any variables at the top of the program. After completing each
task, save the C code and sample output as one PDF and submit it. Make sure the
code is saved as text with a sample output for each task.

Task 1: Hollow Square Pattern


Write a C program to print a hollow square pattern where the side length is predefined.
Define the side length as a variable at the top of the code.

Example:
Side length = 5
Output:
*****
* *
* *
* *
*****

Task 2: Pascal’s Triangle


Write a C program to print Pascal’s Triangle up to a predefined number of rows.
Define the number of rows as a variable at the top of the code.

Example:
Rows = 5
Output:
1
11
121
1331
14641
Task 3: Hollow Right-Angled Triangle
Write a C program to print a hollow right-angled triangle pattern.
Define the side length as a variable at the top of the code.

Example:
Side length = 5
Output:
*
**
* *
* *
*****

Task 4: Pyramid of Numbers


Write a C program to print a pyramid of numbers where the number increases in each row.
Define the height of the pyramid as a variable at the top of the code.

Example:
Height = 4
Output:
1
23
456
7 8 9 10

Task 5: Zigzag Pattern


Write a C program to print a zigzag pattern of stars.
Define the number of rows as a variable at the top of the code.

Example:
Rows = 3
Output:
* * *
* * * *
* *
Task 6: Hollow Diamond Pattern
Write a C program to print a hollow diamond pattern.
Define the side length of the diamond as a variable at the top of the code.

Example:
Side length = 5
Output:
*
**
* *
* *
* *
* *
* *
**
*

Task 7: Prime Numbers in a Range


Write a C program to print all prime numbers between 1 and 100.
Define the range as a variable at the top of the code.

Example:
Start = 1, End = 100
Output:
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97

Task 8: Number Palindrome Checker


Write a C program to check if a predefined number is a palindrome.
Define the number at the top of the code.

Example:
Number = 121
Output:
121 is a palindrome.
Task 9: Armstrong Number Checker
Write a C program to check if a predefined number is an Armstrong number.
Define the number at the top of the code.
153 = 13+53+33
Example:
Number = 153
Output:
153 is an Armstrong number.

Task 10: Collatz Conjecture


Write a C program to simulate the Collatz Conjecture.
It concerns sequences of integers in which each term is obtained from the previous term as
follows: if the previous term is even, the next term is one-half of the last term. If the
previous term is odd, the next term is 3 times the previous term plus 1.

Define the starting number at the top of the code.

Example:
Starting Number = 6
Output:
6 → 3 → 10 → 5 → 16 → 8 → 4 → 2 → 1
Number of steps: 8

You might also like