Programming Shortcut

Write, Run and execute Your programs with simple and esay way by Programming Shortcut

Thursday, April 18, 2019

What Are the Benefits of Java Programming?


Java is an object-oriented programming language. It is used in a variety of computing platforms, you can see it nearly everywhere nowadays, from embedded devices and mobile phones to enterprise servers and supercomputers. In the point of view of many IT experts, Java is a hot property of Sun Microsystem. Seriously speaking, JAVA has brought a lot of advantages to the software developers.

Is Java really great? Here are 7 good points to support.

1. It is simple.

This particular program is specially designed to be very user-friendly. If compared with other programming languages, Java is easier to write, compile, debug and learn. This is because it uses automatic memory management and garbage collection. New learners can apply it easily within a short period of time.

2. It is platform-independent

The best thing about Java is its ability to move easily from one computer system to another without creating any problem. "Write once, run anywhere" best describes Java. It can run independently at both the source and binary levels. The same program can be run smoothly on different systems. This special feature is extremely essential to World Wide Web software which needs a lot of flexibility.

3. It is secure

If security is your main concern, Java will be your best choice. It places security as its top priority. Its language, compiler, interpreter and runtime environment are customized with security in mind. Its platform allows users to download unknown code over a network and run it in a secure environment without causing harm to the systems. The host system will not be infected by virus at all. This capability alone has made the Java platform unique.

4. It is reliable

Honestly speaking, it is indeed hard to look for programming languages which are truly robust. However, Java has put a lot of effort on early checking for possible errors. Java compilers are able to detect many problems at the initial stage of execution. Hence, it is considered the most reliable programming by the developers.

5. It can perform multiple tasks 

Java has the capability to perform several tasks simultaneously. Multithreaded programming has been smoothly integrated into it. It works best in visual and network programming. At the same time, its stable standards help the developers to create multilevel applications with a component based approach.

6. It is dynamic

Java code is organized in modular object-oriented units. These units are known as classes. They are stored in separate files and are loaded into the Java interpreter only when required. In this situation, a program is able to extend itself dynamically by loading which classes it needs to expand its functionality.

7. It is economical 

How much do you need to invest on Java programming? It is an open source. Hence, you don't need to struggle with heavy license fees annually.

More Code »

Introduction of Java Programming Language


Java is a programming language developed by Sun Microsystems in 1995. It is designed to be platform independent. This means that the same program can run regardless of whether you use Windows, MacOS, Linux or a cell phone. To do this there must be a Java interpreter installed on the system where the program should run.
Java allows you to write programs without having to go out and buy something. It only requires some time and patience.
Java can be used for making interactive parts of web sites. It is known as applets. This may be small games or useful tools. Java should not be confused with JavaScript, which can also be used for websites. These are two different things.
Java games are used on many pages and are usually developed by professional programmers. It is also be possible to make a simple game if you are a hobby programmer. When I taught myself Java for a few years ago I made a little Java game to gain some practice in programming.
In this virtual world of an Internet Marketing, windfall profits have made the Java one of the fastest-growing and most extensively used programming language.

"Java" generally refers to a combination of three things:

Java programming language: It is a high-level, object-oriented programming language. Java is centered on creating & manipulating objects, and making the objects to work together.
Java Virtual Machine: Short for JVM, it is a high-performance virtual machine that executes byte codes on a specific computing platform.
Java platform: A JVM running compiled Java byte codes, usually calling on a set of standard libraries such as those provided by Java Standard Edition or Enterprise Edition . Though coupled by design, the language does not imply the JVM, and vice versa.

