d eveloping p rograms using algorithms and flow charts and vice versa week 14 mr.mohammed rahmath

15
DEVELOPING PROGRAMS USING ALGORITHMS AND FLOW CHARTS AND VICE VERSA Week 14 M r . M o h a m m e d R a h m a t h

Upload: edward-tate

Post on 19-Dec-2015

219 views

Category:

Documents


0 download

TRANSCRIPT

DEVELOPING PROGRAMS USING ALGORITHMS AND FLOW CHARTS AND VICE VERSA

Week 14

Mr.M

oh

am

me

d R

ah

ma

th

FLOW CHART

A flowchart is a type of diagram that represents an algorithm or process, showing the steps as boxes of various kinds, and their order by connecting them with arrows. This diagrammatic representation solution to a given problem.

Mr.M

oh

am

me

d R

ah

ma

th

SYMBOLS FOR FLOW CHART

Mr.M

oh

am

me

d R

ah

ma

th

Algorithm Flow chartM

r.Mo

ha

mm

ed

Ra

hm

ath

•step 1 : start•step 2 : input number•step 3 : rem=number mod 2•step 4 : if rem=0 then     print "number even“         else               print "number odd"           endif•step 5 : stop

to be done by student

Q) find out number is odd or even?

Algorithm Flow chartM

r.Mo

ha

mm

ed

Ra

hm

ath

Step 1: Start Step 2: Declare variables num1, num2 and sum. Step 3: Read values num1 and num2. Step 4: Add num1 and num2 and assign the result to sum. sum←num1+num2 Step 5: Display sum Step 6: Stop

to be done by student

Q) add two numbers entered by user.

Algorithm Flow chartM

r.Mo

ha

mm

ed

Ra

hm

ath

•Step 1: Start •Step 2: Declare variables n,i,flag. •Step 3: Initialize variables flag←1 i←2 •Step 4: Read n from user. •Step 5: Repeat the steps until i<(n/2) 5.1 If remainder of n÷i equals 0 flag←0 Go to step 6 5.2 i←i+1 •Step 6: If flag=0 Display n is not prime else Display n is prime •Step 7: Stop

to be done by student

Q)check whether a number entered by user is prime or not.

Algorithm Flow chartM

r.Mo

ha

mm

ed

Ra

hm

ath

Step 1: Start Step 2: Declare variables a,b and c. Step 3: Read variables a,b and c. Step 4: If a>b If a>c Display a is the largest number. Else Display c is the largest number. Else If b>c Display b is the largest number. Else Display c is the greatest number. Step 5: Stop

to be done by student

Q) find the largest among three different numbers entered by user.

C LANGUAGE

• The C programming language was designed by Dennis Ritchie at Bell Laboratories in the early 1970s

• A “C” development environment includes – System libraries and headers: a set of

standard libraries and their header files. For example see /usr/include and glibc.

– Application Source: application source and header files

– Compiler: converts source to object code for a specific platform

– Linker: resolves external references and produces the executable module

Mr.M

oh

am

me

d R

ah

ma

th

EXECUTION PROCESS FOR C LANGUAGE PROGRAM

Mr.M

oh

am

me

d R

ah

ma

th

STEPS TO WRITE BASIC C LANGUAGE PROGRAM AND EXECUTE USING BLOODSHED C++ EDITOR

• Click start• Click all programs• Click bloodshed c++ editor• Click file• Select new• Write c language code/program• Save program/code• compile program using ctrl + f9 key and

execute using ctrl + f10 key.

Mr.M

oh

am

me

d R

ah

ma

th

SCREEN SHOT(DEV C++)

Mr.M

oh

am

me

d R

ah

ma

th

C PROGRAMSQ) Write a c program for addition of two numbers.

#include<stdio.h>   int main() { int a, b, c;   printf("Enter two numbers to add\n");

scanf("%d%d",&a,&b);   c = a + b;   printf("Sum of entered numbers = %d\n",c);   return 0; }

Mr.M

oh

am

me

d R

ah

ma

th

C PROGRAM TO CHECK ODD OR EVEN USING MODULUS OPERATOR#include<stdio.h>   main() { int n;   printf("Enter an integer\n"); scanf("%d",&n);   if ( n%2 == 0 ) printf("Even\n"); else printf("Odd\n");   return 0; }

Mr.M

oh

am

me

d R

ah

ma

th

PALINDROME NUMBER ALGORITHM#include <stdio.h>  

int main() {

int n, reverse = 0, temp;

  printf("Enter a number to check if it is a palindrome or not\n");

scanf("%d",&n);  

temp = n;  

while( temp != 0 ) {

reverse = reverse * 10;

reverse = reverse + temp%10;

temp = temp/10;

}  

if ( n == reverse )

printf("%d is a palindrome number.\n", n);

Else

printf("%d is not a palindrome number.\n", n);

  return 0;

}

Mr.M

oh

am

me

d R

ah

ma

th

SESSION 14 END

Mr.M

oh

am

me

d R

ah

ma

th