Skip to main content

Posts

Showing posts with the label c language programming tutorials

C program to calculate Gross Salary of an employee

Programming Languages Welcome to coding world Write a C program to calculate Gross Salary of an employee Write a C program by  https://houseofinformation31.blogspot.com/   to calculate Gross Salary of an employee. Here’s simple program to calculate Gross Salary of an employee in C Programming Language. Gross salary: We need to take input from user and then apply the simple formula to calculate the gross salary i.e. gross salary= basic salary+ dearness allowance+ house rent allowance. Below is the source code for C program to calculate Gross Salary of an employee which is successfully compiled and run on Windows System to produce desired output as shown below: SOURCE CODE: /*   C program to calculate Gross Salary of an employee   */ # include <stdio.h>   int main() {       char name[30];     float basic, hra, da, pf, gross;       printf("Enter name: ");     gets(name);       printf("Enter Basic Salary: ");     scanf("

C Program to find the sum of natural numbers using while loop

Programming Languages Welcome to coding world C Program to find the sum of natural numbers using while loop #include <stdio.h> int main() {     int n, count, sum = 0;       printf("Enter the value of n(positive integer): ");     scanf("%d",&n);       /* When you use while loop, you have to initialize the      * loop counter variable before the loop and increment      * or decrement it inside the body of loop like we did      * for the variable "count"      */     count=1;     while(count <= n){                 sum = sum + count;                 count++;     }       printf("Sum of first %d natural numbers is: %d",n, sum);       return 0; } Output:   Enter the value of n(positive integer): 7 Sum of first 7 natural numbers is: 28

C Program to find the Sum of First n Natural numbers

Programming Languages Welcome to coding world C Program to find the Sum of First n Natural numbers   Program to find the sum of first n natural numbers. We will see two C programs to calculate the sum of natural numbers. In the first C program we are using for loop for find the sum and in the second program we are doing the same using while loop. Program to find sum of natural numbers using for loop The user enters the value of n and the program calculate the sum of first n natural numbers using for loop.   #include <stdio.h> int main() {     int n, count, sum = 0;       printf("Enter the value of n(positive integer): ");     scanf("%d",&n);       for(count=1; count <= n; count++)     {         sum = sum + count;     }       printf("Sum of first %d natural numbers is: %d",n, sum);       return 0; } Output:   Enter the value of n(positive integer): 6 Sum of first 6 natural numbers is: 21

C Program to check Leap Year

Programming Languages Welcome to coding world C Program to check Leap Year    This program checks whether the input year is leap year or not. Example: Program to check Leap Year You can check whether a year is leap or not by using this mathematical logic: Leap Year: If a year is divisible by 4, 100 and 400 then it is a leap year. If a year is divisible by 4 but not divisible by 100 then it is a leap year Not a Leap Year: If a year is not divisible by 4 then it is not a leap year If a year is divisible by 4 and 100 but not divisible by 400 then it is not a leap year Let’s write this logic in a C Program. To understand this program you should have the knowledge of following C programming  topic: C Programming If..else, Nested if..else #include <stdio.h> int main() {     int y;       printf("Enter year: ");     scanf("%d",&y);       if(y % 4 == 0)     {             //Nested if else         if( y % 100 == 0)         {    

Hello World Program in C

Programming Languages Welcome to coding world Hello World Program in C H ere we will write two C programs to display Hello World on the screen. In the first program we are displaying the message using printf function and in the second program we are calling a user defined function and that function displays the Hello World message on the screen.   Example 1: Displaying Hello World #include <stdio.h> int main() {    /* printf function displays the content that is     * passed between the double quotes.     */    printf("Hello World");    return 0; } Output:   Hello World 1. #include <stdio.h> – This statement tells compiler to include this stdio.h file in the program. This is a standard input output file that contains the definitions of common input output functions such as scanf() and printf(). In the above program we are using printf() function.   2. int main() – Here main() is the function name and int is the return type of

Snake Game Proggramming code in C

Programming Languages Welcome to coding world Snake Game code in C #include <graphics.h> #include <stdio.h> #include <stdlib.h> #define T 2000 int n=0,px,py; main() {   int gd=DETECT,gm,i,j;   clrscr();   gotoxy(25,4);   printf("DON'T TUCH THE BORDER");   gotoxy(25,6);   printf("Press < p > for pause");   gotoxy(17,8);   printf("IN MIDDLE OF GAME, PRESS < Esc > TO EXIT");   x:   gotoxy(26,10);   printf("press < s > to start ");   gotoxy(26,12);   printf(" Use SMALL case only");   gotoxy(34,10);   if(getch()=='s')   initgraph(&gd,&gm,"c:\tc\bgi");   else {   clrscr();   goto x;   }   line(0,0,0,479);   line(0,0,639,0);   line(639,0,639,479);   line(0,479,639,479);   pause();   print();   right(100,100); }   right(int x,int y)   {   char ch,fu='r';   int i,j;   for(i=x;i<=652;i++){