Java is a revolutionary language and so, for this reason, it is the most accepted computing language in use today for a wide-ranging purpose. Some of the substantial benefits of Java Programming language are:
Java is Architectural Neutral: Since Java's applications are typically piled-up to a byte-code and as its' integration is done into all the major operating system, so, for this reason, Java Program can be accessed on any platform with a Java Virtual Machine. Hence, one of the most compelling reason that persuade anyone to Java is its Portability, i.e. - Platform Independence and so developers will be just requiring for the writing of one version and that one version will be running on all the platforms without having to be recompiled. Java runs on most major hardware and software platforms, counting Windows 95 and NT, the Macintosh, and several varieties of UNIX as well.
Security: Language and platform were devised by maintaining the issue of security in mind. All browsers, whether it is a compiler, interpreter or Java-compatible, all hold a number of security measures. They are intended to diminish the risk of security compromise, loss of data and program integrity, and damage to system users. The Java platform allows a user to download an untrusted code over a network and run it in a secure environment as it will protect the host system to not to get infected with a virus.
Programmer Efficiency and Time-to-Market: The final and perhaps the most significant cause for taking the Java into a use is that it is well-liked by the programmers because with Java, they entertain a quick results and it makes their efficiency increase to the great extent. As Java is a simple and elegant language with a well-designed, intuitive set of APIs, programmers are able to write better code that too without shelling-out embarrassing amount of money. This thing reduces the development time.
Hence for these considerable benefits, Java is chosen as the programming language for the network computers (NC) and has been perceived as a universal front end for the enterprise database.

More Code »

Wednesday, April 17, 2019

How to start learning first programming language

Introduction

When we start to learn your first programming language, we have many questions like how to start your first programming language and what we need to start your programming language and what language is better to start. Programming is a very useful and rewarding hobby. There are few better feelings than when someone sees you using a program you lashed together to make your life easier and says that it looks really useful. Most people have, at some point in their lives, really wanted to be able to do something on their computer or phone and been unable to. If you know a programming language, then there is often a fair chance that you can write a program to accomplish that task yourself. While there are a huge number of programming languages, many of them have a lot of similarities; this means that once you learn one language quite well, in most cases you will be able to pick up a new one far quicker.

Selecting Your First Language

Now that we have examined the limitations and handled some of the more unrealistic expectations, those of you still wanting to learn to code will be happy to know that programming is not a hard thing to start learning and will not require you to pay out huge sums of money. If you are reading this article online, you already have the resources to start with some languages, so let us consider what your first language ought to be.

Traditionally the first language a programming newcomer learns is either Visual Basic or Python. The first thing to understand is that these two languages are very different. The simplest difference is one of price. Python is totally free; you can start writing python now with just a text editor on your computer, though if you are on Windows, you will probably need to install it first. However, Visual Basic, often abbreviated to VB, is both free and not free. On the upside, VB can be simpler for newcomers to learn because it allows you to build the interfaces (the part of the program the user will see) by dragging and dropping the different parts much like designing it in some basic art application. The version of VB newcomers learn is usually Visual Basic 6, but this is rather outdated and has been discontinued. So these days the version learned is often VB.NET which can be considerably less simple for newcomers.

VB.NET must be developed inside what we call an IDE (Integrated Development Environment); this is basically a special program you use to write other programs. They also exist for Python, but their use is totally optional. The free VB.NET IDE is called Visual Studio Express. At the time of writing, the latest version is Visual Studio Express 2010. Unfortunately, by using the free version of the IDE you are restricted with what you can do, and any programs you create cannot be commercially sold on. Regretfully, the full paid version of the IDE is not cheap, and probably not appropriate for a hobbyist, but fortunately, to learn VB the free version is enough. In practice, very few commercial programs are developed in VB these days, but the Visual Studio IDE allows you to use many other languages. The familiarity you will develop by using it will also allow you to use the power of the IDE for development in many other languages. Some will argue that almost every language can be developed in a text editor and that they are by far the most flexible way in which to code. While this is technically true (and I do suggest trying development in a text editor to compare once you get a little better), I would strongly advise learning your first language with a proper IDE.

