0% found this document useful (0 votes)
10 views12 pages

Pppppppppppppppppppppprrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrraaaaaaaaaaaaaaaaaaacc

The document contains multiple C++ code snippets demonstrating various programming concepts such as variable declaration, pointers, dynamic memory allocation, arrays, functions, and control structures. Each snippet illustrates different functionalities including arithmetic operations, input/output operations, and memory management. The overall focus is on foundational programming techniques in C++.

Uploaded by

Srestho Saha
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)
10 views12 pages

Pppppppppppppppppppppprrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrraaaaaaaaaaaaaaaaaaacc

The document contains multiple C++ code snippets demonstrating various programming concepts such as variable declaration, pointers, dynamic memory allocation, arrays, functions, and control structures. Each snippet illustrates different functionalities including arithmetic operations, input/output operations, and memory management. The overall focus is on foundational programming techniques in C++.

Uploaded by

Srestho Saha
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/ 12

#include <iostream>

using namespace std;

int main()
{
int a=10;
double b = 5.7;

cout<<"a: "<<a<<endl;
cout<<"b: "<<b<<endl;

cout<<"&a: "<<&a<<endl;
cout<<"&b: "<<&b<<endl;

int *p1 = &a;


double *p2;
p2 = &b;

cout<<"p1: "<<p1<<endl;
cout<<"p2: "<<p2<<endl;
cout<<"*p1: "<<*p1<<endl;
cout<<"*p2: "<<*p2<<endl;
cout<<"&p1: "<<&p1<<endl;
cout<<"&p2: "<<&p2<<endl;

int c = a;//copy by value


c = 15;
cout<<"a: "<<a<<endl;
cout<<"c: "<<c<<endl;

*p1=20;// copy by reference


cout<<"a: "<<a<<endl;
cout<<"*p1: "<<*p1<<endl;

return 0;
}
------------------------------
#include <iostream>

using namespace std;

int main()
{
int a=10;
int b = 20;
const int *p = &a;
p = &b;

cout<<"&a: "<<&a<<endl;
cout<<"&b: "<<&b<<endl;
cout<<"p: "<<p<<endl;
cout<<"*p: "<<*p<<endl;

return 0;
}
_____________________
#include <iostream>
using namespace std;

int main()
{
int a = 45;
int b = 35;
const int *p = &a;
p = &b;

cout<<"*p: "<<*p<<endl;
//*p = 55;
cout<<"*p: "<<*p<<endl;

return 0;
}
________________________________
#include <iostream>

using namespace std;

int main()
{
int s;
cout<<"Enter array size: ";
cin>>s;//5

int *arr = new int[s];


for(int i = 0; i<s; i++)
{
arr[i] = i+2;
}
for(int i = 0; i<s; i++)
{
cout<<arr[i]<<endl;
}
delete[] arr;

int a = 10;
for(int i=0; i<a; i++)
{
cout<<i<<endl;
}
}
_________________________________________________
#include <iostream>

using namespace std;

int main()
{
int a = 5;
int *p = &a;

cout<<"a: "<<a<<endl;
cout<<"&a: "<<&a<<endl;
cout<<"p: "<<p<<endl;
cout<<"*p: "<<*p<<endl;

return 0;
}

__________________________
#include <iostream>

using namespace std;

int main()
{
int a = 5;
int b = a;//copy by value
b = 10;

cout<<"a: "<<a<<endl;
cout<<"b: "<<b<<endl;

int x = 10;
int *y = &x;
cout<<"x: "<<x<<endl;
cout<<"*y: "<<*y<<endl;
*y = 20;
cout<<"x: "<<x<<endl;
cout<<"*y: "<<*y<<endl;

return 0;
}
_____________________
#include <iostream>

using namespace std;

int main()
{
int a = 5;
int *p;
p = &a;
*p = 20;
cout<<"a: "<<a<<endl;
cout<<"&a: "<<&a<<endl;
cout<<"p: "<<p<<endl;
cout<<"*p: "<<*p<<endl;
cout<<"&p: "<<&p<<endl;
return 0;
}
_________________________
#include <iostream>

using namespace std;

int main()
{
int a = 5;
int b = 10;

const int *p = &a;


p = &b;
cout<<"a: "<<a<<endl;
cout<<"&a: "<<&a<<endl;
cout<<"b: "<<b<<endl;
cout<<"&b: "<<&b<<endl;
cout<<"p: "<<p<<endl;
cout<<"*p: "<<*p<<endl;
cout<<"&p: "<<&p<<endl;
return 0;
}
___________________________
#include <iostream>

