## 1.21.2012

### Remove vowel in string

Q. write a C program for remove vowel in string and find the length of resulted string.

Ans.

/*c program for removing vowel in string and calculate length of new string*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
int len=0,i,j=0;
char str[40],new_str[30];
printf("Enter any string : ");
gets(str);
for(i=0; i<=strlen(str); i++)
{
if((str[i]=='a' || str[i]=='e' || str[i]=='i' || str[i]=='o' || str[i]=='u') ||(str[i]=='A' || str[i]=='E' || str[i]=='I' || str[i]=='O' || str[i]=='U' ))
{
str[i]=' ';
}
else
{
len++;
new_str[j++]=str[i];
}
}
new_str[j]='\0';
printf("New vowel less string : %s",new_str);
printf("\nLength of new string = %d",len);
getch();
return 0;
}

Output:-

Enter any string :John Cena Is Awesome
New vowel less string: Jhn Cn s wsm
Length of new string = 13

### Compound Interest

Q. Write an interactive program to calculate compound interest.

Ans.

/*c program for calculate compound interest*/
#include<stdio.h>
#include<math.h>
#include<conio.h>
int main()
{
float p,rate,time,ci;
printf("Enter principal amount : ");
scanf("%f", &p);
printf("Enter interest rate : ");
scanf("%f", &rate);
printf("Enter time period in year : ");
scanf("%f", &time);
//calculate ci
ci=p*(pow((1+rate/100),time)-1);
printf("\nCompound interest = %f",ci);
return 0;
}

Output :-

Enter principal amount : 48500
Enter interest rate : 6
Enter time period in year : 2
Compound interest = 5994.600098

You might also like to read related program:

### Simple interest

Q. Write an interactive program to calculate simple interest.

Ans.

/*c program for calculate simple interest*/
#include<stdio.h>
#include<conio.h>
int main()
{
float p,rate,time,si;
printf("Enter principal amount : ");
scanf("%f", &p);
printf("Enter rate of interest : ");
scanf("%f", &rate);
printf("Enter time period in  year : ");
scanf("%f", &time);
/*calculating simple interest*/
si=(p*time*rate)/100;
printf("\nSimple Interest = %2f",si);
getch();
return 0;
}

Output :-

Enter principal amount : 1000
Enter rate of interest : 2
Enter time period in  year : 1
Simple Interest =20

You might also like to read related C Programs :

### Number triangle

Q. Write a c program for following number structure :
1
22
333
4444
55555
4444
333
22
1

Ans.

/*c program for above triangle structure using while*/
#include<stdio.h>
#include<conio.h>
int main()
{
int num,n,r=1,c;
printf("Enter triangle number : ");
scanf("%d",&num);
while(num >= r)
{
c=1;
while(c <= r)
{
printf("%d",r);
c++;
}
printf("\n");
r++;
}
n=num-1;
while(n >= 1)
{
c=1;
while(c <= n)
{
printf("%d",n);
c++;
}
printf("\n");
n--;
}
getch();
return 0;
}
OR
/*c program for above number triangle using for loop*/

#include<stdio.h>
#include<conio.h>
int main()
{
int num,n,r,c;
printf("Enter triangle number : ");
scanf("%d",&num);
for(r=1; r<=num; r++)
{
for(c=1; c<=r; c++)
printf("%d",r);
printf("\n");
}
for(n=num-1; n>=1; n--)
{
for(c=1; c<=n; c++)
printf("%d",n);
printf("\n");
}
return 0;
}

Output :-

Enter triangle number :5
1
22
333
4444
55555
4444
333
22
1

## 1.14.2012

### Palindrome using pointer

Q. write a program to accept a string and find out whether it is palindrome or not  using pointer.

Ans.

