Skip to main content

Posts

Showing posts from April, 2015

C Program to swap two numbers using pointers and function.

C Program to swap two numbers using pointers and function.   #include <stdio.h> void swap(int *a,int *b); int main() {   int num1=5,num2=10;   swap(&num1,&num2);        /* address of num1 and num2 is passed to swap function */      printf( "Number1 = %d\n" ,num1);   printf( "Number2 = %d" ,num2);      return 0; } void swap(int *a,int *b) {  /* pointer a and b points to address of num1 and num2 respectively */   int temp;   temp=*a;   *a=*b;   *b=temp; }

To check if given string is palindrome or not.

To check if given string is palindrome or not. #include <stdio.h> #include <string.h> #include <conio.h>   int main()   {   char a[100], b[100]; printf ( "Enter the string to check if it is a palindrome\n" );   gets (a);   strcpy (b,a);   strrev (b);   if ( strcmp(a,b) == 0 )   printf ( "Entered string is a palindrome.\n" );   else   printf ( "Entered string is not a palindrome.\n" );   return 0;   }

C Program to find transpose of a Matrix

Transpose : Transpose of a Matrix means changing Rows into Columns and vice-versa.                                                          Statement of C Program : This Program accepts the Matrix and prints its Transpose.         #include<stdio.h> #include<conio.h> void main() { int A[2][3] , B[3][2]; int i, j;                                    /* 'i ' used for rows and ' j ' used for columns */ clrscr(); printf(" Enter the elements of A\n"); for(i=0 ; i<2 ; i+...

C Program to Check Leap Year

C program to check whether a year is leap year or not using if else statement .      #include <stdio.h>      int main()      {       int year;       printf( "Enter a year: " );       scanf( "%d" ,&year);       if (year%4 == 0)       {           if ( year%100 == 0)   /* Checking for a century year */           {               if ( year%400 == 0)                  printf( "%d is a leap year." , year);               else            ...