While traditionally, people learn Python or VB first and these are generally what is taught at schools, I would not suggest either of these. I am of the opinion that your first language should continue to be useful to you one it has served the purpose of helping you learn the fundamentals of programming. If I had to recommend one of these for newcomers, it would be VB.NET as often the most complex part of programming is the graphical side of things and in VB.NET this is very simple due to the drag and drop interface. These two languages are often used as introductions as they are very tolerant of mistakes, and allow you to become confident in programming principles without worrying about a lot of the more complex matters.

For those brave souls among you, I would actually suggest Java as your first language, even though it can be complex, and is therefore not a common choice for a first language. Java programs are different from most others in that they do not run on your computer. The user downloads Java, then your code runs on what is called a VM (Virtual Machine). This means that your code runs in a special place Java sets up for it - a fake copy of your computer - and handles the translation of this to the real machine for you. This means that Java programs are "cross-platform", meaning that they will, for the most part, run on Windows, Mac, Linux, and most other operating systems.

Java is a good language to learn, as it is very widespread and useful. Furthermore, it is very powerful and is available for free for both hobbyists and commercial uses. However, in contrast to VB and Python, it does not tolerate mistakes and requires you to be very specific about everything. It is also an object-oriented programming language, which is a very complex issue which I will briefly try to summarise. Languages like Python and VB are what is known as procedural languages, meaning that the lines of code are run one after another, whereas Java is an object-oriented language. object-oriented development is a term thrown around a lot these days in the programming world, and while not always appropriate it is generally considered a good idea. At the most basic level, an object-oriented program is all about objects. An object is an "instantiation" of a "class". A class is a blueprint used to describe something like a cat. The class contains both the data about the cat such as its name, age and owner as well as "methods" which are essentially actions the cat can perform, such as miaow. An instance of the class "cat" would give you a particular cat. However, this is not a Java tutorial, so if you are brave enough to experiment with Java you will come across this yourself in more detail. It is worth noting that VB.NET and Python both have support for object-oriented development, and Java has the potential to be used procedurally, but these are not the languages' primary intended uses and are not often used. If you did not understand that comparison, don't worry about it too much. Object orientation is hard to get your head around, but any basic Java or another object-oriented language tutorial will have you understanding everything in that paragraph.

A final reason Java is a good first language is that it is similar in many ways to Javascript, which is an entirely different class of language. Javascript is a scripting language (as is Python), and learning Java will mean you understand Javascript reasonably well. The difference is between scripting languages and normal programming languages are outside the scope of this article, but as large generalization scripts are generally used for automated tasks while programs are used interactively by users. This is not totally true, as both types of language are used for both tasks and most web programs are built in Javascript.

As for the actual language you pick, it is entirely up to you. Some may choose the traditional beginner languages or be brave and experiment with Java. Some of you may already have your eye on a language or fancy one of the more specialist languages like Scheme or Prolog. Whatever your choice, the way you will learn how to program is the same.


What IDEs ( Integrated Development Environment ) is best?

Many of the purists say that IDEs are a bad idea, and are packed with unnecessary tools and menus that take up disk space and time to learn. While this is true, I feel that an IDE is definitely worthwhile. Many people offer free IDEs, such as Eclipse and Netbeans, for the more popular languages. There is also Visual Studio, which I mentioned previously; it is very intuitive, very powerful and it supports many languages (much as Netbeans and Eclipse do). If you chose to use Java I would suggest Netbeans, as there is a packaged version of Netbeans with the JDK (Java Development Kit). Most languages need an SDK (Software Development Kit) to work with them, and getting it installed properly and linked to the IDE is often the hardest part of the procedure. Visual Studio already comes with the development kits set up, which makes life easier, but other languages like Java and Python can be quite hard to set up properly. This is why I suggested the Netbeans + JDK bundle for those experimenting with Java, as it handles the complex set up for you, which will save you hours of suffering.

