0% found this document useful (0 votes)
45 views7 pages

Codes

The document contains C++ code examples demonstrating the use of various programming concepts like loops, functions, arrays, and matrices. These include examples of for, while loops, if/else conditional statements, functions with and without parameters, passing arrays and matrices to functions, and performing operations on matrices.

Uploaded by

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

Codes

The document contains C++ code examples demonstrating the use of various programming concepts like loops, functions, arrays, and matrices. These include examples of for, while loops, if/else conditional statements, functions with and without parameters, passing arrays and matrices to functions, and performing operations on matrices.

Uploaded by

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

// Example program

#include <iostream>
#include <string>

using namespace std;


// factorial code
int main()
{
int i = 1, number;
int fac =1;
cout << "Enter the number";
cin >> number;

while (i <= number)


{
fac*=i;
i++;
}
cout << "the result is:" << endl;
cout << fac<< endl;
cout << endl;

return 0;
}

-----------------------------------------------------------------------------------
----------------------

// Example program
#include <iostream>
#include <string>

using namespace std;

int main()
{
for ( int i = 0 ; i < 5 ; i++)
cout << i << endl;

return 0;
}

-----------------------------

// Example program
#include <iostream>
#include <string>

using namespace std;


int main()
{
for ( int i =0 ; i < 31 ; i = 3+i ){
cout << i << endl;}

return 0;
}
----------------------

// Example program
#include <iostream>
#include <string>

using namespace std;


int main()
{
for ( int x =10 ; x >= 0 ; x-- ){
cout << x << endl;}

return 0;
}

------------------------------

// Example program
#include <iostream>
#include <string>

using namespace std;


int main()
{
for ( int i = 0; i < 20 ; i++) {
if (i == 5) {
continue;
}
cout << i << endl;
}

return 0;
}

-------------------------------------------------------------------------

// Example program
#include <iostream>
#include <string>

using namespace std;


int main()
{
int i = 0;
while ( i < 15 ){
cout << i << endl;
i++;
if (i == 5) {
break;
}
}
return 0;
}
------------------------------------------------------------

// Example program
#include <iostream>
#include <string>
using namespace std;
int main()
{
string lecture[4] = { "Phy" , "Math" , "His"};
cout << lecture[0];
return 0;
}

----------------------------------------------------

// Example program
#include <iostream>
#include <string>

using namespace std;


int main()
{
string lecture[4] = { "Phy" , "Math" , "His"};
lecture[1] = "Chem";
cout << lecture[1];
return 0;
}

----------------------------------------------------------

// Example program
#include <iostream>
#include <string>

using namespace std;


int main()
{
string lecture[4] = { "Phy" , "Math" ,"Chem", "His"};

for ( int i = 0 ; i < 4 ; i++) {


cout << lecture[i] << endl;
}

return 0;
}

-----------------------------------------------------------

// Example program
#include <iostream>
#include <string>

using namespace std;

void myFun () {
cout << " your code is working!";
};

int main()
{
myFun();
return 0;
}
-------------------------------------------------

// Example program
#include <iostream>
#include <string>

using namespace std;

void myFun (string Familyname) {


cout << Familyname << "Mahook\n";
};

int main()
{
myFun("Anas ");
myFun("Shahda ");
myFun("Bisher ");
myFun("Lujain ");
myFun("Ghaith ");
myFun("Sondos ");
return 0;
}

------------------------------------------------------------------------------

// Example program
#include <iostream>
#include <string>

using namespace std;

void myFun (string Familyname, int age) {


cout << Familyname << "Mahook" << age << " years old\n";
};

int main()
{
myFun("Anas ", 37);
myFun("Shahda ", 36);
myFun("Bisher ", 33);
myFun("Lujain ", 31);
myFun("Ghaith ", 21);
myFun("Sondos ", 19);
return 0;
}

------------------------------------------------------------------------------

// Example program
#include <iostream>
#include <string>

using namespace std;

int myfun (int x ) {

return x + 10;
}
int main()
{
cout << myfun(5);
return 0;
}
--------------------------------------------

// Example program
#include <iostream>
#include <string>

using namespace std;

int myfun (int x , int y) {

return x + y;
}

int main()
{
cout << myfun(5, 15 );
return 0;
}

-----------------------------------------------------------------------------------
---------------

// Example program
#include <iostream>
#include <string>

using namespace std;

int myfun (int x , int y) {

return x + y;
}

int main()
{
int z = myfun(5, 15 );
cout << z;
return 0;
}
--------------------------------------------------------------

// Example program
#include <iostream>
#include <string>

using namespace std;

void swapNum ( int &x, int &y) {

int z = x;
x=y;
y=z;
}
int main()
{
int firstnum = 10;
int secondnum = 20;

cout << "Before swap: " << endl;


cout << firstnum << secondnum << endl;

swapNum ( firstnum , secondnum);

cout << "after swap: " << endl;


cout << firstnum << secondnum << endl;
return 0;
}

-----------------------------------------------------------------------------------
----------

// Example program
#include <iostream>
#include <string>

using namespace std;

int main()
{
float cel, fah;
cout << "Celcius: ";
cin >> cel;
fah = cel * 9/5 + 32;
cout << "Fahrenheit: " << fah;

return 0;
}

-------------------------------------------------------------

// Example program
#include <iostream>
#include <string>

using namespace std;

int main()
{
int row , col, input;

cout << "Generated Matrix;\n-->row:";


cin >> row;

cout << "--> column: ";


cin >> col;

int matrix1 [row][col] = {};


int matrix2 [row][col] = {};
cout << "\n1. MATRIX\n";
for ( int i = 0 ; i < row , i ++) {
for ( int j = 0 ; j < col ; j ++ ) {
cout << i + 1 << ". row " << 1 + j << ". column: "
cin >> input ;
matrix1 [i][j] = input;
}
}

cout << " 1. matrix comp


cout << "\n2. MATRIX\n";
for ( int i = 0 ; i < row , i ++) {
for ( int j = 0 ; j < col ; j ++ ) {
cout << i + 1 << ". row " << 1 + j << ". column: "
cin >> input ;
matrix2 [i][j] = input;
}
}

for ( int k = 0 ; k < row ; k ++ ) {


for ( int t =0 ; t < col ; t ++ )

result [k][t] = matrix1[k][t] + matrix2[k][t];


}
}

cout << " result ; \n\n" ;


for ( int a = 0 ; a < row ; a++) {

}
return 0;
}

You might also like