Posts

Showing posts from October, 2012

What are Header files?

        Header file contains different predefined functions, which are required to run the program. All header files should be included explicitly before main ( ) function.Header files are also called as Pre-compiled header. Here is some C programming header files ... <assert.h> <complex.h>  <ctype.h> <errno.h>   <fenv.h>   <float.h>   <graphic.h> <inttypes.h> <iso646> <limits.h> <locale.h> <math.h>   <process.h> <setjmp.h>   <signal.h> <stdalign.h> <stdatomic.h> <stdbool.h>  <stdarg.h> <stddef.h> <stdint.h>  <stdio.h>   <stdlib.h> <stdnoreturn.h>  <string.h> <threads.h>  <tgmath.h>   <time.h> <uchar.h> <wchar.h> <wctype.h> We can input using two methods 1. #include<Header file name >      example: #include<stdio.h> 2. #include &qu

C Program to convert string into ASCII values in c programming language

#include<stdio.h> int main(){ char str[100]; int i=0; printf("Enter any string: "); scanf("%s",str); printf("ASCII values of every characters of string: "); while(str[i]) printf("%d ",str[i++]); return 0; } Enter any string:ankit c guru ASCII values of every characters of string: 97 110 107 105 116

C program to change Upper case to lower case

/*by ankit gehlot website:ankitcguru.blogspot.com/ */ #include<stdio.h> int main(){ char str[20]; int i=0; printf("Enter any string :"); scanf("%s",str); while(str[i]!='\0'){ if(str[i]>=65&&str[i]<=97){ str[i]=str[i]+32;}i++; } printf("\nThe string in lowercase is :%s ",str); return 0; } Output:- Enter any string :ANKIT The string in lowercase is :ankit

C program to change lower case to upper case

/*by ankit gehlot website:ankitcguru.blogspot.com/ */ #include<stdio.h> int main(){ char str[20]; int i=0; printf("Enter any string :"); scanf("%s",str); while(str[i]!='\0'){ if(str[i]>=97&&str[i]<=122){ str[i]=str[i]-32;}i++; } printf("\nThe string in Upper case is :%s",str); return 0; } Output:- Enter any string :ankit The string in lowercase is :ANKIT