There are, in my opinion, three major advantages to using a fully featured IDE. Firstly, they are usually extensible, meaning that there are many free plug-ins that could make your life a lot easier when you get a little more advanced. Secondly, and most importantly, is the ease with which an IDE allows you to debug your code. Most IDEs let you set breakpoints in the code, which will make the program stop when it gets to that point and let you step through it line by line so you can examine the contents of all the variables at any time. (For those of you who do not know what a variable is, I will briefly explain. A variable is a bit like a train station locker. You ask for one big enough to hold what you want to store, and if what you want to store is the right shape, it can be stored there. When you write a program, any data you want to store temporarily will be held in one of these until you are done with it.) As the old programming saying goes, if you have not found any bugs, you are not looking hard enough. Almost no non-trivial program will work the first time, and trying to work out where the problem lies without the use of a debugger is a pain I would not wish on anyone. Finally, an IDE will often give you advice on how to fix issues in the code. This can be very useful for fixing bugs and saves you having to resort to Google every other minute.

Learning Another Language

Once you have learned one language, whatever it may be, the most valuable thing you will have learned is all the keywords for searches. When you want to do something in a new language, you need only search for what you want to do and the language name. However, by now you will know the names used to refer to what you want to do, allowing your searches to be more effective and yield examples and answers much more quickly. As the fundamentals of programming are mostly the same, regardless of the language you use, you will hopefully be able to guess at the meaning of most of the code much more effectively once you locate an example, allowing you to pick up most of the language very quickly indeed.

Limits

One thing that all new programmers must come to term with is the amount of time learning a programming language takes. Although when you have become an expert you will be able to write many programs quickly, you must remember that many programs have taken whole teams of expert developers years to create. So it is important to understand that knowing a programming language or even several is not enough to write some of the more complex programs you have seen. Don't look upon this new hobby as a way to save yourself a lot of money, as writing your own version of most of the programs that you need to pay for now will be out of your reach.

The most important thing that a new programmer needs to know is that the "Learn Programming in 24 hours" sort of books is simply not true. A more accurate title would be "Learn Programming in 10,000 hours". If you put 24 hours or a week into learning a language you will not be creating the next Windows or a new, state of the art game. It is possible to learn to write a program in 10 minutes, and really all you need to learn a new language is your favorite search engine, but you will not be an expert. The only way to become an expert is much like learning the violin; the answer is practice, practice, and practices some more.

Practice makes a man perfect
More Code »

Friday, February 15, 2019

Program to check a letter is vowel or consonant in java


Hello Friends! Welcome to programming shortcut
Today will discuss:
--> Program to find whether the alphabet is a vowel or consonant  in java or
--> java program to check vowel or consonant using a switch or
--> program to check an alphabet is a vowel or consonant in java or
--> Program to find whether the letter is a vowel or consonant  in java or
--> program to check a letter is a vowel or consonant in java


import java.util.Scanner;
public class Check_letter_to_vowel_or_consonant {
    public static void main(String[] args) {
       String ch;
       Scanner c = new Scanner(System.in);
       System.out.println("Enter letter to check vowel or consonant:");
       ch = c.next();
       switch(ch){
           case "a":
           case "e":
           case "i":
           case "o":
           case "u":
           case "A":
           case "E":
           case "I":
           case "O":
           case "U":
           System.out.println("The alphabet is a vowel");
           break;
           default:
           System.out.println("The alphabet is a consonant");
       }
    }
}



Output:

   First, run:
   Enter letter to check vowel or consonant:
   a
   The alphabet is a vowel

   Second-time run:
   Enter the alphabet :
   d
   The alphabet is a consonant

Explanation: In this programming, we use the Switch case to check an alphabet or a letter is a vowel or consonant


Hello, Friend We first write the program and compile them and run the program to check compiler error or run time error.
Please share the site and comment on your ideas and your suggestions. All suggestion was all welcome.
If any question or doubt in the programming please mention the comment.
Thank yours very much. 
More Code »

Monday, February 4, 2019

Decimal to binary in java with explanation

