Presentation is loading. Please wait.

Presentation is loading. Please wait.

D EVELOPING P ROGRAMS USING ALGORITHMS AND FLOW CHARTS AND VICE VERSA Week 14 Mr.Mohammed Rahmath.

Similar presentations


Presentation on theme: "D EVELOPING P ROGRAMS USING ALGORITHMS AND FLOW CHARTS AND VICE VERSA Week 14 Mr.Mohammed Rahmath."— Presentation transcript:

1 D EVELOPING P ROGRAMS USING ALGORITHMS AND FLOW CHARTS AND VICE VERSA Week 14 Mr.Mohammed Rahmath

2 F LOW 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.Mohammed Rahmath

3 S YMBOLS FOR F LOW CHART Mr.Mohammed Rahmath

4 AlgorithmFlow chart Mr.Mohammed Rahmath 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?

5 AlgorithmFlow chart Mr.Mohammed Rahmath 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.

6 AlgorithmFlow chart Mr.Mohammed Rahmath 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.

7 AlgorithmFlow chart Mr.Mohammed Rahmath 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.

8 C L ANGUAGE 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.Mohammed Rahmath

9 E XECUTION P ROCESS FOR C LANGUAGE PROGRAM Mr.Mohammed Rahmath

10 S TEPS TO WRITE BASIC C LANGUAGE PROGRAM AND EXECUTE USING B LOODSHED 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.Mohammed Rahmath

11 S CREEN SHOT ( DEV C ++) Mr.Mohammed Rahmath

12 C PROGRAMS Q) Write a c program for addition of two numbers. #include 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.Mohammed Rahmath

13 C PROGRAM TO CHECK ODD OR EVEN USING MODULUS OPERATOR #include 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.Mohammed Rahmath

14 P ALINDROME NUMBER ALGORITHM #include 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.Mohammed Rahmath

15 S ESSION 14 E ND Mr.Mohammed Rahmath


Download ppt "D EVELOPING P ROGRAMS USING ALGORITHMS AND FLOW CHARTS AND VICE VERSA Week 14 Mr.Mohammed Rahmath."

Similar presentations


Ads by Google