Q. If sum of two integer is 14 and if one of them is 8 then find other integer. Ans: Well, this is very simple. Simply, one integer is 8 and sum of two integers is 14. So, we need to subtract the number 8 from their sum of 14 to get the second number. So, the second number is: 14 - 8 = 6 C-Program of this task Code---> #include<stdio.h> int main () { int num1 = 8 , num2 , sum = 14 ; num2 = sum - num1 ; printf ( "The second number is: %d" , num2 ); return 0 ; }
In this C-program we will check the Perfect numbers in a given Range and print them on the screen. The lower range and the upper range will be taken from the user.
input:
The Lower Range and the Upper Range.output:
The Perfect numbers will be printed on the screen in the given range.CODE---->
#include<stdio.h>
#include<stdlib.h>
int perfect(int x)
{
int i,sum=0;
if(x==0)
return 0;
for(i=1;i<=(x-1);i++)
{
if(x%i==0)
sum=sum+i;
}
if(sum==x)
return 1;
else
return 0;
}
int main()
{
int num,i,lr,ur,check;
printf("\n Please, Enter the Lower range : ");
scanf("%d",&lr);
printf("\n Please, Enter the Higher range : ");
scanf("%d",&ur);
printf("\n The Perfect numbers are : ");
for(i=lr;i<=ur;i++)
{
check=perfect(i);
if(check==1)
printf(" %d ",i);
}
printf("\n");
}
Comments
Post a Comment