Hello Friends! Welcome to Programming Shortcut only programming,
Today we'll discuss how to convert a decimal to binary in java. there are two methods to convert decimal to binary:

1. Decimal to binary in java with array using while loop,

2. Decimal to binary in java without array using while loop.


Decimal to binary in java


import java.util.Scanner;
public class DecimaltoBinary  {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int a[] = new int[1000];
        System.out.println("Enter a Decimal number to convert binary");
        int decimalnum = in.nextInt();
        int temp = decimalnum; //the taken number to save take temp variable.
        int n = 0;
        while (temp > 0) { // checking the number to till '0'
            int rem = temp % 2; // taking remainder of number
            temp = temp / 2; // after taking remainder update the number
            a[n] = rem;  // store the remainder into a array
            n++;
        }

//print the array in reverse order
        System.out.print("The binary of " + decimalnum + " is: ");
        for (int i = n - 1; i >= 0; i--) {
            System.out.print(a[i]);
        }
        System.out.println("\n");
    }
}

Output:
Enter a Decimal number to convert binary
23
The binary of 23 is: 10111


Decimal to binary in java without array


import java.util.Scanner;
public class DecimaltoBinary  {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        System.out.println("Enter a Decimal number to convert binary");
        int num = input.nextInt();
        int n = num;
        String temp = "";
        while (n > 0) {
            int rem = n % 2;
            n = n / 2;
            temp = temp + rem;
        }
        String bin = new StringBuffer(temp).reverse().toString();

        System.out.println("The binary number of " + num + " is: " + bin);
    }
}

Output:
Enter a Decimal number to convert binary
24
The binary number of 24 is: 11000

Note: if adding in the String value store in the last of string value

 For example:
 String frist= "Programming";
 String last="Shortcut";
 String name= frist+last;
 System.out.println(name);

 output: ProgrammingShotcut

I make this programming and hope you are like the post if are you like the post you can please comment and Share the post to reach more people.
If any doubt about this java programming code or input & output please comment below
If you have another question about java programming send an email by contacting us form are given on the page right side.
I am Try to Help in your Programming Language by Programming Shortcut

Please share your experience about this post,
Thank You!
More Code »

program to check a alphabet is vowel or consonant in c++

Hello Friends! Welcome to programming shortcut
Today will discuss:
--> Program to find whether the alphabet is a vowel or consonant  in c++ or
--> c++ program to check vowel or consonant using a switch or
--> program to check an alphabet is a vowel or consonant in c++


#include <iostream>
using namespace std;
int main(){
 char ch;
 cout<<"Enter an alphabet :"<<endl;
 cin>>ch;
 switch(ch)
 {
  case 'a':
  case 'e':
  case 'i':
  case 'o':
  case 'u':
  case 'A':
  case 'E':
  case 'I':
  case 'O':
  case 'U':
   cout<<"Alphabet is a vowel"<<endl;
   break;
  default:
   cout<<"Alphabet is a consonant";
 }
 return 0;
}



Output:

   First, run:
   Enter the alphabet :
   a
   The alphabet is a vowel

   Second-time run:
   Enter the alphabet :
   d
   The alphabet is a consonant

Explanation: In this programming, we use the Switch case to check an alphabet is a vowel or consonant


Hello, Friend We first write the program and compile them and run the program to check compiler error or run time error.
Please share the site and comment on your ideas and your suggestions. All suggestion was all welcome.
If any question or doubt in the programming please mention the comment.
Thank yours very much. 
More Code »

Program to find whether the alphabet is a vowel or consonant

Hello Friends! Welcome to programming shortcut
Today will discuss:
--> Program to find whether the alphabet is a vowel or consonant or
--> c program to check vowel or consonant using a switch or
--> program to check an alphabet is a vowel or consonant


#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
printf("Enter an alphabet : \n");
scanf("%c",&ch);
switch(ch)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
 case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
printf("Alphabet is a vowel\n");
break;
default:
printf("Alphabet is a consonant\n");
}
getch();
}


