Sunday, August 30, 2015

C Programs on flow control statements (if, switch, loop, break and continue)-3

2015 & 2016 Batch Freshers Registration Link

JOIN MY FACEBOOK GROUP FOR UPDATES 

C Program to Count Number of Digits of an Integer
Input: Enter an integer : 234
Output: 3

main()
{
          int num,count=0;
           printf("Enter an integer: ");
          scanf("%d", &num);
          while(num!=0)
          {
                    num=num/10;
                    count++;
          }
          printf("Number of digits: %d",count);
}

C Program to Reverse a Number

Input: Enter an integer : 234
Output: 432

main()
{
          int num,rev=0,rem;
           printf("Enter an integer: ");
          scanf("%d", &num);
          while(num!=0)
          {
                    rem=num%10;
                    num=num/10;
                    rev=rev*10+rem;
          }
          printf("reverse of %d is %d",num,rev);
}

C Program to Check Whether a Number is Palindrome or Not

Input: Enter an integer : 234
Output: not a palindrome

main()
{
          int num,rev=0,rem,orig;
           printf("Enter an integer: ");
          scanf("%d", &num);
          orig=num;
          while(num!=0)
          {
                    rem=num%10;
                    num=num/10;
                    rev=rev*10+rem;
          }
          if(orig==rev)
                    printf("Palindrome”);
          else
                    printf(“Not a palindrome”);

}

Contact Geek Placement Preparation

Name

Email *

Message *