C program to print length of string

         C program to print length of string include<stdio.h> void main(){ char str[15]; int=0; printf("Enter any string :\t");  scanf("%s",&str); while(str[i]!='\0') { i++; printf("\nLength of string :\t%d",i); getch(); } Output:- Enter any string :      ankit c guru Length of string :      12 Note:- Compiler will also count blank spaces between words while compiling.

String

Image
                                                                    String String is a set(array) of character which is terminated by '\0'(null character). When compiler assigns string to character array then it automatically supplies null character ('\0') at the end of string. Thus, size of string = original length of string + 1. Declaration of string:-     char <string name>[roof character]; Example:-   char str[15]; Initialization of strings:-    char str[15]="ankit"; //or char str[15]={'a','n','k','i','t','\0'};//you must put '\o'(null)in this method //printing printf("%s",str);// string printing printf("%c",str[i]);// character printing //scanning scanf("%s",&str);// string scanning scanf("%c",&str[i]);// character scanning

Multiplication of Matrix

Image
                                                                                 Multiplication of Matrix C program to multiplication of matrix :-  #include <stdio.h> #include <conio.h> void main() { int a[3][3],b[3][3],c[3][3],i,j,k; clrscr(); printf("\n\t Enter First Matrix : "); for(i=0;i<3;i++) { for(j=0;j<3;j++) { scanf("%d",&a[i][j]); } } printf("\n\t Enter Second Matrix : "); for(i=0;i<3;i++) { for(j=0;j<3;j++) { scanf("%d",&b[i][j]); } } for(i=0;i<3;i++) { for(j=0;j<3;j++) { c[i][j]=0; for(k=0;k<3;k++) { c[i][j]=c[i][j]+a[i][k]*b[k][j]; } } } printf("\n\t Matrix Multiplication is : \n\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("\t %d",c[i][j]); } printf("\n"); } getch(); } Ouput:-  Enter First Matrix : 1 2 1 3 2 1 1 2 1 Enter Second Matrix : 3 3 3 1 2 1 1 1 1 Ma

Subtraction of matrix

Image
                                             Subtraction of matrix Subtraction of matrix means that one matrix is subtracted for another and result is putted into third matrix. C program to subtract matrix:-   #include <stdio.h> #include <conio.h> void main() { int a[3][3],b[3][3],c[3][3],i,j,k; clrscr(); printf("\n\t Enter First Matrix : "); for(i=0;i<3;i++) { for(j=0;j<3;j++) { scanf("%d",&a[i][j]); } } printf("\n\t Enter Second Matrix : "); for(i=0;i<3;i++) { for(j=0;j<3;j++) { scanf("%d",&b[i][j]); } } for(i=0;i<3;i++) { for(j=0;j<3;j++) { c[i][j]=0; for(k=0;k<3;k++) { c[i][j]=c[i][j]+a[i][k]*b[k][j]; } } } printf("\n\t Matrix Multiplication is : \n\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("\t %d",c[i][j]); } printf("\n"); } getch(); } Output:- Enter First Matrix : 2 1 2 3

Addition of matrix

Image
                                        Addition of matrix   Addition of matrix means that two matrix are added and addition of both matrix is putted in into third matrix. C program to add matrix:-   #include <stdio.h> #include <conio.h> void main() { int a[3][3],b[3][3],c[3][3],i,j; clrscr(); printf("\n\t Enter First Matrix : "); for(i=0;i<3;i++) { for(j=0;j<3;j++) { scanf("%d",&a[i][j]); } } printf("\n\t Enter Second Matrix : "); for(i=0;i<3;i++) { for(j=0;j<3;j++) { scanf("%d",&b[i][j]); } } for(i=0;i<3;i++) { for(j=0;j<3;j++) { c[i][j]=a[i][j]+b[i][j]; } } printf("\n\t Matrix Addition is : \n\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("\t %d",c[i][j]); } printf("\n"); } getch(); } Output :-  Enter First Matrix : 2 1 2 3 2 1 2 3 3 Enter Second Matrix : 2 1 0 2 3 0 1 1 2 Matrix Additio

Magic square matrix

Image
                                                                           Magic square matrix A magic square is a square array of  numbers consisting  of  the distinct positive integer ,arranged such that the sum of the numbers in any horizontal,vertical or main diagonal line is always the same number C program of Magic square matrix :-  void main() { int n, i, j, c, a[9][9] ; clrscr() ; printf("Enter the size of the magic square : ") ; scanf("%d", &n) ; if (n % 2 == 0) { printf("\nMagic square is not possible") ; goto end ; } printf("\nThe magic square for %d x %d is :\n\n", n, n) ; j = (n + 1) / 2 ; i = 1 ; for(c = 1 ; c <= n * n ; c++) { a[i][j] = c ; if(c % n == 0) { i = (i + 1); goto loop ; } if(i == 1) i = n ; else i = i - 1 ; if(j == n) j = 1; else j = j + 1 ; loop : ; } for (i = 1 ; i <= n ; i++) { for (j = 1 ; j <= n ; j++) { printf("%d\t", a[i][j]) ; } printf("\n\n") ; } end : ; getch(

Transpose of matrix

Image
                                                 Transpose of matrix The transpose of a matrix A is a matrix formed formed from A by interchanging the rows  and columns such that row i of a matrix  A becomes column i of the transposed matrix.The transpose of A is denoted by AT.Each element a a q in A becomes element a p in AT.If A is a m by n matrix ,then AT is an n and m matrix .The  following represents a matrix and its transpose. C program to transpose matix:-  #include <stdio.h> #include <conio.h> void main() { int a[3][3],i,j; clrscr(); printf("\n\t Enter Matrix : "); for(i=0;i<3;i++) { for(j=0;j<3;j++) { scanf("%d",&a[i][j]); } } printf("\n\t Transpose of Matrix is : \n\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("\t%d",a[j][i]); } printf("\n"); } getch(); } Output:-   Enter Matrix : 2 1 2 3 2 1 2 3 3 Transpose of Matrix is : 2 3 2

Square matrix

Image
                                                             Square matrix     The square matrix is 2D-Array or matrix in which both number of  rows and columns are equal. Example 1:-     int list[5][5]; X = main diagonal -  = upper triangular + = lower triangular Example 2 :- int list[5][5]; main diagonal     = 2,5,5,8,7 upper triangular  = 3,5,8,4,7,9,8,2,3,2 lower triangular  = 2,8,3,3,5,3,7,1,2,5