Skip to main content

Posts

Showing posts from February 25, 2012

Program to Count Number of Words and Number of Characters in a String.

  #include <stdio.h> #include < string .h> #include <conio.h> void main() { char str[20]; int i=0, word=0, chr=0; clrscr(); printf( "\nEnter any string: " ); gets(str); while (str[i] != '\0' ) { if (str[i] == ' ' ) { word++; chr++; } else chr++; i++; } printf( "\nNumber of characters: %d" , chr); printf( "\nNumber of words: %d" , word+1); getch(); }

WAP Program to Add Two Matrices in c

#include <stdio.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" ); }