Friday, November 21, 2014

C Basic pro



C program to read the values of x, y and z and print the results expressions in one line.

#include
#include
void main()
{
    int x, y, z;
    float a, b, c;
    clrscr();
    printf("\nEnter the values of x,y and z : ");
    scanf("%d %d %d", &x, &y, &z);
    a = (x + y + z) / (x - y - z);
    b = (x + y + z) / 3;
    c = (x + y) * (x - y) * (y - z);
    printf("\nValue of a = %f",a);
    printf("\nValue of b = %f",b);
    printf("\nValue of c = %f",c);
    getch();
}

Output

Enter the values of x,y and z : 1.1 2.5 5.5
Value of a = -1.000000
Value of b = 2010.000000
Value of c = 27939.000000

C program to reads customer number and power consumed and prints amount to be paid

#include
#include
 void main()
{
   int cust_no, powerUsage;
   float amount;
   clrscr();
   printf("Enter the customer number: ");
   scanf("%d", &cust_no);
   printf("Enter the power consumed: ");
   scanf("%d", &powerUsage);
   if (powerUsage >= 0 && powerUsage <= 200)
      amount = powerUsage * 0.50;
   else if (powerUsage > 200 && powerUsage < 400)
      amount = 100 + ((powerUsage - 200) * 0.65);
   else if (powerUsage > 400 && powerUsage <= 600)
      amount = 230 + ((powerUsage - 400) * 0.80);
   printf("Amount to be paid by customer no. %d is Rs.:%5.2f.", cust_no, amount);
   getch();
}

Output

Enter the customer number: 1
Enter the power consumed: 100
Amount to be paid by customer no. 1 is Rs.:50.00.

C Program to demonstrates binary expressions using floating-point arithmetic


#include
#include 
int main()
{
   float a = 14.0;
   float b = 5.0;
   printf("%f + %f = %f\n", a, b, a + b);
   printf("%f - %f = %f\n", a, b, a - b);
   printf("%f * %f = %f\n", a, b, a * b);
   printf("%f / %f = %f\n", a, b, a / b);
   return (0);
}

Output
14.000000 + 5.000000 = 19.000000
14.000000 - 5.000000 = 9.000000
14.000000 * 5.000000 = 70.000000
14.000000 / 5.000000 = 2.800000

C Program to demonstrates binary expressions using integer arithmetic


#include
#include
int main()
{
   int a = 5;
   int b = 5;
   printf("%d + %d = %d \n", a, b, a + b);
   printf("%d - %d = %d \n", a, b, a - b);
   printf("%d * %d = %d \n", a, b, a * b);
   printf("%d / %d = %d \n", a, b, a / b);
   printf("%d %% %d = %d\n", a, b, a % b);
   return(0);
}

Output
5 + 5 = 10
5 - 5 = 0
5 * 5 = 25
5 / 5 = 1
5 % 5 = 0

C Program to find greatest in 3 numbers


#include
#include
int main()
{
   int a, b, c;
   printf("\nEnter value of a, b & c : ");
   scanf("%d %d %d", &a, &b, &c);
   if ((a > b) && (a > c))
      printf("\na is greatest");
    if ((b > c) && (b > a))
      printf("\nb is greatest");
    if ((c > a) && (c > b))
      printf("\nc is greatest");
    return(0);
}

Output

Enter value for a,b & c : 15 17 21
c is greatest

C Program to calculate gross salary of a person


#include
#include 
int main()
{
   int gross_salary, basic, da, ta;
   printf("Enter basic salary : ");
   scanf("%d", &basic);
   da = (10 * basic) / 100;
   ta = (12 * basic) / 100;
   gross_salary = basic + da + ta;
   printf("\nGross salary : %d", gross_salary);
   return (0);
}

Output

Enter basic Salary : 1000
Gross Salart : 1220

No comments:

Post a Comment