let c program




                 











(a) Ramesh's basic salary is input through the keyboard. His dearness allowance is 40% of basic salary, and house rent allowance is 20% of basic salary. Write a program to calculate his gross salary.

#include<stdio.h>
float BASI , DA, HRA, GS ;
void main()
{
    clrscr();
    printf("Enter BASIC salary: ");
    scanf("%f",&BASIC);
    DA = BASIC*0.4;
    HRA = BASIC*0.2;
    GS = BASIC + DA + HRA;
    printf("\nGross Salary = %f",GS);
}


——————————————————————————————————————————————————

(b) The distance between two cities (in km.) is input through the keyboard. Write a program to convert and print this distance in meters, feet, inches and centimeters.

#include<stdio.h>
float dist,meter,cm,feet,inch,mile,yard,nm;
void main()
{
    clrscr();
    printf("\nEnter distsnce b/w cities in Km: ");
    scanf("%f",&dist);

    meter=dist*1000;
    cm=dist*1000000;
    feet=dist*3280.84;       // 1Km = 3280.84feet
    inch=feet*12;               // 1foot = 12inch
    mile=dist*0.621371;    // 1Km = 0.621371miles
    yard=dist*1093.61;     // 1Km = 1093.61yards
    nm=dist*0.539957;     // 1Km = 0.539957 Nautical miles

    printf("\n%0.2f Km = %0.2f meter",dist,meter);
    printf("\n%0.2f Km = %0.2f centimeter",dist,cm);
    printf("\n%0.2f Km = %0.2f feet",dist,feet);
    printf("\n%0.2f Km = %0.2f inches",dist,inch);
    printf("\n%0.2f Km = %0.2f miles",dist,mile);
    printf("\n%0.2f Km = %0.2f Yards",dist,yard);
    printf("\n%0.2f Km = %0.2f Nautical Miles",dist,nm);
}


——————————————————————————————————————————————————

(c) If the marks obtained by a student in five different subjects are input through the keyboard, find out the aggregate marks and percentage marks obtained by the student. Assume that the maximum marks that can be obtained by a student in each subject is 100.

#include<stdio.h>
float sub1,sub2,sub3,sub4,sub5,sum,perc;
void main()
{
    clrscr();
    printf("Enter marks obtained in 5 subjects (separated by space): ");
    scanf("%f%f%f%f%f",&sub1,&sub2,&sub3,&sub4,&sub5);
    sum=sub1+sub2+sub3+sub4+sub5;
    perc=sum/5;
    printf("\nAggregate marks = %0.2f",sum);
    printf("\nPercentage marks obtained = %0.2f%",perc);
}


——————————————————————————————————————————————————

(d) Temperature of a city in Fahrenheit degrees is input through the keyboard. Write a program to convert this temperature into Centigrade degrees.

#include<stdio.h>
float C,F,K;
main()
{
    clrscr();
    printf("Enter temperature of city in fahrenheit: ");
    scanf("%f",&F);
    C=(F-32)*5.0/9.0;    // Celcius calculation
    K=C+273.15;           // Kelvin calculation
    printf("\nTemp in Centigrade = %0.2f C",C);
    printf("\nTemp in Kelvin = %0.2f K",K);
}


——————————————————————————————————————————————————

(e) The length & breadth of a rectangle and radius of a circle are input through the keyboard. Write a program to calculate the area & perimeter of the rectangle, and the area & circumference of the circle.

#include<stdio.h>
#define PI 3.14    // Macro for Pi value
float L, B, R, Area_Rect, Peri_Rect, Area_Circ, Circum_Circ;
void main()
{
    clrscr();
    printf("\nEnter Length of Rectangle: ");
    scanf("%f",&L);
    printf("\nEnter Breadth of Rectangle: ");
    scanf("%f",&B);
    Area_Rect = L*B;
    Peri_Rect = 2*(L+B);
    printf("\nArea of Rectangle = %0.2f",Area_Rect);
    printf("\nPerimeter of Rectangle = %0.2f",Peri_Rect);
   
    printf("\nEnter Radius of Circle: ");
    scanf("%f",&R);
    Area_Circ = PI*R*R;
    Circum_Circ = 2*PI*R;
    printf("\nArea of Circle = %0.2f",Area_Circ);
    printf("\nCircumference of Circle = %0.2f",Circum_Circ);
}

