Posts

Showing posts with the label CExamples

Differentiate and add the digits of three digit number

 Here, the code of differentiate and add the digits of a three-digit number entered by the user. Code: //The task is to add the digits of three digit number ,that is input by the user. #include <stdio.h> int main() { int a, b, c, d, e, sum = 0;  //variable declaration printf("Enter a three digit number:"); scanf("%d", &a); // The user input the 3 digit number b = a / 100; //first digit c = a % 100; //last 2 digits d = c / 10;  //middle digit e = c % 10;  //last digit sum = b + d + e; printf("\nThe indvidual digits are : %d\t%d\t%d", b, d, e); printf("\nThe sum is :%d\n", sum); //sum of 3 digits will appear on screen. getchar; return 0; }

Find the number is even or odd

Here,the code of finding the number is even or odd.For understand the following code first understand the following topics. output input operators Code:  //this task is to find the number is even or odd ,that is enter by the user #include <stdio.h> int main() { int a = 0; printf("Please enter the number\n"); scanf("%d", &a); if (a % 2 == 0)  //it means if the remainder come 0 after dividing by2 ,then it is even otherwise it is odd.  printf("\nThe number is Even.\n"); else printf("\nThe number is Odd.\n"); getchar; return 0; }

calculate the health allowance, house rent, and gross salary

  Here ,code of the calculation health allowance,house rent,and gross salary.For understanding this code you should learn first following topics. output input //caluculating health allownce,house rent ,Gross salary   Code #include <stdio.h> int main() { int x = 0, y = 0, z = 0,g=0;  // variable declaration  printf("Enter the Basic Salary\n"); scanf("   %d", &x);  // user input the basic salary printf("                      Salary Details                     \n"); y = (40 * x) / 100;  //to calculate the health allownce printf("     Basic Salary:                             Rs%d\n",x); printf("     Health Allownce:                          Rs%d\n", y); z = (20 * x) / 100;  //to calculate  the house rent printf("     House Rent:                               Rs%d\n", z); g = x + y + z;      //to calculate the gross salary printf("  ________________________________________________________