using namespace std;

int main()
{
int *arr;
int s;
cout<<"Enter Array Size: ";
cin>>s;//5
//dynamic memory allocation
arr = new int[s];

for(int i =0; i<s; i++)


{
cout<<"Enter array elements for arr["<<i<<"]: ";
cin>>arr[i];
}
for(int i =0; i<s; i++)
{
cout<<"arr["<<i<<"]: "<<arr[i]<<endl;
}
//deallocation
delete[] arr;
return 0;
}
_________________________
#include <iostream>

using namespace std;

int main()
{
int arr [3][3];
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
cout << "Input Array["<<i<<"]["<< j <<"]: " ;
cin >> arr[i][j];
}
}
cout << "Numbers in array are: ";
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
cout << arr[i][j];
if (i==2 && j==2)
{
cout << ".";
break;
}
else
{
cout << ", ";
}
}
}
return 0;
}
_______________________________
int a = 10;
cout<< a <<endl;
cout<< &a <<endl;

int b = 30;
cout<< b <<endl;
cout<< &b <<endl;

int arr1d[4] = {10, 20, 30, 40};


cout<< arr1d[0]<<endl;
cout<<&arr1d[0]<<endl;

cout<< arr1d[1]<<endl;
cout<<&arr1d[1]<<endl;

cout<< arr1d[2]<<endl;
cout<<&arr1d[2]<<endl;

cout<< arr1d[3]<<endl;
cout<<&arr1d[3]<<endl;
____________________________________
#include <iostream>

using namespace std;

int main()
{

int days = 3;
int times = 3;

int arr[days][times];

for(int i = 0; i<days; i++)


{

for(int j = 0; j<times; j++)


{
cout<<"Enter temperature for day "<<i+1<< ", time slot "<<j+1<<" : ";
cin>>arr[i][j];
}
}
for(int i = 0; i<days; i++)
{
cout<<"Temperature for day "<<i+1<< " : ";
for(int j = 0; j<times; j++)
{

cout<<arr[i][j]<< " ";


}
cout<<endl;
}
for(int i = 0; i<days; i++)
{
cout<<"Sum of temperature for day "<<i+1<< " : ";
int sum = 0;
for(int j = 0; j<times; j++)
{
sum = sum + arr[i][j];
}
cout<<sum<<endl;
}
return 0;
}
________________________________________________
#include <iostream>

using namespace std;

int main()
{

int days = 3;
int times = 3;

int arr[days][times];

for(int i = 0; i<days; i++)


{

for(int j = 0; j<times; j++)


{
cout<<"Enter temperature for day "<<i+1<< ", time slot "<<j+1<<" : ";
cin>>arr[i][j];
}
}
for(int i = 0; i<days; i++)
{
cout<<"Temperature for day "<<i+1<< " : ";
for(int j = 0; j<times; j++)
{

cout<<arr[i][j]<< " ";


}
cout<<endl;
}
for(int i = 0; i<days; i++)
{
cout<<"Sum of temperature for day "<<i+1<< " : ";
int sum = 0;
for(int j = 0; j<times; j++)
{
sum = sum + arr[i][j];
}
cout<<sum<<endl;
}
return 0;
}
____________________________________________________________
int arr[3] = {10, 20, 30};

int *p = &arr[0];

cout<<*(p+1)<<endl;
________________________
#include <iostream>
using namespace std;

//return_type method_name(parameter) {}
void add(int a, int b)//formal parameter
{
cout<<"Addition: "<<a+b<<endl;
}
void subtraction(int a, int b)
{
cout<<"Subtraction: "<<a-b<<endl;
}
void multiplication(int a, int b)
{
cout<<"Multiplication: "<<a*b<<endl;
}
void division(int a, int b)
{
if(b!=0)
{
cout<<"Division: "<<(float)a/b<<endl;
}
else
{
cout<<"Math Error"<<endl;
}

}
void square(int a)
{
cout<<"Square: "<<a*a<<endl;
}
void checkEvenOdd(int a)
{
if(a%2 == 0)
{
cout<<"Even"<<endl;
}
else
{
cout<<"Odd"<<endl;
}
}