/*program to check whether a string is palindrome or not using pointer*/
#include<stdio.h>
#include<conio.h>
int main()
{
char str[30];
char *p,*t;
printf("Enter any string : ");
gets(str);
for(p=str ; *p!=NULL ; p++);
for(t=str, p-- ; p>=t; )
{
if(*p==*t)
{
p--;
t++;
}
else
break;
}
if(t>p)
printf("\nString is palindrome");
else
printf("\n
String is Not palindrome");
getch();
return 0;
}

/*************Output*************/

Enter any string : SHAREMARKET
String is not palindrome

String is palindrome

/*********Output as snap shot*********/

 Screen shot for checking whether a string is palindrome or not using pointer

You might also like :

## 1.10.2012

### Diagonal sum of matrix

Q. Write a C program to find the sum of diagonal elements in matrix.
Hint: If you have following typical square 3X3 matrix, then diagonal elements will be:

1  2  3
5  6
7  8  9

In above 3X3 matrix there are two types diagonal element as:
first diagonal elements are  1, 5, 9 and
second diagonal elements are 3, 5,7

Ans.

/*program to find the sum of diagonal elements of the matrix*/
#include<stdio.h>
#include<conio.h>
#define MAX 5
int main()
{
int mat[MAX][MAX],row,col;
int i,j,d1=0,d2=0;
printf("Enter no. of rows and columns : ");
scanf("%d%d",&row,&col);
printf("Enter the elements of matrix:\n");
if(row==col)
{
for(i=0; i<row; i++)
{
for(j=0; j<col; j++)
scanf("%d",&mat[i][j]);
}
for(i=0,j=col-1; i<row || j>=0; i++,j--)
{
d1=d1+mat[i][i];
d2=d2+mat[i][j];
}
printf("\nThe sum of first diagonal elements : %d",d1);
printf("\nThe sum of second diagonal elements : %d",d2);
}
else
{
printf("Rows and columns are not equal!");
printf("\nTry again!");
}
getch();
return 0;
}

output:-

Enter no. of rows and columns : 3  2
Enter the elements of matrix:
Rows and columns are not equal!
Try again!

Enter no. of rows and columns : 3 3
Enter the elements of matrix:
1  2  3
4  5  6
7  8  9
The sum of first diagonal elements : 15
The sum of second diagonal elements : 15

You might also like to read:

### Product of matrix

Q. Write a C program to accept value of matrix and find out the product of matrix.
OR
Q. Give a example of 2d array with suitable arithmetic operation.

Ans.

/*source code of product of two matrix c program*/
#include<stdio.h>
#include<conio.h>
#define MAX 3
void input_mat(int [MAX][MAX], int, int);
void show_mat(int [MAX][MAX], int, int);
void prod_mat(int [MAX][MAX],int [MAX][MAX],int [MAX][MAX],int,int);
int main()
{
int x[MAX][MAX],y[MAX][MAX],z[MAX][MAX];
int row,col;
printf("Enter no. of rows and columns : ");
scanf("%d%d",&row, &col);
printf("Enter values in first matrix :\n");
input_mat(x,row,col);
printf("Enter values in second matrix :\n");
input_mat(y,row,col);
prod_mat(x,y,z,row,col);
printf("\nDisplay product of two matrices :\n");
show_mat(z,row,col);
getch();
return 0;
}
void input_mat(int matA[MAX][MAX], int r, int c)
{
int i,j;
for(i=0; i<r; i++)
{
for(j=0;j<c; j++)
scanf("%d",&matA[i][j]);
}
}
void prod_mat(int matA[MAX][MAX],int matB[MAX][MAX],int matC[MAX][MAX],int r,int c)
{
int i,j,k;
for(i=0; i<r; i++)
{
for(j=0;j<c; j++)
{
matC[i][j]=0;
for(k=0;k<c; k++)
{
matC[i][j]=matC[i][j]+matA[i][j]*matB[i][j];
}
}
}
}
void show_mat(int mat[MAX][MAX], int r, int c)
{
int i,j;
for(i=0; i<r; i++)
{
for(j=0;j<c; j++)
printf(" %d",mat[i][j]);
printf("\n");
}
}
/************************************
The output of above program would be:
*************************************/
 Figure: Screen shot of product of two matrix C program

Output in simple and easy way :-
Enter no. of rows and columns : 3 3
Enter values in First matrix :
4 5 3
2 1 9
6 7 5
Enter values in second matrix :
1 3 2
7 6 4
2 1 0

Display product of two matrices :
12 45 18
42 18 108
36 21 0

You might also like to read:

### Transpose of matrix

Q. Write a C program to accept value of matrix and find the transpose matrix.

Ans.

/*program of transpose of matrix*/
#include<stdio.h>
#include<conio.h>
#define MAX 3
void input_mat(int [MAX][MAX], int, int);
void show_mat(int [MAX][MAX], int, int);
void trns_mat(int [MAX][MAX],int [MAX][MAX],int,int);
int main()
{
int x[MAX][MAX],z[MAX][MAX];
int row,col;
printf("Enter no. of rows and columns : ");
scanf("%d%d",&row, &col);
printf("Enter values of %d X %d matrix :\n",row,col);
input_mat(x,row,col);
printf("\nYour entered matrix is : \n");
show_mat(x,row,col);
trns_mat(x,z,row,col);
printf("\nTranspose of entered matrix is :\n");
show_mat(z,row,col);
return 0;
}

void input_mat(int matA[MAX][MAX], int r, int c)
{
int i,j;
for(i=0; i<r; i++)
{
for(j=0;j<c; j++)
scanf("%d",&matA[i][j]);
}
}

void trns_mat(int matA[MAX][MAX],int matT[MAX][MAX],int r,int c)
{
int i,j;
for(i=0; i<r; i++)
{
for(j=0;j<c; j++)
matT[j][i] matA[i][j];
}
}

void show_mat(int mat[MAX][MAX], int r, int c)
{
int i,j;
for(i=0; i<r; i++)
{
for(j=0;j<c; j++)
printf(" %d",mat[i][j]);
printf("\n");
}
}

The output of above program would be:

 Figure: Screen shot for transpose of matrix C program

You might also like:

## 1.09.2012

### Sum of matrix

Q. Write a C program to accept value of matrix and print out the sum of matrix.
OR
Q. Give a example of 2d array with suitable arithmetic operation.

Ans.

/*program of sum of two matrix*/
#include<stdio.h>
#include<conio.h>
#define MAX 3
void input_mat(int [MAX][MAX], int, int);
void show_mat(int [MAX][MAX], int, int);
void sum_mat(int [MAX][MAX],int [MAX][MAX],int [MAX][MAX],int,int);
int main()
{
int x[MAX][MAX],y[MAX][MAX],z[MAX][MAX];
int row,col;
printf("Enter no. of rows and columns : ");
scanf("%d%d",&row, &col);
printf("Enter values in first matrix :\n");
input_mat(x,row,col);
printf("Enter values in second matrix :\n");
input_mat(y,row,col);
sum_mat(x,y,z,row,col);
printf("\nDisplay sum of two matrices :");
show_mat(z,row,col);
getch();
return 0;
}

void input_mat(int matA[MAX][MAX], int r, int c)
{
int i,j;
for(i=0; i<r; i++)
{
for(j=0;j<c; j++)
scanf("%d",&matA[i][j]);
}
}

void sum_mat(int matA[MAX][MAX],int matB[MAX][MAX],int matC[MAX][MAX],int r,int c)
{
int i,j;
for(i=0; i<r; i++)
{
for(j=0;j<c; j++)
matC[i][j]=matA[i][j]+matB[i][j];
}
}

void show_mat(int mat[MAX][MAX], int r, int c)
{
int i,j;
for(i=0; i<r; i++)
{
for(j=0;j<c; j++)
printf(" %d",mat[i][j]);
printf("\n");
}
}

Output:-

Enter no. of rows and columns : 3 3
Enter values in First matrix :
4 5 3
2 1 9
6 7 5
Enter values in second matrix :
1 3 2
7 6 4
2 1 0
Display sum of two matrices :
5 8 5
9 7 13
8 8 5

You might also like:
1. Difference of two matrix C program
2. Transpose of matrix C program
3. Product of matrix C program
4. Sum of diagonal elements C program
5. Sum of all corner elements C program

## 1.08.2012

### Difference of matrix

Q. Write a C program to accept value of matrix and print out the difference or subtract  of matrix.
OR
Q. Give a example of 2d array with suitable arithmetic operation.

Ans.

/*program of difference of two matrix*/
#include<stdio.h>
#include<conio.h>
#define MAX 3
void input_mat(int [MAX][MAX], int, int);
void show_mat(int [MAX][MAX], int, int);
void diff_mat(int [MAX][MAX],int [MAX][MAX],int [MAX][MAX],int,int);
int main()
{
int x[MAX][MAX],y[MAX][MAX],z[MAX][MAX];
int row,col;
printf("Enter no. of rows and columns : ");
scanf("%d%d",&row, &col);
printf("Enter values in first matrix :\n");
input_mat(x,row,col);
printf("Enter values in second matrix :\n");
input_mat(y,row,col);
diff_mat(x,y,z,row,col);
printf("\nDisplay difference of two matrices :");
show_mat(z,row,col);
getch();
return 0;
}

void input_mat(int matA[MAX][MAX], int r, int c)
{
int i,j;
for(i=0; i<r; i++)
{
for(j=0;j<c; j++)
scanf("%d",&matA[i][j]);
}
}

void diff_mat(int matA[MAX][MAX],int matB[MAX][MAX],int matC[MAX][MAX],int r,int c)
{
int i,j;
for(i=0; i<r; i++)
{
for(j=0;j<c; j++)
matC[i][j]=matA[i][j]-matB[i][j];
}
}

void show_mat(int mat[MAX][MAX], int r, int c)
{
int i,j;
for(i=0; i<r; i++)
{
for(j=0;j<c; j++)
printf(" %d",mat[i][j]);
printf("\n");
}
}

Output:-

Enter no. of rows and columns : 3 3
Enter values in First matrix :
4 5 3
7 6 1
6 9 5
Enter values in second matrix :
1 3 2
7 6 4
5 1 0
Display difference of two matrices :
3 2 1
0 0 -3
1 8 5

You might also like:
1. Sum of two matrix C program
2. Transpose of matrix C program
3. Product of matrix C program
4. Sum of diagonal elements C program
5. Sum of all corner elements C program