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

Assignment 1

Uploaded by

yjvhz2pf5y
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Assignment 1

Uploaded by

yjvhz2pf5y
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Assignment 1: Getting Started with C

Objective: Familiarize students with the basic setup and syntax of C programming.

Tasks:

1. Write a C program to print "Hello, World!" to the console.


2. Implement a program to calculate the sum of two numbers entered by the user.
3. Write a program to find the area of a rectangle given its length and width.

#include <stdio.h>

int main() {
printf("Hello, World!\n");
return 0;
}

This code works because it is a simple C program that utilizes the printf() function from
the standard input-output library ( stdio.h). Here's a breakdown of why it works:

1. #include <stdio.h>: This line includes the standard input-output library ( stdio.h) in the
program. This library provides functions like printf() for input and output
operations.
2. int main() { ... }: This is the main function of the program. In C, every program must
have a main() function, which serves as the entry point of the program. The int
before main() indicates that the function returns an integer value, typically 0 to
indicate successful execution.
3. printf("Hello, World!\n");: This line prints the string "Hello, World!" to the console.
The printf() function is used for formatted output. In this case, it takes a string
"Hello, World!\n" , where \n represents a newline character, causing the output to
appear on a new line.
4. return 0;: This statement exits the main() function and returns 0 to the operating
system, indicating that the program executed successfully. In C, returning 0 from
main() typically signifies that the program terminated without errors.

Overall, this code is a simple C program that prints "Hello, World!" to the console,
demonstrating a basic use of the printf() function for output and the main() function as
the entry point of the program.

You might also like