Friday, 30 September 2016
Friday, 2 September 2016
Question: Big integer addition with array of integer as input .
Solution :
// I have used different syntax for ip/op, you can use scanf / printf instead .
//big integer addition program without test case and array input
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
int a[100],b[100];
int c[100],m,n;
cin>>m;
cin>>n;
int i,j;
int newpos=0;
for( i=0;i<m;i++)
{
cin>>a[i];
}
for( j=0;j<n;j++)
{
cin>>b[j];
}
int sum,carry=0;
for( i=m-1,j=n-1;i>=0,j>=0;i--,j--)
{
sum=a[i]+b[j]+carry;
c[newpos++]=sum%10;
carry=sum/10;
}
for(;j>=0;j--)
{
sum=b[j]+carry;
c[newpos++]=sum%10;
carry=sum/10;
}
for(;i>=0;i--)
{
sum=a[i]+carry;
c[newpos++]=sum%10;
carry=sum/10;
}
if(carry>0)
{
c[newpos++]=carry;
}
//reversing the array
for(i=newpos-1;i>=0;i--)
{
cout<<c[i];
}
cout<<"\n";
}
Thursday, 1 September 2016
Welcome to the world of writing C program on piece of paper .
Isn't it funny?
But you have to do it now in your Mid semester exam.
Some Do's and dont's
1. Practice all programs given in tutorials by writing on piece of a paper.
2. Focus on syntax of the language . Never miss out the semicolons.
3. In theory paper marks are divided on both syntax and logic .
4. Always attempt the problem and write your logic even though it may be not correct on the paper.
5. The paper will consist of easy , moderate and difficult questions.
6. Be quick and accurate in easy programs ( these are problems directly related to tutorial problems).
7.Moderate questions are slight modification of easy problems .
8. Don't worry , only 1 or 2 hard questions are there in which logic part is only tricky.
9.Try writing syntaxes on piece of paper.
and AT LAST ONLY HARD WORK PAYS FOR NOW.
Bye for now, next post will be about strings and 2 d array .
Comment for a topic which you want to discuss. (You can use pseudonames) .
Subscribe to:
Comments (Atom)