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

Using Namespace Int Char Int Int

The document contains code for two C++ programs. The first program checks if a string is a palindrome by comparing the first and last characters, then moving inward, until a mismatch is found or the whole string is checked. The second program checks if a number is perfect by adding all its factors and comparing the sum to the original number.
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)
14 views

Using Namespace Int Char Int Int

The document contains code for two C++ programs. The first program checks if a string is a palindrome by comparing the first and last characters, then moving inward, until a mismatch is found or the whole string is checked. The second program checks if a number is perfect by adding all its factors and comparing the sum to the original number.
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
You are on page 1/ 1

?

PAlimdrome program
#include <iostream>
using namespace std;

int main(){
char string1[20];
int i, length;
int flag = 0;

cout << "Enter a string: "; cin >> string1;

length = strlen(string1);

for(i=0;i < length ;i++){


if(string1[i] != string1[length-i-1]){
flag = 1;
break;
}
}

if (flag) {
cout << string1 << " is not a palindrome" << endl;
}
else {
cout << string1 << " is a palindrome" << endl;
}
system("pause");
return 0;
}

?* Perfect number

#include <iostream>
#include <cctype>
using namespace std;

int main(){
int n,i=1,sum=0;
cout << "Enter a number: ";
cin >> n;
while(i<n){
if(n%i==0)
sum=sum+i;
i++;
}

if(sum==n)
cout << i << " is a perfect number\n";
else
cout << i << " is not a perfect number\n";
system("pause");

return 0;
}

You might also like