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 find Prime numbers between a range. The range will be taken from the user.
input:
The lower range and the upper range .output:
We will print the Prime numbers between the range .CODE---->
#include<stdio.h>#include<conio.h>
main()
{
int range1,range2,change,i,j,flag;
printf(" \n\n Enter the range 1 : ");
scanf("%d",&range1);
printf("\n Enter the range 2 : ");
scanf("%d",&range2);
if(range1>range2)
{
change=range1;
range1=range2;
range2=change;
} //if user enter the higher range first.
if(range1==1)
range1++; //because 1 is not a prime number.
printf("\n\n The prime numbers between %d and %d are : ",range1,range2); while(range1<=range2)
{
i=range1;
flag=0;
for(j=2;j<=(i-1);j++)
{
if(i%j==0)
flag=flag+1;
}
if(flag==0)
printf(" %d",i);
range1++;
}
getch();
}
Comments
Post a Comment