Learning C++

free web hosting
Free Web Hosting > Computers & Tech > How-To's and Tutorials > Programming > C and C++

Learning C++

abdo
CODE
// Program to check whether the given string is palindrome or not
  using library functions

#include<iostream.h>
#include<string.h>
int main()
{
     char str[80],temp[80];
     cout<<"Enter string to check \n";
     cin>>str;
     strcpy(temp,str);
     strrev(temp);
     if(strcmp(str,temp)==0)
          cout<<"\n Given string is palindrome";
     else
          cout<<"\n Given string is not palindrome";
     return 0;
}


Test data 1

Enter string to check
madam

Output
Given string is palindrome


Test data 2

Enter string to check
master

Output
Given string is not palindrome


// program to check whether the string is palindrome or not
If not make it a palindrome by adding to its end

#include<iostream.h>
int main()
{
char str[80],temp[80];
int i=0,n=0,flag;
cout<<"Enter string to check \n ";
cin>>str;
while(str[i]!='\')
{
++n;
++i;
}

for(i=0;i<n/2;i++)
{
if(str[i]!=str[n-i-1])
{
flag=0;
break;
}
else flag =1;
}

if(flag==1)
cout<<"\n Given string is palindrome";
else
{
for(i=0;i<n-1;i++)
str[n+i]=str[n-i-2];
str[n+i]='\';
cout<<"\n Given string is converted to palindrome";
cout<<str;
}
return 0;
}



Test data 1

Enter string to check
madam

output
Given string is palindrome

Test data 2

Enter string to check
mouse

Output
Given string is converted to palindrome
mousesuom

// Program to find whether a given number is palindrome or not
If not make it palindrome by adding to its end


#include <iostream.h>

int main(void)
{
long n,i,j,sum=0;
cout<<"Enter any number \n";
cin>>n;
j=n;
while(j)
{
sum =sum*10+j%10;
j /=10;
}

if(sum==n)
cout<<"\n palindrome";
else
{
i=n;
n/=10;
while(n)
{

i= i*10+n%10;
n /=10;
}
cout<<"\n new palindrome"<<i;
}
return 0;
}



Test data 1

Enter any number
121
Output
palindrome

Test data 2

Enter any number
123
Output
new palindrome 12321

// Program to find the maximum sum of consecutive positive integers

#include <iostream.h>
#include<conio.h>
int main()
{
int a[50];
int i,n;
int sum=0,maxsum=0;
clrscr();
cout<<"Enter how many numbers \n";
cin>>n;
for(i=0;i<n;i++)
cin >> a[i];
for(i=0;i<n;i++)
{

if(a[i]> 0)
sum = sum + a[i];
if(sum>maxsum)
maxsum=sum;
if(a[i]<0)
sum=0;
}
cout<<maxsum;
return 0;
}


Test data

Enter how many numbers
12
-5 1 2 3 -7 4 6 -1 1 1 1 1

Output
10

// Program to sort given names

#include<iostream.h>
#include<string.h>
#include<conio.h>

int main()
{
char name[5][20],temp[20];
int i,j;
clrscr();
cout<<"Enter 5 names \n";
for(i=0;i<5;i++)
cin>>name[i];
for(i=0;i<4;i++)
{
for(j=i+1;j<5;j++)
{
if(strcmp(name[i],name[j])>0)
{
strcpy(temp,name[i]);
strcpy(name[i],name[j]);
strcpy(name[j],temp);
}
}
}
cout<<"The sorted names are \n";
for(i=0;i<5;i++)
cout<<name[i]<<"\n";
return 0 ;
}


Test data


Enter 5 names
java
oracle
cplusplus
perl
cobol


Output

The sorted names are
cobol
cplusplus
java
oracle
perl

// Program to convert binary to decimal

#include<iostream.h>
#include<math.h>
int main()
{

int m,i=0,sum=0,a[16],j,x=0;
long no;

cout<<"Enter Binary number:";
cin>>no;
while(no>0)
{
m=no%10;
a[i]=m;
++i;
no=no/10;
}
for(j=0;j<i;j++)
{

sum=sum+a[j] * pow(2,x);
++x;
}
cout<<"\n Decimal number : "<<sum;
return 0 ;

}


Test data

Enter Binary number : 100011

Output
Decimal number : 35

// Example program for call by reference


#include<iostream.h>
void change(int &,int &);
int main()
{
int a,b;
cout<<"Enter values for a and b \n";
cin>>a>>b;
change(a,cool.gif;
cout<<"\n The values of a and b after executing the function :";
cout<<a<<" "<<b;
return 0 ;
}


void change(int & c, int & d)
{

c=c*10;
d=d+8;
cout<<"The values of a and b inside the function :"<<c<<" "<<d;
}


Test data

Enter values for and b
2 3
The values of a and b inside the function : 20 11
The values of a and b after executing the function : 20 11

// Example program for call by value


#include<iostream.h>
void change(int,int);
int main()
{
int a,b;
cout<<"Enter values for a and b \n";
cin>>a>>b;
change(a,cool.gif;
cout<<"\n The values of a and b after executing the function :";
cout<<a<<" "<<b;
return 0 ;
}


void change(int c, int d)
{

c=c*10;
d=d+8;
cout<<"\n The values of a and b inside the function : "<<c<<" "<<d;
}


Test data

Enter values for a and b
2 3

Output
The values of a and b inside the function : 20 11
The values of a and b after executing the function : 2 3

 

 

 


Reply

yordan
Please use the "code" and "/code" tags to delimit the portions of code inside your post.
I did it for the first portion of code. Please look how I did it and do it the same way for the other portions of code mentionned in your post.
I unlocked your post in order to allow you to perform this.
Regards
Yordan

Reply


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Recent Queries:-
  1. check a number is palindrome or not in programming c - 35.28 hr back. (1)
  2. fees of learning c - 62.92 hr back. (1)
  3. program to check a given string is palindrome - 79.53 hr back. (1)
  4. int palindrome program c - 134.15 hr back. (1)
  5. int palindrome(char *str) - 343.98 hr back. (1)
Similar Topics

Keywords : learning, c,

  1. Good Book For Learning Xhtml & Css
    (2)
  2. Going To Try Learning Php
    (4)
    As some of you may know, I'm not exactly the worlds greates at PHP, infact I don't know much
    at all. I mainly like to design websites (the graphical side of it), not code any scripts. I only
    know x/html and css. So... I've decided to take a go at learning PHP, because as you also might
    know, I love Joomla and I want to start making components and that for it, I have the basic idea of
    how it all works, but I've only ever made templates for it before. I have this book here, I
    borrowed off a friend about a year ago and I'm not sure if he hinted I can j....
  3. Learning Php/sql Basics
    Want to learn CSS, PHP and create a website (17)
    Hello, I've been wanting to learn to create websites for a long time. I'm not sure how hard
    it will be and how long it will take to learn enough to make my own database-driven website. I
    studied SQL, basic programming, worked with databases and am familiar with HTML tags, but this all
    was for work, university and I never paid a lot of attention to details. In the past few days I read
    beginner's tutorials on PHP/SQL, CSS and even HTML. Now I want to create a simple database with
    some tables to practice with PHP scripts for a website, write and read database i....
  4. Learning To Use The Pen Tool In Photoshop
    (0)
    The Pen Tool is a great utility that everyone who wants to use Photoshop well should know about. In
    this tutorial I will cover a few things: 1. Basics 2. Things to Remember About the Pen Tool 3.
    Cutting Out an Object (1) Basics: Ok, so some people can use it, and others can't, but
    nevertheless it is a very useful tool that I find myself using every time I use Photoshop. It makes
    very nice curves and is much more flexible and useful than any of the marquee tools. To begin,
    select the pen tool from the bottom left of the third section of the left toolbar. Nex....
  5. How To Learn A Programming Language
    overview of the best way to go about learning a programming language. (0)
    How to Learn a Programming Language 1. Choose a programming language. Pythonand Turtle
    Graphics are good starter languages. they are very straightforward and easy to learn. Also, there is
    a module called Pygame available that makes handling windows a breeze. Another programming language
    for a beginner to try is Kids Programming Language, or KPL's new version, called Phrogram.
    Don't be put off by KPL's name! Once you learn the basic concepts of programming, you
    can then take those ideas into any programming language you choose. Be aware however....
  6. I Think A Good Programming Learning Steps Would Be...
    (5)
    Firstly PHP, secondly C, thirdly assembly. PHP has a lot of features in a close relationship with C
    and assembly will give you more of machine-level understanding required for programming. PHP fits
    more of network related job handling, C is good for general programming regardless the architectures
    while assembly gives almost close - and almost as it is - to architecture specific job when the
    speed is in demand. PHP will give the ease to the learner to get familiar with C and as well as
    other languages with C and C will give more understanding of the computer machine r....
  7. Just Learning Perl
    (6)
    Okay so I've decided to learn PERL. As I am VERY burned out on PHP after making an online
    hacking game in it and working on it for a month after release. Now that its almost done other than
    maintenance. I'm VERY good at php now. However I tried to do C and quickly thew my hands up
    (maybe too quickly). So I decided to learn PERL just to learn it. I'm curious, what are some
    practical uses for PERL (online. but more importantly offline/background/not used by public), does
    perl use the same if, else, while and the like as PHP? Thanks....
  8. Learning Php
    (7)
    I have decided to start learning php as I think it is essential if you want to make a good site. I
    have a book which is good for starters but it doesnt have much advanced stuff. Would anyone happen
    to know a good site I can learn from? While im on the topic, i cant get PHP to install on apache. So
    i still cant use php on my computer anyway :l....
  9. Best Way Of Learning A Scripting Language?
    (6)
    I was going to wonder what is the best way to learn a scripting language. I mean there are tons of
    different ways including buying Books on internet of that langauge. You can also take tech
    classes,or even internet classes, or best way to just learn by yourlself? Ive been messing alot
    lately with Macromedia MX director. Ive been learning its scripting language called Lingo, but ive
    just been learning from messing with source codes and server scripts. Is the best way trial and
    error and repeat?....
  10. Best Places To Start Learning PHP
    (7)
    best places to start learning PHP,good resources http://www.php.net/ http://www.sitepoint.com/
    http://hotwired.lycos.com/webmonkey/ http://www.devshed.com/ ....
  11. Learning Java
    (0)
    Thisi is a good place to learn java for beginner Here is one. http://java.sun.com/docs/ From the
    official site /biggrin.gif' border='0' style='vertical-align:middle' alt='biggrin.gif' /> The
    Java API here : http://www.ii.uam.es/~poo/java_doc/docs/api/index.html (it my university's
    webpage for Java Documentation). It contains all methods and objects predefined in Java. But before
    that, it could be useful for you to know some basic conceps of the Object Oriented Programming
    style, and what is it useful for. Javascript and Java aren't the same thing....
  12. Where To Start Learning Programming
    Please advise me on which language to (16)
    I am a beginer to programming i wish to know from which language should i start programming C, C++
    Is there any problem if i jump directly to vb or like please respond where can i find good beginer
    tutorials Thank you....
  13. Two Serious Learning Tools
    landmarkcases.org and gallica.bnf.fr (5)
    I don't expect the Net to replace libraries as a tool for serious learners in my lifetime, but
    occasionally one can find some serious learning tools on it. Here are two of my candidates:
    http://gallica.bnf.fr/ Interesting editions of the complete texts of classics of French literature
    (in French), for download, with background articles. They use an interesting technology to create
    the PDFs on the fly. Unfortunately, these are image-based PDFs, which can be inconvenient.
    http://www.landmarkcases.org/ Discussions of important cases which came before the Unit....
  14. How Can I Start Learning Linux
    (12)
    can someone give some tutor or website to me??? and i want to know what i need to learn first and
    which version is easiler to learn.......
  15. Having Little Time For Learning
    Visual Basic? C/C++? Java? (3)
    Hello all. I'm a 15 year old sophomore in an international school located in a Southeast Asian
    country called Thailand. The technology is very limited here and almost all pieces of equipment is
    imported. However, it's difficult to find programmers or computer experts who can help you for
    free. There are several popular computer / development centers where they teach you for a fee. And
    with this poor country's economy affecting the population, which is divided into rich and poor,
    with no in-between, it's difficult to find a good amount of money. Thus, I h....
  16. Linux User Needs Help Learning Freebsd
    (7)
    Recently, i decided that FreeBSD was somthing i wasnted to be able to say i could use, and afdmin
    comfortably. I was reading several comparasons between GNU/Linux (what i currently use) and
    f'BSD. Apart from the differences in the Licences, and they way they were developed, and of
    cource the history, they were very very similar. Ive used and become comfortable with several Linux
    distro's inclusing Linux From Scratch, Slackware, Gentoo Mandrake, Fedora/Redhat, and maybe a
    few others, LOL. After becomming comfortable with linux, i started university, where i use....
  17. Languages Worth Learning
    What languages should I learn? (21)
    Hello all. Right now I'm a Computer Science major in college. After I graduate (hopefully in
    three years) I'm wanting to get a job programming. At the moment I'm not too picky about
    the type of job, as long as it involves programming. So what I'm wanting to know is what
    languages would be worth learning while I'm in college. There are a lot of languages out there,
    and I'm not sure which ones are extensively used. I'm wondering what languages any
    programmers out there use at your job or have heard of people using. I want to be sure to ha....
  18. Huge Problem>> Learning Flash
    (3)
    Flash does not deserve to get the negative vibe that it has been getting. ie flash sucks. I have
    done a movie in my mind now if I can just get these programs to behave. My main problem is I am
    useing way to many programs and my brain is going to explode. I know you should learn one and learn
    it well but my problem is liking different ones for different things. I have noticed that people
    like Corel draw and I have never used it. Problem is with graphics that all the programs work
    differently. PSP 8 is my fav but I have an old program that I like much better for cropping e....
  19. Learning Programming: Which Language To Start
    which language to start on (11)
    Okay i have a basic knoledge of programming and am starting to learn it in more detail, my only
    problem is i dont know which language would be best to start on a book i brought suggested starting
    on Visual Basic, some old posts tha came up on searches said QBasic and a friend who does program
    says i should start on C or Pascal wha do you all think i should start on?....
  20. Microsoft Learning
    (1)
    Visit Microsoft Learning and Microsoft Skill Assessment to test ur skills. I scored 22/30 in
    the first Win XP test and 25/30 in the second. U can also use this thread to post your scores.
    Once again wrong forum. Kindly be a little extra careful next time as to where your posts are
    heading for. The forum descriptions are always there to help you figure it out. ....
  21. Some Of My 3D Models
    im still learning.. (25)
    sorry if this is the wrong forum,its 3d but not animation. forum description was a little confusing.
    well, ive been trying to model for a long time, but just a couple weeks ago i really got into
    learning to model in 3ds max, and its just suddenly started to click. this is a brick of C4, im
    redoing the wires. the only primitive i used was the chamfered box ( the tan one) everything was
    extruded from the original primitive. this next one is a concept shuriken (throwing star). i
    started with just a tube, then extruded and tapered the first spike, then used symmetry an....
  22. Learning Css
    (8)
    Is there a good site that teaches how to use CSS? I would really like to master it.....
  23. Learning How To Network?
    (5)
    Hey guys, I really have no idea about networking. Can someone please give a quick intro or maybe a
    link to some tutorial that could get me started. I really wanna learn how to network computers. I
    also need it for my studies. Thanks in advanced guys and Merry Christmas to you all /smile.gif'
    border='0' style='vertical-align:middle' alt='smile.gif' /> ....
  24. Learning Php
    (7)
    Okay, I was goin to start learning php...hopefully this free service will support php so I can test
    my code and such b/c I have it on my pc to test...but it seems to have problems running. Maybe I
    didn't enable some of the right things. Seems a bity hard to setup if you don't know what
    you're doing. Anyways I was wondering if they're any certain things that can improve my php
    skills. I'm familiar with setup of the language b/c I am very familiar with c++ syntax. So the
    syntax isn't a problem. The variables are a little different...dynamic or....
  25. Learning MySQL
    (9)
    Hello I want to learn about MySql Database. Do any one know about free rescorces for learning it.
    Also a tutor for DreamWeaver MX I will be very thanful. Sohail Ahmed sohail4@msn.com....
  26. Learning PHP
    (18)
    I'm interested in learning PHP, but I fear that I would have no time to learn the language and
    master it. How long would it take to develop good competence in PHP? I think I'm going to learn
    using technical books.....

    1. Looking for learning, c,

Searching Video's for learning, c,
advertisement




Learning C++



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE