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

Basic of C Programming Lab

Uploaded by

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

Basic of C Programming Lab

Uploaded by

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

 ALGORITHM

 FLOWCHART
Definition of Algorithm – a finite number of step-by-step
procedures to solve a given problem is called algorithm.

3 important control structure


1. Sequence- default mode. Sequential execution of code
statements (one line after another).
2. Conditional(branching)/selection- used for decision,
branching choosing b/w 2 or more alternative paths. E.g.
if statement, else, switch.
3. Iterative(looping/repetitive)- used for looping, i.e.
repeating a piece of code multiple times in a row. E.g.
while,do/while,for.

Flowchart
Graphical or pictorial representation of an algorithm is called
flowchart.
Consist set of predefined symbols
Sl.no Symbol Name function

1 Oval Start/stop

2 Parallelogram Input/output

3 Rhombus/diamo Condition
nd

4 Rectangle Processing/computati
on

5 Hexagon Looping/iteration

6 Circle continuation
a

7 Arrow Flow of
direction/control

8 Predefined Subroutine/function
process

9 Document Function
document/report
C program to add two numbers with algorithm, flowchart

Algorithm
Step1 – start
Step2 – declare a, b, sum
Step3 – read a & b
Step4 – sum= a+b
Step5 – display sum
Step6 – stop
Flowchart

start

Declare variable a,
b,sum

Read a & b

Add a,b and assign


value to sum=a+b

Print sum
stop

#include<stdio.h>
int main()
{
int a, b, sum;
printf(“add two integer \n”);
scanf(“ %d %d”,&a,&b);
sum= a+b;
printf(“the sum value is %d”,sum);
return 0;
}

To create a directory – mkdir Name(Ranjitha)


To open ur current directory – cd Name(Ranjitha)
Create a new file – gedit filename3.c
To compile a program – cc filename3.c
To execute a program - ./a.out
1. Write an algorithm and design the flowchart for the C
program performing the following operations like addition,
subtraction, multiplication, division and Modulo. Display
the appropriate messages with output.

Algorithm
Flowchart
Program
int a,b,c,sum;
Printf(“add three integer”);
Scanf(“%d %d %d”,&a,&b,&c);
Sum=a+b+c;
Printf(“display the sum value %d”,sum);

Write an algorithm and design the flowchart for the C program


to find the Simple interest and Compound Interest.

Simple interest = (p*t*r)/100


Compound interest = p*((1+r/100)^t -1)
Lab Program-1 – Develop a program to solve simple computational
problems using arithmetic expressions and use of each operator
leading to simulation of a Commercial calculator.
#include <stdio.h>

int main()

int num1,num2;

float result;

char choice; //to store operator choice

printf("Enter first number: ");

scanf("%d",&num1);

printf("Enter second number: ");

scanf("%d",&num2);

printf("Choose operation to perform (+,-,*,/,%): ");

scanf(" %c",&choice);

result=0;

switch(choice)

case '+':

result=num1+num2;

break;

case '-':

result=num1-num2;

break;

case '*':
result=num1*num2;

break;

case '/':

result=(float)num1/(float)num2;

break;

case '%':

result=num1%num2;

break;

default:

printf("Invalid operation.\n");

Printf("Result: %d %c %d =%f\n",num1,choice,num2,result);
return 0;

You might also like