Find the sum of all the multiples of 3 or 5 below or equal to 1000

To find the sum of all the multiples of 3 or 5 below or equal to 1000, first we have to find the sum of all the numbers which are divisible by 3, than sum of numbers which are divisible by 5. Once we are done with this we have to subtract the sum of numbers which are divisible by 3 and 5.

There are two approaches to solve this problem.

  1. The first approach is to write a loop and find the numbers which are divisible by 3,5 and add them, after this subtract the numbers which are divisible by 3 and 5.
  2. The other approach is to find the count of numbers which are divisible by 3,5 and 15. After this apply the arithmetic progression’s sum formula to find the sum.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
  class Program
  {
    static void Main(string[] args)
    {
      int sum = 0;
      int range = 1000;
      int Number1 = 3; int Number2 = 5;
      for (int i = 0, j = 0; i <= range; i += Number1, j += Number2)
      {
        sum += i;
        if (j < range && j % Number2 == 0)
        {
          sum += j;
        }
        if (i <= range && i % Number2 * Number1 == 0)
        {
          sum -= i;
        }

      }
      Console.WriteLine("\n");
      Console.WriteLine("Sum of all the multiples of 3 or 5 below or equal to 1000" +
      "using Loop "  + sum);

      int Total_Number1 = range / Number1;
      int Total_Number2 = range / Number2;
      int Total_Number1AndNumber2 = range / (Number1 * Number2);

      int sumTotal_Number1 = Total_Number1 * (Number1 + Total_Number1 * Number1) / 2;
      int sumTotal_Number2 = Total_Number2 * (Number2 + Total_Number2 * Number2) / 2;
      int sumTotal_Number1andNumber2 = Total_Number1AndNumber2 * (Number2 * Number1
          + Total_Number1AndNumber2 * Number2 * Number1) / 2;
      int total = sumTotal_Number1 + sumTotal_Number2 - sumTotal_Number1andNumber2;
      Console.WriteLine("Sum of all the multiples of 3 or 5 below or equal to 1000 " +
                      "using arithmetic progression’s sum formula  " + total);

      Console.ReadLine();
    }
  }
}

Please post your comments if you find a better way to find the sum of numbers which are divisible by 3 or 5 and less than 1000.

Disable Internet Explorer Friendly Error Messages

Sometimes Internet Explorer display friendly error messages like “Internet explorer cannot display this webpage”. Via looking into this error message we do not get, any idea related to error message and most people think, it’s an internet connection problem.

In order to view the actual error message, we need to disable “Internet Explorer’s friendly error message” feature. In order to disable this feature go to Tools menu, click Internet Options, click the resulting dialog’s Advanced tab, and clear the “Show friendly HTTP error messages” checkbox.

Extend Visual Studio Team Foundation Server 2010 Using Java

Microsoft released a SDK for visual studio team foundation server 2010, for java developers. This SDK allows java developers to write code for VSTFS like .NET developers can write. This SDK allow java developers to write software components that can be integrated with VSTFS 2010.

 

The Team Foundation Server SDK for Java includes documentation, samples and redistributable components to help you develop software products that integrate with Microsoft Visual Studio Team Foundation Server 2010. By downloading the SDK from the link below you agree to the Microsoft Visual Studio Team Foundation Server 2010 Software Development Kit for Java license terms.

The SDK contains the following components:

  • Redistributable library (jar file) containing the TFS API’s
  • Redistributable native code libraries required by the SDK for Java
  • API Documentation in Javadoc format
  • Check-in policy code sample
  • Custom work item control code sample
  • Console application code sample
  • Code snippets

Download Microsoft Visual Studio Team Foundation Server 2010 Software Development Kit for Java

What is .NET Framework

Microsoft .NET Framework is an integral part of Windows operating system and it is used for developing applications that runs on family of Windows operating system. The .NET Framework has two major components called Common Language Runtime and .NET Base Class Library. .NET Framework support an array of language, VB.C#, F#, C++ and J# are supported by Visual Studio’s default installation.

Features of .NET Framework

Interoperability : Sometimes application developed in .NET has to interact with applications developed outside .NET. Access to COM components is provided in the System.Runtime.InteropServices and System.EnterpriseServices namespaces of the framework; access to other functionality is provided using the P/Invoke feature.

Common Runtime Engine : The Common Language Runtime (CLR) is the execution engine of the .NET Framework. Its CLR responsibility to locate, load and manage .NET types on your behalf. The CLR also takes care of a number of low-level details such as memory management, application hosting, handling threads, and performing various security checks.

Common Type System  : The CTS specification fully describes all possible data types and programming constructs supported by the runtime, specifies how these entities can interact with each other, and details how they are represented in the .NET metadata format. Common Type System makes .NET Framework language independent means, class libraries developed in one language can be used applications that are developed in some other language.

Base Class Library : The Base Class Library (BCL), part of the Framework Class Library (FCL), is a library of functionality available to all languages using the .NET Framework. The BCL provides classes which encapsulate a number of common functions, including file reading and writing, graphic rendering, database interaction, XML document manipulation and so on.

Simplified Deployment Model : .NET Framework provides a simplified deployment. Applications developed using .NET Framework are not required to register them as binary unit into system registry. Further more .NET Framework allows multiple versions of the same *.dll to exist in harmony on a single machine.

Visual Studio LightSwitch: An Integrated Development Environment for Managers

Microsoft is working on product called LightSwitch and release a beta version of Visual Studio LightSwitch on August 23, 2010. Visual Studio LightSwitch will come with pre-configured templates, pre-written code and other reusable components. Visual Studio LightSwitch also allows users to write custom code in Visual Basic .NET or C#. Applications developed using LightSwitch can be deployed on desktop, browser or on cloud.

