CODING:
#include<conio.h>
#include<stdio.h>
void main()
{
int num1,num2,i,prod=0;
clrscr();
printf("Enter 1st number: ");
scanf("%d",&num1);
printf("Enter 2nd number: ");
scanf("%d",&num2);
for(i=1;i<=num2;i++)
{
prod+=num1;
}
printf("\n\n\nProduct of %d and %d is %d",num1,num2,prod);
getch();
}
#include<conio.h>
#include<stdio.h>
void main()
{
int num1,num2,i,prod=0;
clrscr();
printf("Enter 1st number: ");
scanf("%d",&num1);
printf("Enter 2nd number: ");
scanf("%d",&num2);
for(i=1;i<=num2;i++)
{
prod+=num1;
}
printf("\n\n\nProduct of %d and %d is %d",num1,num2,prod);
getch();
}
CODING |
OUTPUT |
For any query or suggestion please comment below...
A much better method using bit manipulation(IN C++)
ReplyDelete#include
using namespace std;
int main()
{
int a,b,c,i;
cin>>a>>b;
if(a>=1,i++)
{
if(b&1)c+=(a<<i);
}
cout<<c;
return 0;
}
Yes ok.But you are used + operator.So we can use sum+=i
ReplyDeleteit doesnt work because when we enter negative integer it counts as 0
ReplyDeleteThis method is suitable for not all values, input 2,-3
ReplyDeleteGetting output is 0.
So how to solve this..