Blog Moved

This website completely moved to new domain. For latest content, visit www.programmingposts.com

Search This Blog

22 Apr 2013

C PROGRAM TO FIND WHETHER STRING IS A PALINDROME

C PROGRAM TO FIND WHETHER STRING IS PALINDROME :

#include<stdio.h>
#include<string.h>
main()
{
 char str1[25],str2[25];
 printf("\n *** C Programs Blog ***");
    printf("\n >>> C Program to find whether string is Palindrome <<<");
    printf("\n\n Enter the string: ");
    scanf("%s",str1);
    strcpy(str2,str1); //copying str1 in str2
    strrev(str2);  //reversing str2
    if(strcmp(str1,str2) == 0) //checking whether str1 and atr2 are same
    { 
      printf("\n Entered string \" %s \" is a Palindrome",str1);
    }
    else
    {
     printf("\n Entered string \" %s \" is not a Palindrome",str1);
    }
    getch();   
}

Sample Output :

14 Apr 2013

C PROGRAM TO PRINT SOURCE PROGRAM NAME

#include<stdio.h>
main(int argc, char *argv[])
{
	char *p=argv[0];
	printf("\n *** C PROGRAMS BLOG ***");
	printf("\n >>> C PROGRAM TO PRINT NAME OF SOURCE PROGRAM <<< \n");
	printf("\n Program name is :  %s ",p);
	getch();
}

10 Mar 2013

C PROGRAM TO CHECK WHETHER GIVEN YEAR IS LEAP YEAR OR NOT


C PROGRAM TO CHECK WHETHER GIVEN YEAR IS LEAP YEAR OR NOT

#include<stdio.h>
void LeapYear(int);
void main()
{
    int year;
    printf("\n *** C PROGRAMS BLOG *** \n");
    printf("\n >>>> C PROGRAM TO CHECK WHETHER GIVEN YEAR LEAP YEAR OR NOT <<<< \n");
    printf("\n Enter the year : ");
    scanf("%d",&year);
    LeapYear(year);
    getch();
    return 0;
}
void LeapYear(int yr)
{
    int rem1,rem2;
    rem1 = yr%4 ; //rem1 = 0 for leap year
    rem2 = yr%100; //rem2! = 0 for leap year
    if((rem1 == 0) && (rem2!=0) || yr%400 == 0)
    {
        printf("\n The given year %d is Leap Year..",yr);
    }
    else
    {
        printf("\n The given year %d is Not Leap Year..",yr);
    }
    
}

Sample Output :