Programming In C++ Spring Semester 2013 Practice 2 Programming In C++, Practice By Umer Rana.

Slides:



Advertisements
Similar presentations
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Advertisements

© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 5: Repetition and Loop Statements Problem Solving & Program.
Chapter 7: Arrays In this chapter, you will learn about
Discrete Maths Objective to describe the Big-Oh notation for estimating the running time of programs , Semester 2, Running Time of.
Singly Linked List BTECH, EE KAZIRANGA UNIVERSITY.
Computer Programming for Engineering Applications ECE 175 Intro to Programming.
1 Structures. 2 Structure Basics A structure is a collection of data values, called data members, that form a single unit. Unlike arrays, the data members.
Structures Often we want to be able to manipulate logical entities as a whole For example, complex numbers, dates, student records, etc Each of these must.
Program Looping EE2372 Software Design I Dr. Gerardo Rosiles.
Copyright 2008 by Pearson Education 1 Nested loops reading: 2.3 self-check: exercises: videos: Ch. 2 #4.
1 Chapter Eleven Arrays. 2 A Motivating Example main( ) { int n0, n1, n2, n3, n4; scanf(“%d”, &n0); scanf(“%d”, &n1); scanf(“%d”, &n2); scanf(“%d”, &n3);
Recursion Prog #include <stdio.h> #include<conio.h> main()
Programming In C++ Spring Semester 2013 Practice 1-3 Lectures Programming In C++, Lecture 3 By Umer Rana.
Programming In C++ Spring Semester 2013 Lecture 11 Programming In C++, Lecture 11 By Umer Rana.
Programming In C++ Spring Semester 2013 Lecture 3 Programming In C++, Lecture 3 By Umer Rana.
Data Structure Lecture-3 Prepared by: Shipra Shukla Assistant Professor Kaziranga University.
Programming In C++ Spring Semester 2013 Lecture 6 Programming In C++, Lecture 6 By Umer Rana.
Spring Semester 2013 Lecture 5
Programming In C++ Spring Semester 2013 Lecture 4 Programming In C++, Lecture 3 By Umer Rana.
Pointers and Arrays Chapter 12
Two-Dimensional Arrays Chapter What is a two-dimensional array? A two-dimensional array has “rows” and “columns,” and can be thought of as a series.
CS1010 Programming Methodology
Programming In C++ Spring Semester 2013 Lecture 13 Programming In C++, Lecture 13 By Umer Rana.
COMPSCI 210 Semester Tutorial 10 Exercises from CH 14.
Call By Address Parameters (Pointers) Chapter 5. Functions that “return” more than a single value What if we need more than one value to be returned from.
Representing an algorithm using Flowcharts
Chapter 6 Advanced Function Features Pass by Value Pass by Reference Const parameters Overloaded functions.
Arrays and Strings.
Single Variable and a Lot of Variables The declaration int k; float f; reserve one single integer variable called k and one single floating point variable.
Array_strcpy void array_strcpy(char dest[], char src[]) { int i = 0; while (src[i] != '\0') { dest[i] = src[i]; i++; } dest[i] = '\0'; }
Week 8 Arrays Part 2 String & Pointer
Sort the given string, without using string handling functions.
Programming In C++ Spring Semester 2013 Lecture 8 Programming In C++, Lecture 8 By Umer Rana.
 2007 Pearson Education, Inc. All rights reserved. Structs as Function Arguments and Results  Arrays – Pass by referance  Struts – the same way as the.
By Senem Kumova Metin 1 POINTERS + ARRAYS + STRINGS REVIEW.
Nested Loops. Problem Print The only printfs you can use are: –printf(“*”); –printf(“\n”); *****
Insertion Sorting Lecture 21. Insertion Sort Start from element 2 of list location 1 –In first iteration: Compare element 1 with all of its elements to.
- SEARCHING - SORTING.  Given:  The array  The search target: the array element value we are looking for  Algorithm:  Start with the initial array.
+ ARRAYS - SEARCHING - SORTING Dr. Soha S. Zaghloul updated by Rasha M. AL_Eidan 2015.
Repetitive Structures BBS514 Structured Programming (Yapısal Programlama)1.
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
Nested LOOPS.
Function Problems. Write Functions Asks users whether the user wants to continue of not, then returns the answer. Takes two integers and returns 1 if.
ECE 103 Engineering Programming Chapter 24 Sorting Herbert G. Mayer, PSU CS Status 6/2/2015 Initial content copied verbatim from ECE 103 material developed.
CSCI 171 Presentation 5. The while loop Executes a block as long as the condition is true general form: while (condition) { statement 1; statement 2;
Lecture 4 Function example. Example1 int max (int a, int b) { int c; if (a > b) c = a; else c = b; return (c); } void main ( ) {int x, y; cin>>x>>y; cout.
Computer Programming for Engineers
Print Row Function void PrintRow(float x[ ][4],int i) { int j; for(j=0;j
CS 162 Intro to Programming II Sorting Introduction & Selection Sort 1.
CS 161 Introduction to Programming and Problem Solving Chapter 17 Nested Loops Herbert G. Mayer, PSU Status 9/8/2014 Initial content copied verbatim from.
COMP 110: Spring Announcements Lab 7 was due today Binary Expression Assignment due Friday.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
Arrays. Example Write a program to keep track of all students’ scores on quiz 1. Need a list of everyone’s score Declare 14 double variables? What about.
EXAMPLE. Dr. Soha S. Zaghloul2 Write a complete program that searches for all the elements that are multiple of 7 in array X of type int and size 100.
Announcements. Practice questions, with and without solutions will be uploaded by Friday 5 th November, make sure to check them before the weekend \\netstorage\Subjects\ITCA-b\Exam.
Beginning C for Engineers Fall 2005 Arrays, 2-D arrays, character strings Bettina Schimanski Lecture 5: Section 2 (9/28/05) Section 4 (9/29/05)
REEM ALAMER REVISION FOR C LANGUAGE COURSE. OUTPUTS int main (void) { int C1, C2; int *p1, *p2; C1 = 8; p1 = &C1; C2 = *p1 / 2 + 5; p2 = &C2; printf ("C1.
Lesson #5 Repetition and Loops.
Lesson #5 Repetition and Loops.
The nested repetition control structures & Continue Statements
Chapter 2.2 Control Structures (Iteration)
Looping.
Lesson #5 Repetition and Loops.
Lec 7.
CSE 1342 Programming Concepts
Chapter 2.2 Control Structures (Iteration)
Week 6 CPS125.
ECE 103 Engineering Programming Chapter 19 Nested Loops
Lesson #5 Repetition and Loops.
Visit for more Learning Resources
Presentation transcript:

Programming In C++ Spring Semester 2013 Practice 2 Programming In C++, Practice By Umer Rana

Practice-1 n Write down a program to return sum of square of two numbers entered by the user with the help of a function. Programming In C++, Practice By Umer Rana

Practice-1 #include int sqSum(int,int); int main(void) { int num1,num2,Ans; printf("First Number is "); scanf("%d",&num1); printf("\n2nd Number is "); scanf("%d",&num2); Ans=sqSum(num1,num2); printf("\nSum of the Square of two Numbers is %d",Ans); getch(); } int sqSum(int p,int q) { p=p*p; q=q*q; return p+q; } Programming In C++, Practice By Umer Rana

Practice-2 n Write nested loop with help of program? Programming In C++, Practice By Umer Rana

Practice-2 Programming In C++, Practice By Umer Rana # include Void main () { int inner, outer; for(outer=7; outer=>1;outer--) { inner=1; while(inner<+outer) { printf(“*”); inner++ } printf(“\n”); } getche(); }

Practice-3 n Write down a program using if-else-if statement to find the age group of a student. Programming In C++, Practice By Umer Rana Group Age A B C D31 and Greater

Practice-3 int main(void) { int Age; printf("Please Enter the Age of the Student"); scanf("%d",&Age); if (Age>=18 && Age<=21) printf("You are in Age Group A"); else if (Age>=22 && Age<=25) printf("You are in Age Group B"); else if (Age>=26 && Age<=30) printf("You are in Age Group C"); else if (Age>=31) printf("You are in Age Group D"); getch(); } Programming In C++, Practice By Umer Rana

Practice-4 n Define an array of ten elements to accept a series of numbers from user and then print in descending order. Programming In C++, Practice By Umer Rana

Practice-4 Programming In C++, Practice By Umer Rana { int i,j,temp,a[10]; printf ("Enter the numbers \n"); for (i=0; i<10; ++i) scanf ("%d",&a[i]); for (i=0; i<10; ++i) { for (j=i+1; j<10; ++j) { if (a[i] < a[j]) { temp = a[i]; a[i] = a[j]; a[j] = temp; } printf (“Descending order are given below\n"); for (i=0; i<10; ++i) printf ("%d\n",a[i]); getche(); }

Practice-5 n Write down a program using if-else-if statement to calculate two values enter by user and apply chosen function as ( +, -, *, / ). Programming In C++, Practice By Umer Rana

Practice-5 int num1,num2,Ans; char ope; printf("Please Enter the two number to operate\n"); scanf("%d",&num1); scanf("%d",&num2); printf("\n Please Choose the Function Please (+,-,*,/)\n"); ope=getche(); if(ope=='-') printf("\nSubtraction of two numbers are %d",num1-num2); else if(ope=='+') printf("\nSum of two numbers are %d",num1+num2); else if(ope=='*') printf("\n Multiply of two numbers are %d",num1*num2); else if(ope=='/') printf("\n Division of two numbers are %d",num1/num2); getche(); Programming In C++, Practice By Umer Rana

Practice-6 n Write a program that will print asterisks (*) according to the pattern shown in: ********* Programming In C++, Practice By Umer Rana

Practice-6 int main() { for ( int i=0; i<5; i++) { for (int j=0; j<=8; j++) printf("*"); printf("\n"); } getch(); } Programming In C++, Practice By Umer Rana

Practice-7 n Write a program that will print asterisks (*) according to the pattern shown in: * ** *** **** ***** **** *** ** * Programming In C++, Practice By Umer Rana

Practice-7 Void main () { for ( int i=0; i<5; i++) { for (int j=0; j<=i; j++) printf("*"); printf("\n"); } for ( int i=0; i<5; i++) { for (int j=4; j>=i; j--) printf("*"); printf("\n"); } getch(); } Programming In C++, Practice By Umer Rana