int main()
{
add(2,3);
subtraction(10, 8);
multiplication(2, 3);
division(10, 0);
add(15, 5);
subtraction(30, 7);
multiplication(3, 5);
division(15, 5);

square(5);
square(7);

checkEvenOdd(10);
checkEvenOdd(17);

return 0;
}

________________________________________
#include <iostream>
using namespace std;

//return_type method_name(parameter) {}
void add(int a, int b)//formal parameter
{
int r = a+b;
cout<<"Addition: "<<r<<endl;
}
void subtraction(int a, int b)
{
cout<<"Subtraction: "<<a-b<<endl;
}
void multiplication(int a, int b)
{
cout<<"Multiplication: "<<a*b<<endl;
}
void division(int a, int b)
{
if(b!=0)
{
cout<<"Division: "<<(float)a/b<<endl;
}
else
{
cout<<"Math Error"<<endl;
}

}
void square(float a)
{
cout<<"Square: "<<a*a<<endl;
}
void checkEvenOdd(int a)
{
if(a%2 == 0)
{
cout<<"Even"<<endl;
}
else
{
cout<<"Odd"<<endl;
}
}

float average(int a, int b, int c)


{
int s = a+b+c;
float r = (float) s/3;

return r;
}

int main()
{
add(2,3);
subtraction(10, 8);
multiplication(2, 3);
division(10, 0);

add(15, 5);
subtraction(30, 7);
multiplication(3, 5);
division(15, 5);

square(5);
square(7);

checkEvenOdd(10);
checkEvenOdd(17);

float avg = average(10, 4, 3);


cout<<"Average: "<<avg<<endl;
square(avg);

return 0;
}
____________________________________________________
#include <iostream>
using namespace std;

float average(float a, float b, float c)


{
return (a+b+c)/3;
}
int main()
{
float avg = average(67, 85, 80);
if(avg>=75)
{
cout<<"Eligible for scholarship"<<endl;
}
else
{
cout<<"Not eligible for scholarship"<<endl;
}
return 0;
}
_______________________________________________
#include <iostream>

using namespace std;


int sumseris(int x)
{
int sum=0;
for(int i=1;i<x;i++)
{
sum=sum+i;
}
return sum;
}
int main()
{

cout<<sumseris(15);

return 0;
}
__________________________
#include <iostream>

using namespace std;


void far(float c00)
{
float cel;
cel=(c00-32)*5/9;
cout<<cel;
}

int main()
{
float coo;
cout<< "enter a temperature to convert ";
cin>>coo;
far(coo);
}

___________
#include <iostream>

using namespace std;


int far(float c00)
{
float cel;
cel=(c00-32)*5/9;
return cel;
}

int main()
{
float coo;
cout<< "enter a temperature to convert ";
cin>>coo;
cout<<far(coo);

________________________________
#include <iostream>
using namespace std;
int aaa(int num[], int a)
{int sum=0;
for(int i=0;i<a;i++)
{
sum=sum+num[i];
}
int av1=sum/a;
return av1;
}

int main()
{

int a;
cout<< "koita mark dibi"<<endl;
cin>>a;
int num[a];
for(int i=0;i<a;i++)
{
cout<<"tumar heda"<<i<<endl;
cin>>num[i];
}
int avg =aaa(num,a);
cout<<avg;

}
#include<iostream>

using namespace std;

int main() {

int student, numsub;


cout << "total omanush ";
cin >> student;
cout << "total sub ";
cin >> numsub;

int grade[student][numsub];
cout << "jibon bedonamoy num: "<<endl;

for (int i = 0; i <student;i++)


{
cout << "Student " << i + 1 << endl;
for (int j = 0; j < numsub; j++)
{
cin >> grade[i][j];
}
}
cout << "total saffolo";
for (int i = 0; i < student; i++) {
int sum = 0;
for (int j = 0; j < numsub;j++) {
sum += grade[i][j];
}
float average = float(sum) / numsub;
cout << "Student " << i + 1 << ": " << average << endl;
}

return 0;
}

_______________________________
#include <iostream>
using namespace std;
int sums(int n)
{
int sum=0;
for(int i=1;i<=n;i++)
{
sum=sum+i;
}
return sum;
}
int main()
{
int n;
cout<< "koto porjonto khelben"<<endl;
cin>>n;
cout<<sums(n);

return 0;
}

You might also like