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

Basic Programming Concepts in C++

The document provides programming concepts in C++ focusing on arrays and functions. It includes examples of finding the minimum value in an array of five elements and a function to calculate the sum of two integers. Additionally, it explains the use of pointer variables and includes code snippets for better understanding.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Basic Programming Concepts in C++

The document provides programming concepts in C++ focusing on arrays and functions. It includes examples of finding the minimum value in an array of five elements and a function to calculate the sum of two integers. Additionally, it explains the use of pointer variables and includes code snippets for better understanding.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Programming Concepts

Instructor: Ms. Zainab Iftikhar


Arrays
• Write a C++ program to find minimum value from an array of 5
members.

• Syntax:
int a[5];
Solution
#include <iostream> min = input[0];
using namespace std; for(i = 0; i <= 4; i++){
int main(){ if(input[i] < min){
int input[4], i, min; min = input[i];
for(i = 0; i <= 4; i++){ }
cin >> input[i]; }
} cout << "Minimum Element\
n" << min;
}
Dry Run 2d Array

Output
Using a Pointer Variable
2000
int x;
12
x = 12;
x

3000
int* ptr;
2000
ptr = &x;
ptr

NOTE: Because ptr holds the address of x, we say that ptr


“points to” x
5
Types of Functions
Functions
• Write a C++ program to write a function named sum. Pass two integer
type values from main to function and return the sum of numbers in
main

• Function Declaration
• Function Definition
• Function Call
Solution
#include <iostream> int sum(int a,int b)
using namespace std; {
int sum(int a, int b);
int c;
int main()
{ c= a+b;
int x,y,z; return c;
cout<<"Enter value for x: "; }
cin>>x;
cout<<"Enter value for y: ";
cin>>y;
z = sum(x,y);
cout<<"Sum "<<z<<endl;
}

You might also like