0% found this document useful (0 votes)
7 views4 pages

Assignment 6

The document contains four programming assignments in C. The first program calculates the sum of digits of a user-input number, the second converts a decimal number to binary, the third checks if a number is an Armstrong number, and the fourth checks if a number is a palindrome. Each program includes the necessary code and prompts for user input.

Uploaded by

Priyanka rani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

Assignment 6

The document contains four programming assignments in C. The first program calculates the sum of digits of a user-input number, the second converts a decimal number to binary, the third checks if a number is an Armstrong number, and the fourth checks if a number is a palindrome. Each program includes the necessary code and prompts for user input.

Uploaded by

Priyanka rani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Assignment 6

Ques1. Write a program to calculate sum of digits of a number input


by a user.
#include <stdio.h>
int main()
{
int number, remainder, sum = 0;
printf("\nenter any number\n");
scanf("%d",&number);
while (number > 0)
{
remainder = number % 10;
sum += remainder;
number = number / 10;
}
printf("sum is %d", sum);
return 0;
}

Ques2. . Write a program to convert a decimal number input by a user to binary


#include <stdio.h>
int main()
{
int i,j, n, a[10];
printf("enter a number");
scanf("%d", &n);
for (i = 0; n > 0; i++)
{
a[i] = n % 2;
n = n / 2;
}
for (j = i - 1; j >= 0; j--)
{
printf("%d", a[j]);
}
return 0;
}

Ques3. Write a program to take a number as input and check if it is Armstrong or not.
#include<stdio.h>
int main()
{
int n,arm=0,r,c;
printf("enter any number");
scanf("%d",&n);
c=n;

while(n>0)
{
r=n%10;
arm=(r*r*r)+arm;
n=n/10;
}
if(c==arm)
printf("armstrong number");
else
printf("not");
return 0;
}

Ques 4. Write a program to check if a number input by user is palindrome or not.


#include<stdio.h>
int main()
{
int n,s=0,r,c;
printf("enter any number");
scanf("%d",&n);
c=n;
while(n>0)
{
r=n%10;
s= r+(s*10);
n=n/10;
}
if (c==s)
printf("palindrome number");
else
printf("not");
return 0;
}

You might also like