## Apr 13, 2012

### C Program to check matrix is magic square or not.

Write a c program to check whether the given matrix is a  magic square matrix or not?
The matrix is magic  square matrix, if all rows sum, columns sum and diagonals sum must be equal. Example:

8   1   6
3   5   7
4   9   2      is the magic square matrix. Read more about C Programming Language . and read the C Programming Language (2nd Edition). by K and R.

```/***********************************************************
* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact info@c-program-example.com
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
*                      Happy Coding
***********************************************************/

#include <stdio.h>
#include<conio.h>
void main()
{
int A[10][10];
int i, j=0, M,N;
int size;
int sum,sum1,sum2;
int flag=0;

clrscr();

printf("Enter the order of the matrix:\n");
scanf("%d %d", &M, &N);
if(M==N){
printf("Enter the elements of matrix \n");
for(i=0; i<M; i++)
{
for(j=0; j<N; j++)
{
scanf("%d",&A[i][j]);
}
}

printf("\n\nMATRIX  is\n");
for(i=0; i<M; i++)
{
for(j=0; j<N; j++)
{
printf("%3d\t",A[i][j]);
}
printf("\n");
}

sum=0;
for(i=0;i<M;i++)
for(j=0;j<N;j++)
{
if(i==j)
sum=sum+A[i][j];
}

for(i=0;i<M;i++)
{
sum1=0;
{
for(j=0;j<N;j++)
sum1=sum1+A[i][j];
}
if(sum==sum1)
flag=1;
else
{
flag=0;
break;
}
}

for(i=0;i<M;i++)
{
sum2=0;
for(j=0;j<N;j++)
{
sum2=sum2+A[j][i];
}
if(sum==sum2)
flag=1;
else
{
flag=0;
break;
}
}

if(flag==1)
printf("\n\n The given Matrix is a Magic square matrix\n\n");
else
printf("The given Matrix is NOT a  Magic square matrix\n\n");
} else
{
printf("\n\nPlease enter the square matrix order(m=n)\n\n");
}
}
```
```Read more Similar C Programs
Matrix Programs
Learn C Programming```
You can easily select the code by double clicking on the code area above.

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

(you can send this program to your friend using this button)

To browse more C Programs visit this link

## Apr 11, 2012

### C Program to delete vowels in a string.

C Strings:
Write a C Program to delete a vowel in a given string.
In this program, We use the pointers to position the characters.check_vowel() function checks the character is vowel or not, if the character is vowel it returns true else false.
Example output:Given string: Check vowel
Output is: Chck vwl
Read more about C Programming Language . and read the C Programming Language (2nd Edition). by K and R.

```/***********************************************************
* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact info@c-program-example.com
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
*                      Happy Coding
***********************************************************/

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#define TRUE 1
#define FALSE 0

int check_vowel(char);

main()
{
char string[100], *temp, *pointer, ch, *start;
csrcscr();
printf("\n\nEnter a string\n");
scanf("%s",string);
temp = string;
pointer = (char*)malloc(100);

if( pointer == NULL )
{
printf("Unable to allocate memory.\n");
exit(EXIT_FAILURE);
}

start = pointer;

while(*temp)
{
ch = *temp;

if ( !check_vowel(ch) )
{
*pointer = ch;
pointer++;
}
temp++;
}
*pointer = '\0';

pointer = start;
strcpy(string, pointer); /* If you wish to convert original string */
free(pointer);

printf("String after removing vowels is \"%s\"\n", string);

return 0;
}

int check_vowel(char a)
{
if ( a >= 'A' && a <= 'Z' )
a = a + 'a' - 'A';

if ( a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
return TRUE;

return FALSE;
}
```
```Read more c programs
C Basic
C Strings
```
You can easily select the code by double clicking on the code area above.

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!