New Android apps UniqueKey

Saturday, 7 March 2015

Find enter number pellendrom or not and find number is prime or not


/*program to find enter number pellendrom or not and find number is prime or not*/

#include<stdio.h>
#include<math.h>

main()
{
  int num,i,j,k,rev=0,n,c=0;

  printf("enter the number\n");
  scanf("%d",&num);
  n=num;
  while(num>0)
  {
   i=num%10;
   rev=rev*10+i;
   num=num/10;
  }
   
  if(rev==n)
  {
   printf("%d is pellendrom number\n\n",n);
  }
  else
  {
  printf("%d is not a pellendrom number\n",n);
  }
  for(j=2;j<=n/2;j++)
  {
    if(n%j==0)
    {
      c=1;
      break;
    }
  }
   if((c==1)||(n==1))
   printf("%d is not a prime number\n\n",n);
   else
   printf("%d is a prime number\n\n",n);
   
   


}

Check whether year is a leap year or not


/*program to check the year leap or not*/

#include<stdio.h>
#include<math.h>

main()
{
  int year;
 
  printf("enter the year which you want to check\n");
  scanf("%d",&year);

  if(year%400==0)
   {
       printf("%d is leap year\n",year);
   }  
  else
   { 
     if(year%4==0&&year%100!=0)
     {
       printf("%d is leap year\n",year);
     }
     else
     {
       printf("%d is not leap year\n",year);
     }
   }  
}

Sunday, 22 February 2015

Removing white space from a string.


#include<stdio.h>

main()
{
    char str[150];
    int i,j;
    
    printf("Enter a string: ");
    gets(str);
    
    for(i=0; str[i]!='\0'; i++)
    {
        while (!((str[i]>='a'&&str[i]<='z') || (str[i]>='A'&&str[i]<='Z' || str[i]=='\0')))
        {
            for(j=i;str[j]!='\0';++j)
            {
                str[j]=str[j+1];
            }
            str[j]='\0';
        }
    }
    printf("Output String: ");
    puts(str);
}

Find no. of vowels , consonants , digits and white spaces in a string.


#include<stdio.h>

main()
{
    char str[150];
    int i,v,c,ch,d,s,o;
    
    o=v=c=ch=d=s=0;
    
    printf("Enter a string:\n");
    gets(str);
    
    for(i=0;str[i]!='\0';i++)
    {
        if(str[i]=='a' || str[i]=='e' || str[i]=='i' || str[i]=='o' || str[i]=='u' || str[i]=='A' || str[i]=='E' || str[i]=='I' || str[i]=='O' || str[i]=='U')
            ++v;
        else if((str[i]>='a'&& str[i]<='z') || (str[i]>='A'&& str[i]<='Z'))
            ++c;
        else if(str[i]>='0'&&c<='9')
            ++d;
        else if (str[i]==' ')
            ++s;
    }
    printf("Vowels: %d",v);
    printf("\nConsonants: %d",c);
    printf("\nDigits: %d",d);
    printf("\nWhite spaces: %d",s);
}

No. of particular character in a string.


#include <stdio.h>

main()
{
   char c[100],ch;
   int i,count=0;
   
   printf("Enter a string: ");
   gets(c);
   printf("Enter a character to find frequency: ");
   scanf("%c",&ch);
   
   for(i=0;c[i]!='\0';i++)
   {
       if(ch==c[i])
           count++;
   }
   printf("Frequency of %c = %d", ch, count);
}