Ticker

6/recent/ticker-posts

C Language Simple Programs.

C language Simple Programs


Assignment number 2 -- Programming Fundamentals -- Submitted by Hamza jadoon




Program for converting decimal into binary.


#include <stdio.h>
int main()
     {
     int n, i, j, binary=0,input;
  printf("Enter a number to convert : ");
     scanf("%d",&n);

     input=n;
     i=1;

      for(j=n;j>0;j=j/2)
       {
        binary=binary+(n%2)*i;
        i=i*10;
        n=n/2;
       }
     
     printf("\nThe Binary of %d is %d.\n\n",input,binary);
 }




Program for Sum of digits...


#include <stdio.h>
 int main()
{
   int n, t, sum = 0, remainder;
   printf("Enter an integer\n");
   scanf("%d", &n);
   t = n;
   while (t != 0)
   {
      remainder = t % 10;
      sum       = sum + remainder;
      t         = t / 10;
   }
   printf("Sum of digits of %d = %d\n", n, sum);
   return 0;
}



Program for Palindrome..


#include <stdio.h>
int main()
{
    int n, r_integer = 0, remainder, o_integer;
    printf("Enter an integer: ");
    scanf("%d", &n);

    o_integer = n;

    while( n!=0 )
    {
        remainder = n%10;
        r_integer = r_integer*10 + remainder;
        n /= 10;
    }
     if (o_integer == r_integer)
        printf("%d is a palindrome.", o_integer);
    else
        printf("%d is not a palindrome.", o_integer);
    
    return 0;
}




Programe for Armstrong Number.


#include <stdio.h>
int main()
{
    int number, o_integer, remainder, result = 0;

    printf("Enter a three digit integer: ");
    scanf("%d", &number);
    o_integer = number;
    while (o_integer != 0)
    {
        remainder = o_integer%10;
        result += remainder*remainder*remainder;
        o_integer /= 10;
    }

    if(result == number)
        printf("%d is an Armstrong number.",number);
    else
        printf("%d is not an Armstrong number.",number);

    return 0;
}

Post a Comment

1 Comments

  1. If you're trying to lose kilograms then you absolutely need to get on this brand new personalized keto meal plan diet.

    To create this keto diet service, certified nutritionists, fitness trainers, and cooks joined together to provide keto meal plans that are productive, convenient, economically-efficient, and enjoyable.

    From their grand opening in early 2019, 1000's of people have already completely transformed their figure and well-being with the benefits a certified keto meal plan diet can offer.

    Speaking of benefits; in this link, you'll discover 8 scientifically-tested ones offered by the keto meal plan diet.

    ReplyDelete