Output:

   First, run:
   Enter the alphabet :
   a
   Alphabet is a vowel

   Second Time run:
   Enter the alphabet :
   d
   Alphabet is a consonant

Explanation: In this programming, we use the Switch case to check an alphabet is a vowel or consonant


Hello, Friend We first write the program and compile them and run the program to check compiler error or run time error.
Please share the site and comment on your ideas and your suggestions. All suggestion was all welcome.
If any question or doubt in the programming please mention the comment.
Thank yours very much. 
More Code »

Short name by java program

Hello Friends, Welcome to my blog

Today will write a program to the short name by java program, this problem is also asking in many ways they are following:
 1. Java Program to Convert a Person Name in Abbreviated.
 2. wap to print the short name of the user.
 3. Java program to convert full name to short name.
 4. Java program to a short name.
 5. Abbreviation of Java programming language.

 Problem:-
    Enter Name: Anant Deep Vishwakarma
        Output: A. D. Vishwakarma

 Solutions:-
    1. Store Name in a name String.
    2. Split Name String and Store to a temp string array.
    3. Find temp string array length store value in other variables.
    4. Take a loop to store all value to expect the last name and print the first character by value with
       dot or abbreviation.
    5. then print the last value of temp string all Character

 Explain:
    For example a store name 'Anant Deep Vishwakarma'in a name string and then split value into temp string array as temp[0]='Anant', temp[1]='Deep' and temp[2]='Vishwakarma', after that count length of temp string array and use loop to left the last index value last name 'Vishwakarma', in loop print first char of every index value within loop. in the last print last index of program

Best java program example:

    import java.util.*;
    class SName
    {
     public static void main(String[] args)
        {
            String n;
            Scanner c=new Scanner(System.in);
            System.out.print("Enter the user name:");
            n=c.nextLine();
            String [] t=n.split(" ");
            int l=t.length;
            System.out.print("Your Short name:");
            for(int i=0;i<l-1;i++)
            {
                System.out.print(t[i].charAt(0)+".");
            }
            System.out.print(t[l-1]);
         }
    }
     
I hope you understand the program is any query please comment below your query I reply your questions soon.
Bye..
       
More Code »

Java program to perform sum of digits until single digit is obtained

 Hello Friends!
 Today will discuss do while loop with an example, how to make a program in java by do-while loop, do while loop in java program an example with explanation.
 Write a program in java to find the sum of digits of a number until the sum is reduced to 1 digit.
 For example:
  The number is 538769.
  Then 5+3+8+7+6+9=38
  3+8=11
   11=2

Finding sum of digits of a number until sum becomes single digit java program


import java.util.Scanner;
public class do_while {
   public static void main(String[] args){
    long num,dig,sum;
    Scanner in =new Scanner(System.in);
System.out.print("Enter a number :");
    num=in.nextLong();
    System.out.println("");
System.out.print(num);
do{
        sum = 0;
        while(num!=0)
{
dig=num%10;
            sum+=dig;
            num/=10;
}
        System.out.print("->"+sum);
        num=sum;
}while(num/10!=0);
   }
}
Output: Enter a number : 538769
        538769->38->11->2

Explanation :

    do{
/* 1: program code */
}while(num/10!=0);
        The Above Condition is not exited while a number is more than one digit.
     
/* 1: program code */
while(num!=0)
{
dig=num%10;
sum+=dig;
num/=10;
}
     Here we use program code to find a sum of digit then the given program exapmle is for "Sum of digits of a number until the sum is reduced to 1 digit"

So we find Your Program

I make this programming and hope you are like the post if are you like the post you can please comment and Share the post to reach more people.
If any doubt about this java programming code or input & output please comment below
If you have another question about java programming send an email by contacting us form are given on the page right side.
I am Try to Help in your Programming Language by Programming Shortcut

Please share your experience about this post,
Thank You!
More Code »

