C Program to check whether a given Number is Armstrong
#include
#include
#include
void main()
{
int number, sum = 0, rem = 0, cube = 0, temp;
clrscr();
printf ("enter a number");
scanf("%d", &number);
temp = number;
while (number != 0)
{
rem = number % 10;
cube = pow(rem, 3);
sum = sum + cube;
number = number / 10;
}
if (sum == temp)
printf ("The given no is armstrong no");
else
printf ("The given no is not a armstrong no");
getch();
}
Output
Enter a number370
The given no is armstrong no
C Program to check whether a given Number is Perfect Number
#include
#include
int main()
{
int number, rem, sum = 0, i;
clrscr();
printf("Enter a Number\n");
scanf("%d", &number);
for (i = 1; i <= (number - 1); i++)
{
rem = number % i;
if (rem == 0)
{
sum = sum + i;
}
}
if (sum == number)
printf("Entered Number is perfect number");
else
printf("Entered Number is not a perfect number");
return 0;
}
Output
Enter a Number
6
Entered Number is perfect number
C Program to Shutdown or Turn off the Computer in Linux
#include
#include
int main()
{
clrscr();
system("Shutdown -P now");
return 0;
}
Output
Shutdown: Need to be root
C program to Increase 1 to all of the given Integer
Digit
#include
#include
int main()
{
int number, sum = 0, remainder, count;
clrscr();
printf("Enter a number: ");
scanf("%d", &number);
while (number)
{
remainder = number % 10;
sum = sum + (remainder + 1);
number /= 10;
}
printf("increasing 1 to all digits: %d", sum);
return 0;
}
Output
Enter a number: 3456
Increasing 1 to all digits: 22
No comments:
Post a Comment