Let us C Chapter 1.(H)

 (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>
int main(){
int bs, gs;
printf("Enter basic salary: ");
scanf("%d", &bs);
gs=bs+(bs*40/100)+(bs*20/100);
printf("Gross salary is %d", 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>
int main()
{
    int m,c;
    float d,f;
    printf("Distance between two cities(in km): ");
    scanf("%f", &d);
    m=d*1000; f=d*3280.84; c=d*100000;
    printf("%f is equal to %d metres.\n", d,m);
    printf("%f is equal to %f feet.\n", d,f);
    printf("%f is equal to %d centimetres.", d,c);

}

(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>
int main(){
    int a,b,c,d,e;
    float m;
    printf("Enter English Marks: ");
    scanf("%d", &a);
    printf("Enter Hindi Marks: ");
    scanf("%d", &b);
    printf("Enter Physics Marks: ");
    scanf("%d", &c);
    printf("Enter Chemistry Marks: ");
    scanf("%d", &d);
    printf("Enter Maths Marks: ");
    scanf("%d", &e);
    printf("Aggregate score is %d marks.\n", a+b+c+d+e);
    m=(a+b+c+d+e)*100/500;
    printf("Scored percentage is %f.", m);
}

 (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>
int main(){
    float f;
    printf("Temprature(in farhenheit): ");
    scanf("%f", &f);
    printf("temprature in farhenheit is %fF.\n", f);
    printf("temprature in Celsius is %fC.\n", (f-32)*5/9);
}

(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>
int main(){
    float l,b,r,a,p,ac,c;
    printf("length of rectangle: ");
    scanf("%f", &l);
    printf("Breadth of rectangle: ");
    scanf("%f", &b);
    printf("Radius of cicle : ");
    scanf("%f", &r);
    printf("Area of Rectangle is %f sq.unit.\n", l*b);
    printf("Perimeter of Rectangle is %f unit.\n", (l+b)*2);
    printf("Area of circle is %f sq.unit.\n", 3.14*r*r);
    printf("Circumference of circle is %f unit.\n",2*3.14*r);

}

 (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 main(){
    int c,d;
    printf("Number C: ");
    scanf("%d", &c);
    printf("Number D: ");
    scanf("%d", &d);
    printf("C=%d.\n", d);
    printf("D=%d.\n", c);

}

(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>
int main(){
    int num,a,b,c,d,e;
    printf("Enter a Five Digit Number: ");
    scanf("%d", &num);
    a=(num/10)%10;b=(num/100)%10;c=(num/1000)%10;
    d=(num/10000); e=num%10;
    printf("%d is the sum of digits of %d.", a+b+c+d+e, num);
}


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

#include<stdio.h>
int main(){
    int num,a,b,c,d,e;
    printf("Enter a Five Digit Number: ");
    scanf("%d", &num);
    a=num%10;b=(num/10)%10;c=(num/100)%10;
    d=(num/1000)%10;e=(num/10000);
    printf("The number produced by reversing %d is %d%d%d%d%d.", num,a,b,c,d,e);
}

 (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 main(){
    int num,a,b;
    printf("Enter a four Digit Number: ");
    scanf("%d", &num);
    a=num%10;b=(num/1000);
    printf("The sum of first and last digit of %d is %d.", num,a+b);
}

 (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>
int main(){
    int m,w,l,lm,ilm,lw,ilw;
    m=52*80000/100;
    w=80000-m;
    l=48*80000/100;
    lm=35*80000/100;
    ilm=m-lm;
    lw=l-lm;
    ilw=w-lw;
    printf("total no. of iliterate man is %d\n", ilm);
    printf("total no. of iliterate woman is %d", ilw);
}

(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 withdrawer.

#include<stdio.h>
int main(){
    int amo;
    printf("enter amount (in hundreds): ");
    scanf("%d", &amo);

    printf("numer of 100's notes is %d.\n", amo/100);
    printf("numer of 50's notes is %d.\n", (amo%100)/50);
    printf("numer of 10's notes is %d.\n", ((amo%100)%50)/10);
    printf("remaining cash is %d.", ((amo%100)%50)%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>
int main(){
    int tsp,p;
    printf("Total selling price(15 units): ");
    scanf("%d", &tsp);
    printf("Total profit earned(15 unit): ");
    scanf("%d", &p);
    printf("cost price of 1 item is %d.", (tsp-p)/15);

}

 (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>
int main(){
    int num,r,add=0,rev=0;

    printf("Enter a Five digit number: ");
    scanf("%d", &num);
    while (num>0)
    {
        r=num%10;
        num=num/10;
        rev=rev*10+r;
    }
    while (rev>0)
    {
        r=rev%10;
        rev=rev/10;
        r=r+1;
        add=add*10+r;
    }
    printf("The number by adding one to each of digits: %d", add);
    return 0;
   
}


Comments

Popular posts from this blog

Functions and recrusion.

Quick calculator using HTML,CSS and Java Script.