Sum of digits of a number until the sum is reduced to 1 digit in c++

 Hello Friends! Welcome to Programming Shortcut
Today will discuss do while loop with an example, how to make a program in c++ by the do-while loop, do while loop in c++ with an example with explanation.
 Write a program in c++ to find the sum of digits of a number until the sum is reduced to 1 digit.
 For example
  The number is 538769.
  Then 5+3+8+7+6+9=38
            3+8=11
            11=2

Sum of digits of a number until the sum is reduced to 1 digit in c++ program

#include <iostream>
using namespace std;
int main()
{
long num,dig,sum;
cout<<"Enter a number :"<<endl;
cin>>num;
cout<<num<<endl;
do{
sum = 0;
while(num!=0)
{
dig=num%10;
sum+=dig;
num/=10;
}
cout<<"->"<<sum<<endl;
num=sum;
}while(num/10!=0);  /*while num is more than one digit*/
return 0;
}

Output: Enter The number 538769
            538769->38->11->2

Explanation :

      do{
/* 1: program code */
}while(num/10!=0);

                The Above Condition is not exit while num. is more than one digit.
     
/* 1: program code */
while(num!=0) 
{
dig=num%10;
sum+=dig;
num/=10;
}

     Here we use program code to find a sum of digit then the given program example is for "Sum of digits of a number until the sum is reduced to 1 digit"

So we find Your Program what we want. 

I make this programming and hope you are like the post if are you like the post you can please comment and Share the post to reach more people.
If any doubt about this c programming code or input & output please comment below
If you have another question about c programming send an email by contacting us form are given on the page right side.
I am Try to Help in your Programming Language by Programming Shortcut

Please share your experience about this post,
Thank You!
More Code »

Sum of digits of a number until the sum is reduced to 1 digit in c

 Hello Friends!
 Today will discuss do while loop with the example, how to make a program in c by a do-while loop,   do while loop in c programming example with explanation and how to make c program to Sum of digits of a number until the sum is reduced to 1 digit. Nested Loop in c program
 Write a program in c to find the sum of digits of a number until the sum is reduced to 1 digit.
 For example: 
 The number is 538769.
 Then 5+3+8+7+6+9=38
          3+8=11
          11=2

Sum of digits of a number until the sum is reduced to 1 digit in c program

#include<stdio.h>
int main(void)
{
long num,dig,sum;
printf("Enter a number : ");
scanf("%ld",&num);
printf("\n%ld",num);
do{
sum = 0;
while(num!=0)
{
dig=num%10;
sum+=dig;
num/=10;
}
printf("->%d",sum);
num=sum;
}while(num/10!=0);  /*while num is more than one digit*/
return 0;
}

Output: Enter The number 538769
              538769->38->11->2


Explanation :

      do{
/* 1: program code */
}while(num/10!=0);
The Above Condition is not exit while num. is more than one digit.
      
 /* 1: program code */
while(num!=0) 
{
dig=num%10;
sum+=dig;
num/=10;
}
Here we use program code to find a sum of digit then the given program example is for "Sum of digits of a number until the sum is reduced to 1 digit"

So we find Your Program what we want. 

I make this programming and hope you are like the post if are you like the post you can please comment and Share the post to reach more people.
If any doubt about this c programming code or input & output please comment below
If you have another question about c programming send an email by contacting us form are given on the page right side.
I am Try to Help in your Programming Language by Programming Shortcut

Please share your experience about this post,
Thank You!
More Code »

Programming Shortcut

Programming Shortcut is collections in java best programs with example, best c programs with example and best c++ programs with example, best way to learn java, c and c++

About Programming Shortcut

This is a programming learning website that can help you learn and when your write your programming code. And all programming code is compiled run programming code in the following programming language C, c++, Java, php and Javascript Languages. find your programming read, understand the programming then copy and past and run your program and save your golden time to typing the program becuse you learn more in leas time. All Programming is codeing is ease to understand the programming