You are here:

# C++/Source Code

Question
Hi i need to solve this query, can anybody solve this query.

.Write a program using malloc function. In which you take input from user and allocate memory equal to square of this number.  Which multiply numbers and draw a table in the following format?

Hint: User enters 3 then program allocates equal to 9 integer memories.

Output:1

Enter a single digit number:
2
The multiplication table of 2 is:
1       2
----------------
1|      1       2
2|      2       4

Output:2

Enter a single digit number:
4
The multiplication table of 4 is:
1       2       3       4
--------------------------------
1|      1       2       3       4
2|      2       4       6       8
3|      3       6       9       12
4|      4       8       12      16

.Write a macros in which swap two number without using 3rd variable and then call
Macro in main function.

Hint: a=4, b=2 after swapping a=2, b=4.

Dear Mr zanib akram !

Sorry for the delay in responding ! here im presenting you the code that you've requested

/* Macro to swap two integer numbers without using the third variable  , just call this macro in main function */

#define SWAP(x, y) (x ^= y ^= x ^= y)

#include<stdio.h>
void main()
{
int i,j;
int n;
int **array;

printf("Enter the order of matrix:");
scanf("%d" , &n);
array = (int **)malloc(n * sizeof(int *));

for(i = 0; i < n; ++i)
array[i] = (int *)malloc(n * sizeof(int));
for( i = 0 ; i < n ; i++)
for( j = 0 ; j < n ; j++)
*(*(array+i)+j) =  (i+1)*(j+1);
for( i = 0 ; i < n ; i++)
{
for( j = 0 ; j < n ; j++)
printf("%3d ",*(*(array+i )+j));
printf("\n");
}
}

Note : If you have any problems with this code , kindly i request you to intimate me !

Thanks and Regards
Prince M. Premnath
Questioner's Rating
 Rating(1-10) Knowledgeability = 10 Clarity of Response = 10 Politeness = 10 Comment Thank you very much for such kind of cooperation. But i mention onthing clear that i am not Mr. Zanib i am Miss Zanib. thanks again.

C++

Volunteer

#### Prince M. Premnath

##### Expertise

Years of research in C/C++ Will bring you all facts regarding , OOPS , SVGA , MOUSE , BIOS , IVT , Feel free to query me :-)

##### Experience

More than 5 years

Education/Credentials
MCA