1. add two numbers without using + or any arithmetic operator??
answer:
int main()
{
int num1,num2,i;
printf("enter num1 : ");
scanf("%d",&num1);
printf("enter num2 : ");
scanf("%d",&num2");
for(i=num1 ; i<num2 ;i++);
{
num1++;
}
printf("\n sum of num1 & num2 is : %d",num1);
return 0;
}
explanation:
here were are incrementing num1 upto num2 times ,so finally we are obtaining the sum
ex: num1=2 ,num2=3 then increment(+1) num1(2) upto num2(3) times = 2 + 1 + 1 + 1 =5 nothing but 2+3=5
answer:
int main()
{
int num1,num2,i;
printf("enter num1 : ");
scanf("%d",&num1);
printf("enter num2 : ");
scanf("%d",&num2");
for(i=num1 ; i<num2 ;i++);
{
num1++;
}
printf("\n sum of num1 & num2 is : %d",num1);
return 0;
}
explanation:
here were are incrementing num1 upto num2 times ,so finally we are obtaining the sum
ex: num1=2 ,num2=3 then increment(+1) num1(2) upto num2(3) times = 2 + 1 + 1 + 1 =5 nothing but 2+3=5
No comments:
Post a Comment