0% found this document useful (0 votes)
26 views5 pages

Exercise 1 C Language

The document outlines exercises for programming in C, including algorithms and flowcharts to find the greatest of two and three integers, a 'Hello World' program, and a program using the scanf function for user input. Each exercise includes logic explanations and code snippets. The date of performance for these exercises is set for 29/08/2024.

Uploaded by

Aditya Singh
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)
26 views5 pages

Exercise 1 C Language

The document outlines exercises for programming in C, including algorithms and flowcharts to find the greatest of two and three integers, a 'Hello World' program, and a program using the scanf function for user input. Each exercise includes logic explanations and code snippets. The date of performance for these exercises is set for 29/08/2024.

Uploaded by

Aditya Singh
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/ 5

Programming in C Date of performance: 29/08/2024

Exercise 1

1. Draw a flowchart and write an algorithm to find out greatest of two integers.

ALGORITHMS:
 START
 Get values of a and b.
 Check if a is greater than b.
 If true, Print a as the greatest number.
 If false, Print b as the greatest number.
 STOP

FLOWCHART:

DY24SBBU0BID001 1
Programming in C Date of performance: 29/08/2024

Exercise 1
2. Draw a flowchart and write an algorithm to find out greatest of three integers

ALGORITHMS:
 START
 Get values of a, b and c.
 Check if a>b
 If Yes: Then check a>c
If yes: Then print a is greatest.
If no: Then check c>b: then print c is greatest.
 If No: then check b>c
If yes: Then print b is greatest.
If no: Then print c is greatest.
 STOP

FLOWCHART:

DY24SBBU0BID001 2
Programming in C Date of performance: 29/08/2024

Exercise 1
3. Write a “Hello World” program in C.
LOGIC:
 The #include <stdio> directive tells the compiler to include the Standard
Input/Output library, which contains functions for performing input and output
operations. In this program, it provides the printf function used for outputting text.
  The main function is the entry point of a C program. Execution starts here. The
function signature is int main(), indicating that it returns an integer value.
 Inside the main function, the printf function is used to print the string "Hello,
World!" to the console. The printf function is part of the C Standard Library and
is used for formatted output.
 The return 0; statement signals that the program has terminated successfully. By
convention, returning 0 indicates success, while other values indicate different types
of errors.

CODE:

Fig 3.1: “Hello World” code.

OUTPUT:

Fig 3.2: “Hello World” output.

DY24SBBU0BID001 3
Programming in C Date of performance: 29/08/2024

Exercise 1
4. Write a program to take input from user using scanf () function.
LOGIC:
 #include <stdio.h>: This line includes the Standard Input/Output library, which
provides functions for input and output operations. In this program, it allows the use
of printf and scanf.
 int main() { ... }: This is the entry point of the program. Execution begins here.
The int return type indicates that the function will return an integer value.
 int a;: This declares a variable a of type int to store the integer value that the user will
input.
 printf("enter an integer :");: This line outputs a prompt to the user, asking them to
enter an integer. printf is used to display formatted text to the console.
 scanf("%d", &a);: This line reads an integer value entered by the user and stores it
in the variable a. scanf is used for input, and %d specifies that the input is expected to
be an integer. The & operator is used to provide the address of the variable a where
the input will be stored.
 printf("You Entered %d\n", a);: This line outputs the value stored in a to the
console, preceded by the text "You Entered". The %d format specifier is used to
insert the integer value of a into the output string. The \n character moves the cursor
to the next line after printing.
 return 0;: This ends the main function and returns the value 0 to the operating
system, indicating that the program has completed successfully.
CODE:

Fig 4.1: “scanf” code.

OUTPUT:

Fig: “scanf” output.

DY24SBBU0BID001 4
Programming in C Date of performance: 29/08/2024

DY24SBBU0BID001 5

You might also like