Thursday, September 13, 2012

A program that shows GCD & LCM of two numbers using Euklid's Algorithm

#include


void main()
{
int num1, num2, gcd, lcm, remainder, numerator, denominator;


printf("Enter two Integer numbers\n");
scanf("%d %d", &num1,&num2);

if (num1 > num2)
{
numerator = num1;
denominator = num2;
}
else
{
numerator = num2;
denominator = num1;
}
remainder = num1 % num2;
while(remainder !=0)
{
numerator = denominator;
denominator = remainder;
remainder = numerator % denominator;
}
gcd = denominator;
lcm = num1 * num2 / gcd;
printf("GCD of %d and %d = %d \n", num1,num2,gcd);
printf("LCM of %d and %d = %d \n", num1,num2,lcm);
} /* End of main() */

A program that shows GCD & LCM of two numbers

#include


void main()
{
int num1, num2, gcd, lcm, remainder, numerator, denominator;


printf("Enter two Integer numbers\n");
scanf("%d %d", &num1,&num2);

if (num1 > num2)
{
numerator = num1;
denominator = num2;
}
else
{
numerator = num2;
denominator = num1;
}
remainder = num1 % num2;
while(remainder !=0)
{
numerator = denominator;
denominator = remainder;
remainder = numerator % denominator;
}
gcd = denominator;
lcm = num1 * num2 / gcd;
printf("GCD of %d and %d = %d \n", num1,num2,gcd);
printf("LCM of %d and %d = %d \n", num1,num2,lcm);
} /* End of main() */

Thursday, July 26, 2012

Some useful Math class’s methods in C-sharp




By using Math class we can program our code easily in C#.  For example we need to find square root of 900.0

Math.Sqrt( 900.0 )

So to get 30.0 as output type:        
                                            Console.WriteLine(Math.Sqrt(900.0));

One more interesting thing is you can evaluate an expression(i.e, combination of constant variables & operators) by using this method: 

If a=13.0, b=3.0, c=4.0
Then  the statement        

                                       Console.WriteLine( Math.Sqrt( c + d * f ) );  
evaluates the square root of (13.0+3.0*4.0) = 25.0 – namely 5.0        

Now see in the figure above some more methods that uses in Math class.

Don't delay to practice the functions. Start at the right time.  

Friday, July 13, 2012

How to learn Programming language?

New-comers of the department of CSE student don't have any knowledge of programming language.
As they get admitted to different universities of the country, they start to know about this. Most students think it very hard. They get frustrated.
Newcomers should not be frustrated. Keep believe in yourself & your teachers. Then learn your lessons as best as you can.
Computer software are created using many programming language. There are many programming language like C, C++, Java, C# etc. C is the mother of programming language. CSE students must learn C programming. C is a procedural programming language. On the other hand C++, C#, Java are OOP!( i.e, object oriented programming language). To build your career with programming you first have to start with C language.