——————————————————————————————————————————————————

(f) Two numbers are input through the keyboard into two locations C and D. Write a program to interchange the contents of C and D.

#include<stdio.h>
int C,D,X;
void main()
{
    clrscr();
    printf("\nEnter Number 1: ");
    scanf("%d",&C);
    printf("\nEnter Number 2: ");
    scanf("%d",&D);
    printf("\nBefore Interchange");
    printf("\nC = %d, D = %d",C,D);

    /* method 1: Using 3rd variable */
    X=C;
    C=D;
    D=X;
    printf("\nAfter Interchange (Using 3rd variable)");
    printf("\nC = %d, D = %d",C,D);

    /* method 2: Without using 3rd variable */
    C=C+D;
    D=C-D;
    C=C-D;
    printf("\nAfter Interchange(without using 3rd variable)");
    printf("\nC = %d, D = %d",C,D);
}


——————————————————————————————————————————————————

(g) If a five-digit number is input through the keyboard, write a program to calculate the sum of its digits.
(Hint: Use the modulus operator ‘%’)


#include<stdio.h>
long num=0,rem=0,sum=0,temp;
void main()
{
    clrscr();
    printf("\nEnter any 5 digit no. ");
    scanf("%ld",&num);
    if(num<100000)
    {
        temp=num;
        while(temp)
        {
            rem = temp % 10;
            sum = sum + rem;
            temp = temp/10;
        }
        printf("sum of digits of %ld is : %ld",num,sum);
    }
    else
        printf("\nYou entered bigger number");
}


——————————————————————————————————————————————————

  
(h) If a five-digit number is input through the keyboard, write a program to reverse the number.

/************* 1st approach: using arithmetic's *************/
#include<stdio.h>
long num,rem,sum=0,temp;
void main()
{
    clrscr();
    printf("\nEnter the 5 digit no. ");
    scanf("%ld",&num);
    temp=num;
    if(temp>9999 && temp<100000)
    {
        printf("Reverse of %ld is: ",num);
        while(temp)
        {
            rem = temp % 10;
            temp = temp/10;
            printf("%ld",rem);
        }
    }
    else
        printf("\nYou entered wrong number");
}

/************* 2nd approach: using string operations *************/ 
#include<stdio.h>
#include<string.h>    // Header file containing String functions
int num[5];
void main()
{
    clrscr();
    printf("Enter a 5-digit No. ");
    scanf("%s",num);
    printf("Reverse of %s is ",num);
    printf("%s",strrev(num));
}


——————————————————————————————————————————————————
 



(i) If a four-digit number is input through the keyboard, write a program to obtain the sum of the first and last digit of this number.

#include<stdio.h>
int num,rem,sum=0,temp;
void main()
{
    clrscr();
    printf("\nEnter the 4 digit no. ");
    scanf("%d",&num);
    temp=num;
    if(num<10000 && num>999)
    {
        rem = temp % 10;
        while(temp>9)
        {
            temp = temp/10;
        }
        sum = rem + temp;
        printf("\nSum of 1st & last digit of %d is %d",num,sum);
    }
    else
        printf("\nYou entered wrong number");
}


——————————————————————————————————————————————————

(j) In a town, the percentage of men is 52. The percentage of total literacy is 48. If total percentage of literate men is 35 of the total population, write a program to find the total number of illiterate men and women if the population of the town is 80,000.

