Skip to main content

Posts

switch statement in C,sample programs and programs to try

There is one potential problem with the if-else statement which is the complexity of the program increases whenever the number of alternative path increases. If you use multiple if-else constructs in the program, a program might become difficult to read and comprehend. Sometimes it may even confuse the developer who himself wrote the program. The solution to this problem is the switch statement. A switch statement is used for multiple way selections that will branch into different code segments based on the value of a variable or expression. This expression or variable must be of integer data type. Syntax: switch (expression) { case value1:                   code segment1;                   break; case value2:                  code segment2;                  break; case valueN:                  code segmentN;                  break; default:                 default code segment; } The value of this expression is either generated duri

Structure of a C program

Lets understand the  basic structure of a C program. A C program is divided into different sections. There are six main sections to a basic c program. The six sections are, Documentation Include/Link/Preprocessor     section Definition Global Declarations ( Functions and variables) Main function Subprogram functions     Now let us learn about each of this layer in detail. Figure: Basic Structure Of C Program Sample Program The C program here will find the area of a circle using a user-defined function and a global variable PI holding the value of pi /* File Name: areaofcircle.c Author: Abhijith date: 06/05/2021   description: a program to calculate area of circle user enters the radius */ #include<stdio.h>   //link section #define PI   3.14;//definition section float area(float r);//global declaration /****************************/ int main()//main function { float r; printf(" Enter the radius:\n"); scanf("%

Beginning with C programming

Beginning with C programming: Finding a Compiler: Before we start C programming, we need to have a compiler to compile and run our programs. There are certain online compilers like http://ideone.com/ or https://www.onlinegdb.com/online_c_compiler that can be used to start C programming without installing a compiler. Windows: There are many compilers available freely for compilation of C programs like Code Blocks and Dev-CPP. Borland C( https://developerinsider.co/download-and-install-borland-c-compiler-on-windows-10/ ), Turbo C ( https://developerinsider.co/download-turbo-c-for-windows-7-8-8-1-and-windows-10-32-64-bit-full-screen/ ) etc Linux: For Linux, gcc comes bundled with the linux, Code Blocks can also be used with Linux. This Blog has been written based on Linux and all the given examples have been compiled on the Ubuntu flavor of the Linux system.If you are using Linux or UNIX, then check whether GCC is installed on your system by entering the following command from the comma

Basic Linux Commands

Basic Linux Commands for Beginners Linux is an Operating System’s Kernel. You might have heard of UNIX. Well, Linux is a UNIX clone. But it was actually created by Linus Torvalds from Scratch. Linux is free and open-source, that means that you can simply change anything in Linux and redistribute it in your own name! There are several Linux Distributions, commonly called “distros”. A few of them are: Mint Ubuntu Linux Red Hat Enterprise Linux Debian Fedora Kali Linux is Mainly used in Servers. About 90% of the Internet is powered by Linux Servers. This is because Linux is fast, secure, and free! The main problem of using Windows Servers are their cost. This is solved by using Linux Servers. Forgot to mention, the OS that runs in about 80% of the Smartphones in the World, Android, is also made from the Linux Kernel. Yes, Linux is amazing! A simple example of its security is that most of the viruses in the world run on Windows, but not on Li