i want help in programming coding in c++

admin
c
c-plus-plus
code
java
programming

#1

i want rpogramming code for --> acceptive value from user and find out square of the no. in c++


#2

@rohya, what do you mean by “acceptive”?

i think you want to accept a number from user and print square of that number isn’t it? What difficulty are you facing? please elaborate so that you get better help :slight_smile:

But for now here’s the c++ code:

#include<iostream>
using namespace std;
int main()
{
    int a;
    cout<<"enter the number";
    cin>>a;
    int square= a*a;
    cout<< "The square is: " << square;
    return 0;
}

#3

this code will work in software borland c++?
and yes it’s accept not acceptive… typing error.
please just let me know is this code will work in software borland c++?


#4

Ok, so since you asked i just installed Borland c++(version 3.1) for the first time.


important points to be noted:

  • In Borland while using header files you must use .h extension. while, coding for online environments like codehcef or spoj never use .h extensions.
  • You can not use "using namespace std" in Borland( I think)

  • and here is your answer, working code for finding square in borland with ouput:

    ![alt text][1]

    Hope this helps! :slight_smile:


#5

thank you so much bro… :slight_smile: :smiley:
will you be help me out with this
question is : Accept number from user and find out cube of the number.
this also i want to be run in borland … plz try if you can…


#6

i didnt got plz can you please show throught code


#7

In the above code:

Replace:

 int square= a * a;

with:
 int cube= a * a * a;



everything else remains the same.


#8

ya image one only used in borland but showing thi error

#include<iostream>
void main()
{
    int a;
    cout<<"enter the number"<<end1;
    cin>>a;
    int cube;
    cube=a*a*a;
    cout<<"The cube of the number is: " << cube;
}

output:

Line 2: error: ‘::main’ must return ‘int’


#9

@rohya well, now you can follow the code in the image. i’m sure it wont be difficult to make out that cube of number = aaa so you just need to add multiply the square one more time with “a” and you have the cube!


#10

Why on earth would you use Borland when you have Code Blocks and Visual Studio? :stuck_out_tongue: