Sunday, April 01, 2012

Concatenate Two Strings without using strcat()

#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
char str1[30], str2[20];
int i, length=0, temp;
printf("Enter the First String: \n");
gets(str1);
printf("\nEnter the Second String: \n");
gets(str2);
for(i=0; str1[i]!='\0'; i++)
length++;
temp = length;
for(i=0; str2[i]!='\0'; i++)
{
str1[temp] = str2[i];
temp++;
}
str1[temp] = '\0';
printf("\nThe concatenated string is:\n");
puts(str1);
getch();
}

Check Whether a Character is a Vowel or not by using switch Statement

#include <stdio.h>
#include <conio.h>
void main()
{
char ch;
printf("\nEnter any character: ");
scanf("%c", &ch);
switch (ch)
{
case 'a':
case 'A':
printf("\n\n%c is a vowel", ch);
break;
case 'e':
case 'E':
printf("\n\n%c is a vowel", ch);
break;
case 'i':
case 'I':
printf("\n\n%c is a vowel", ch);
break;
case 'o':
case 'O':
printf("\n\n%c is a vowel", ch);
break;
case 'u':
case 'U':
printf("\n\n%c is a vowel", ch);
break;
default:
printf("\n\n%c is not a vowel", ch);
}
getch();
}

Add Two Matices

#include <stdio.h>
#include <conio.h>
void main()
{
int a[10][10], b[10][10], c[10][10], i, j, row, col;
printf("\nEnter number of rows and columns: ");
scanf("%d %d", &row, &col);
printf("\nEnter elements of Array A:\n");
for (i=0; i<row; i++)
for (j=0; j<col; j++)
scanf("%d", &a[i][j]);
printf("\nEnter elements of Array B:\n");
for (i=0; i<row; i++)
for (j=0; j<col; j++)
scanf("%d", &b[i][j]);
printf("\nElements of Matrix A:\n\n");
for (i=0; i<row; i++)
{
for (j=0; j<col; j++)
printf("\t%d", a[i][j]);
printf("\n\n");
}
printf("\nElements of Matrix B:\n\n");
for (i=0; i<row; i++)
{
for (j=0; j<col; j++)
printf("\t%d", b[i][j]);
printf("\n\n");
}
for (i=0; i<row; i++)
for (j=0; j<col; j++)
c[i][j] = a[i][j] + b[i][j];
printf("\nMatrix Addition is:\n\n");
for (i=0; i<row; i++)
{
for (j=0; j<col; j++)
printf("\t%d", c[i][j]);
printf("\n");
}
getch();
}