WAP to find square of a given number, Write a C or C++ Program to find the square of a given number with output
Program
#include<stdio.h>
#include<conio.h>
void main()
{
float a,b;
clrscr();
printf("enter the number");
scanf("%f", &a);
b=a*a;
printf ("\n value is :");
printf ("%f", b);
getch();
}
Changes for C++
If you want to write the same program in c++ apply the following changes to the program.
1.) change the header file from "#include<stdio.h>" to "#include<iostream>.h"
2.) for input & output use "cout<<" & "cin>>" instead of "printf" & "scanf".
3.) don't use "% "symbol and "&" sign in "cin>>" statement.
Click here to check the output
Program
#include<stdio.h>
#include<conio.h>
void main()
{
float a,b;
clrscr();
printf("enter the number");
scanf("%f", &a);
b=a*a;
printf ("\n value is :");
printf ("%f", b);
getch();
}
Changes for C++
If you want to write the same program in c++ apply the following changes to the program.
1.) change the header file from "#include<stdio.h>" to "#include<iostream>.h"
2.) for input & output use "cout<<" & "cin>>" instead of "printf" & "scanf".
3.) don't use "% "symbol and "&" sign in "cin>>" statement.
Click here to check the output
No comments:
Post a Comment