#include<stdio.h>
long TOT_POP=80000,MEN,WOMEN,TOT_LIT,LIT_MEN,LIT_WOMEN,ILLIT_MEN,ILLIT_WOMEN;
void main()
{
    clrscr();
    MEN = TOT_POP*0.52;
    WOMEN = TOT_POP - MEN;
    TOT_LIT = TOT_POP*0.48;
    LIT_MEN = TOT_POP*0.35;
    ILLIT_MEN = MEN-LIT_MEN;
    LIT_WOMEN = TOT_LIT - LIT_MEN;
    ILLIT_WOMEN = WOMEN - LIT_WOMEN;
    printf("Total MEN = %ld",MEN);
    printf("\nTotal WOMEN = %ld",WOMEN);
    printf("\nTotal literate MEN = %ld",LIT_MEN);
    printf("\nTotal literate WOMEN = %ld",LIT_WOMEN);
    printf("\nTotal illiterate MEN = %ld",ILLIT_MEN);
    printf("\nTotal illiterate WOMEN = %ld",ILLIT_WOMEN);
}


——————————————————————————————————————————————————


(k) A cashier has currency notes of denominations 10, 50 and 100. If the amount to be withdrawn is input through the keyboard in hundreds, find the total number of currency notes of each denomination the cashier will have to give to the with-drawer.

#include<stdio.h>
long amt, note_100, note_50, note_10;
void main()
{
    clrscr();
    printf("\nEnter amount to be withdrawn in multiple of 100:  ");
    scanf("%ld",&amt);
    if(amt%10 != 0)
        printf("Amount is not multiple of 100");
    else
    {
        while(amt)
        {
            if(amt>=100)
            {
                note_100=amt/100;
                amt=amt%100;
            }
            else if(amt>=50)
            {
                note_50=amt/50;
                amt=amt%50;
            }
            else
            {
                note_10=amt/10;
                amt=amt%10;
            }
        }
        printf("\nDenomination 100 = %ld\nDenomination 50  = %ld\nDenomination 10  = %ld",note_100,note_50,note_10);
    }
}


——————————————————————————————————————————————————


(l) If the total selling price of 15 items and the total profit earned on them is input through the keyboard, write a program to find the cost price of one item.

#include<stdio.h>
double TOT_S,TOT_P,S,P,C;
void main()
{
    clrscr();
    printf("Enter Total Selling price of 15 items:Rs");
    scanf("%lf",&TOT_S);
    printf("Enter Total profit earned on 15 items:Rs");
    scanf("%lf",&TOT_P);
    S = TOT_S/15;     // selling price of 1 item
    P = TOT_P/15;    // profit behind 1 item
    C = S - P;             // cost of 1 item
    printf("Cost of 1 item = Rs%0.2lf",C);
}



——————————————————————————————————————————————————


(m) If a five-digit number is input through the keyboard, write a program to print a new number by adding one to each of its digits. For example if the number that is input is 12391 then the output should be displayed as 23402.

#include<stdio.h>
long num,rem,new_rem,sum=0;
int i=1;
void main()
{
    clrscr();
    printf("\nEnter a 5 digit number: ");
    scanf("%ld",&num);
    while(num)
    {
        rem=num%10;
        if(rem==9)
            new_rem=0;
        else
            new_rem=rem+1;
        sum=sum + new_rem*i;
        i=i*10;
        num=num/10;
    }
    printf("Final no. is : %ld",sum);
}



——————————————————————————————————————————————————


program to input three number and find biggest of them 
#include<stdio.h>
#include<conio.h>
void  main()
{
int    x, y, z ;
printf(" \ n enter x " ) ;
scanf(" %d " , &x ) ;
printf(" \n  enter y " ) ;
scanf( " %d " , &y ) ;
printf( " \n enter z " ) ;
scanf( " %d " , &z ) ;
if ( x > y & x > z )
{
printf( "\ n  x is bis " ) ;
}
else if ( y > x  & y > z )
{
printf( " \ n y is big " ) :
}
else
{
printf( " \ n z is big " ) ;
}
getch () ;

}