Sunday 27 March 2016

Armstrong Number & palindrome numbers with examples .

A positive integer is called an Armstrong number if the sum of cubes of individual digit is equal to that number itself. For example:
153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
12 is not equal to 1*1*1+2*2*2  // 12 is not an Armstrong number.
#include <stdio.h>
int main()
{
  int n, n1, rem, num=0;
  printf("Enter a positive  integer: ");
  scanf("%d", &n);
  n1=n;
  while(n1!=0)
  {
      rem=n1%10;
      num+=rem*rem*rem;
      n1/=10;
  }
  if(num==n)
    printf("%d is an Armstrong number.",n);
  else
    printf("%d is not an Armstrong number.",n);
}
Output:Enter a positive integer: 371
371 is an Armstrong number
palindrome program in c language, c code to check if a string is a palindrome or not and for palindrome number.
#include <stdio.h>
#include <string.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;
Output:
Enter the string to check if it is a palindrome
wow
Entered string is not a palindrome

C program examples

Some simple program in C-
1.
#include <stdio.h>
 
main()
{
    printf("Hello World\n");
    return 0;
}

Output:
       "Hello World"
2.
#include <stdio.h>
 
main()
{
   int number;
 
   printf("Enter an integer\n");
   scanf("%d",&number);
 
   printf("Integer entered by you is %d\n", number);
 
   return 0;
}

Output:
        Enter a number
5 Number entered by you is 5

3.
#include <stdio.h>
 
int main()
{
   int n;
 
   printf("Enter an integer\n");
   scanf("%d", &n);
 
   if (n%2 == 0)
      printf("Even\n");
   else
      printf("Odd\n");
 
   return 0;
}

4.
#include<stdio.h>
 
int main()
{
   int a, b, c;
 
   printf("Enter two numbers to add\n");
   scanf("%d%d",&a,&b);
 
   c = a + b;
 
   printf("Sum of entered numbers = %d\n",c);
 
   return 0;
}
Output:
Enter two numbres to add
4
5
Sum of entered numbers=9

E-books of C

What is C Language

C (/ˈs/, as in the letter c) is a general-purpose, imperative computer programming language(High level language), supporting structured programming,lexical variable scope and recursion, while a static type system prevents many unintended operations. By design, C provides constructs that map efficiently to typical machine instructions, and therefore it has found lasting use in applications that had formerly been coded in assembly language, including operating systems, as well as various application software for computers ranging from supercomputers to embedded systems.
C was originally developed by Dennis Ritchie between 1969 and 1973 at AT&T Bell Labs,[5] and used to re-implement the Unix Operating system. It has since become one of the most widely used programming languages of all time, with C compilers from various vendors available for the majority of existing computer architectures and operating systems. C has been standardized by the American National Standards Institute (ANSI) since 1989 (see ANSI C) and subsequently by the International Organization for Standardization (ISO).

Recent Post

C videos in Hindi language

Hello friends , in the following links you will get whole C Programming videos in Hindi Language (availability is not guaranteed & th...

Popular Posts

visit counter