Learn C++ beginer programs

July 8, 2009

write a program to check whether entered number is palindrome or not

Filed under: cin,cout,else if,if,if else,loop,numbers,while loop — snehilkhanor @ 12:33 pm
Palindrome :A word or phrase that reads the same backward as forward
A number is taken from user and then checks if the entered number is palindrome or not.

Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. long int n,rev=0,m,num;
  7. cout<<”please enter a five digit no.: “;
  8. cin>>n;
  9. num=n;
  10. while(n>0)
  11. {
  12. m=n%10;
  13. rev=rev*10+m;
  14. n=n/10;
  15. }
  16. cout<<rev<<endl;
  17. if (num==rev)
  18. cout<<”Number is a palindrome”;
  19. else
  20. cout<<”Not a palindrome”;
  21. getch();
  22. }

write a program to reverse digits of a number

Filed under: cin,cout,loop,while loop — snehilkhanor @ 12:18 pm
A number is taken from the user number with reverse digits is displayed

Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. long int n,rev=0,m;
  7. cout<<”please enter a five digit no.: “;
  8. cin>>n;
  9. while(n>0)
  10. {
  11. m=n%10;
  12. rev=rev*10+m;
  13. n=n/10;
  14. }
  15. cout<<rev;
  16. getch();
  17. }

write a program to find sum of digits of a number

Filed under: cin,cout,loop,while loop — snehilkhanor @ 12:16 pm
A number is taken from user and the sum of the digits is displayed.
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int n,sum=0,m;
  7. cout<<”please enter a five digit no.: “;
  8. cin>>n;
  9. while(n>0)
  10. {
  11. m=n%10;
  12. sum=sum+m;
  13. n=n/10;
  14. }
  15. cout<<sum;
  16. getch();
  17. }

Theme: Rubric. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.