0% found this document useful (0 votes)
7 views4 pages

C++ Programming Basics: Functions & Logic

Some Program in c++

Uploaded by

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

C++ Programming Basics: Functions & Logic

Some Program in c++

Uploaded by

shibdasb4
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Computer Project

By Achirangshu Banerjee
1. #include<iostream> #include<cmath>

using namespace std;

int main()

double number, sqrtResult;

cout << "\nPlease Enter any Number to find Square root = "; cin >> number;

sqrtResult = sqrt(number);

cout << "\nThe Square root of " << number << " = " << sqrtResult;

long long x = 49; if


(sqrt(number)) cout
<< "\nYes"; else

cout << "\nNo";

return 0;

2. #include <iostream> using


namespace std;

int main()

int n, num, digit, rev = 0;

cout << "Enter a positive number: "; cin >>


num;

n = num;

do

digit = num % 10; rev =


(rev * 10) + digit;

num = num / 10;

}
while (num != 0);

cout << " The reverse of the number is: " << rev << endl;

if (n == rev and n > 0) // Negative numbers are not palindromic


cout << " The number is a palindrome.";
else

cout << " The number is not a palindrome.";

return 0;

3. #include <cmath>

#include <iostream>

using namespace std;

int main() {

int num, originalNum, remainder, n = 0, result = 0, power; cout <<


"Enter an integer: "; cin >> num;

originalNum = num;

while (originalNum != 0) {

originalNum /= 10;

++n;

originalNum = num;

while (originalNum != 0) {

remainder = originalNum % 10;

// pow() returns a double value // round()


returns the equivalent int power =
round(pow(remainder, n));

result += power;

originalNum /= 10;

if (result == num)

cout << num << " is an Armstrong number."; else

cout << num << " is not an Armstrong number."; return 0;

}
4. #include <iostream> using
namespace std;

int main() {

int num[10], a, sum = 0, greatest, least; double avg;

cout << "Enter 10 integer numbers:" << endl; for (a = 0; a <


10; a++) {

cin >> num[a];

cout << "List of elements: "; for


(a = 0; a < 10; a++) { cout <<
num[a] << "\t"; sum += num[a];

greatest = num[0]; least =


num[0];

for (int i = 1; i < 10; i++) { if


(num[i] > greatest) {

greatest = num[i];

if (num[i] < least) {

least = num[i];

avg = double(sum) / 10;

// Output the results cout << "\nSum is " << sum << endl;
cout << "Average is " << avg << endl; cout << "Greatest number
is " << greatest << endl;

cout << "Least number is " << least << endl;

return 0;

5. #include <iostream>

int main() {

int i, j;
for (i = 1; i <= 5; i++) { for (j
= 1; j <= i; j++) { if (j % 2 ==
0) std::cout << "#";
else

std::cout << "*";

std::cout << std::endl;

return 0;

You might also like