Applications created with LightSwitch support exporting data to Microsoft Office Excel for fast and easy sharing and reporting. You can also attach your application to existing data sources, which makes it easy to collect, analyze, and reuse information from a variety of data sources including Microsoft SQL Server, Microsoft SQL Azure, SharePoint, Microsoft Office Access (post-Beta), and other third-party data sources.

With LightSwitch you can create custom applications for the way you do business. Keep your technology and business options open, while building a practical yet scalable application that matches your current needs now and in the future. The pre-built templates and components in LightSwitch are fully extensible, so you can get the specific functionality your application demands. In addition, your application can grow to meet the increasing demands of popular applications using the Microsoft Windows Azure Cloud Hosting option.

Optional Parameters in C#

With the release of .NET 4.0 C# programmers are now able to created methods with optional parameters like VB programmers doing. Optional arguments are widely used in VBA for long time. Although they make life a little bit easier for programmers (you don’t have to repeat default values in your method calls).

Code Snippet
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace optionalParameters
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             OptionalParameterTest t = new OptionalParameterTest();
  13.             Console.WriteLine("Optional Parameter :  {0}", t.OptionalParameter("One"));
  14.             Console.WriteLine("Optional Parameter :  {0} ", t.OptionalParameter("One1", "Two1"));
  15.             Console.WriteLine("Optional Parameter :  {0} ", t.OptionalParameter("One1", "Two1","three1"));
  16.             Console.WriteLine("Optional Parameter :  {0} ", t.OptionalParameter("One1", "Two1","Three1","Four1"));
  17.             Console.ReadLine();
  18.  
  19.         }
  20.  
  21.     }
  22.     public class OptionalParameterTest
  23.     {
  24.         public string OptionalParameter(string  one, string two = "Two",string three="Three",string four="Four")
  25.         {
  26.  
  27.            
  28.             return one + "  " + two + "  " + three + "  " + four;
  29.         }
  30.     }
  31.  
  32. }

Optional Parameters

WCF Messages

Applications written using Windows Communication foundation communicate through messages. WCF uses SOAP messages, formatted in XML as SOAP messages.

WCF Message

Lets discuss each of the section in detail

SOAP Envelope is outer most section of WCF message. It acts as a container for WCF header and body. A SOAP envelope contains several pieces of key information in the form of elements. They include the following:

  • The name of envelope
  • Namespace name : The namespace name must be “http://www.w3.org/2003/05/soap-envelope”.
                            • An optional <header> element: SOAP header is a collection of one or more than one header block. A SOAP message can contain zero or more than one header block. If a header is included, it must be the first child element of the envelope element. Header is  good place to put optional information related to message. Any child element of header element is called “Header Blocks”.  The following code sample illustrates the basic format for including a message header:
                              <env:Envelope xmlns:s=”http://www.w3.org/2003/05/soap-envelope” xmlns:a=”http://schemas.xmlsoap.org/ws/2004/08/addressing”>
                              <env:Header>
                              </env:Header>
                              </env:Envelope>
  • A required body element. : The SOAP body is a collection of data items to be used at a specific target (SOAP receiver). Like the SOAP header, a message can contain zero or more bodies.

WCF Messaging Programs

In WCF ,following type of applications can send and receive messages

  • Client: Client is a program that initiates a communication via sending a message
  • Service: Service is program that respond to a message. Service perform predefined activities once it receives a message. A service never initiates a communication. While processing request , if the service call some other services than this concept is called “Service chain”. Here the service is acting as client and service has initiated the communication in response to incoming message.

Messaging Patterns

Messaging patterns, basically describe how programs should exchange messages. There are three basic messaging patterns that programs can use to exchange messages. Those patterns include the following:

  • Simplex : The Simplex message pattern is simply a one-way communication from Program A to Program B. No response is generated by Program B, thus causing the one-way communication. Simplex messaging suffers from short term memory loss. When the client sends the message, it has no idea it sent a message because it is not expecting a response.
  • Duplex: In duplex pattern client and service programs communicate openly and exchange information in both directions.
  • Request-Reply: Request-Reply messaging pattern doesn’t allow bi-directional communication to happen freely. In this pattern, the client sends a response and then waits for reply. The service doesn’t communicate anything until it receives a message.

AppFabric Dashboard Overview

AppFabric has this great new Dashboard that gives you insight into what is happening with your services and workflows. In this video, Senior Programming Writer Michael McKeown shows you what the Dashboard can do for you.

Get Microsoft Silverlight

How to Run Java Apps in Windows Azure

A video is posted on MSDN showing how developers can use Windows Azure platform to run Java Applications. In the video, Scott Golightly creates a simple Java application that runs under Apache Tomcat, and then shows how that can be packaged up and deployed to the Windows Azure development fabric.

About this Video

Windows Azure in an open platform. This means you can run applictions written in .NET, PHP, or Java. In this video Scott Golightly will show how to create and run an application written in Java in Windows Azure. We will create a simple Java application that runs under Apache Tomcat and then show how that can be packaged up and deployed to the Windows Azure development fabric.

ADO.NET Data Services

WCF Data Services (formerly ADO.NET Data Services[1], codename "Astoria")[2] is a platform for what Microsoft calls Data Services. It is actually a combination of the runtime and a web service through which the services are exposed. In addition, it also includes the Data Services Toolkit which lets Astoria Data Services be created from within ASP.NET itself. The Astoria project was announced at MIX 2007, and the first developer preview was made available on April 30, 2007. The first CTP was made available as a part of the ASP.NET 3.5 Extensions Preview. The final version was released as part of Service Pack 1 of the .NET Framework 3.5 on August 11, 2008. The name change from ADO.NET Data Services to WCF data Services was announced at the 2009 PDC.