C language Simple Programs
Assignment number 2 -- Programming Fundamentals -- Submitted by Hamza jadoon
Assignment number 2 -- Programming Fundamentals -- Submitted by Hamza jadoon
Program for converting decimal into 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;
}
#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;
}
#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;
}
#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;
}
1 Comments
If you're trying to lose kilograms then you absolutely need to get on this brand new personalized keto meal plan diet.
ReplyDeleteTo 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.