Write a program which takes a number as an argument and returns its square.(4 marks)
#include
#include
int main(int argc,char **argv)
{
int x;
if(argc<2)
printf("You need to give a number to square in the command line.\n");
else{
x=atoi(argv[1]);
printf("The square of %d is %d\n",x,x*x);
}
}
1 mark for remembering the semicolon after int x
1 mark for remembering the semicolon after ("You need to give a number to square in the command line.\n")
1 mark for remembering the semicolon after (argv[1])
1 mark for remembering the semicolon after ("The square of %d is %dn",x,x*x)