Posts

Showing posts from March, 2020

Q: Consider a currency system in which there are note of seven denominations, namely, Rs. 1, Rs. 2, Rs. 5, Rs. 10, Rs. 50, Rs. 100. if a sum of Rs. N is entered through the keyboard, write a program to compute the smallest number of notes that will combine to give Rs N.

#include <stdio.h> #include <math.h> int main() {     int x,a,b,c,d,e,f;         printf("enter total amount of money\n");     scanf("%d",&x);         /*floor fun is used to get significant value*/         a=floor(x/100);     b=floor((x%100)/50);     c=floor(((x%100)%50)/10);     d=floor((((x%100)%50)%10)/5);     e=floor(((((x%100)%50)%10)%5)/2);     f=floor(((((x%100)%50)%10)%5)%2);         printf("note of 100 = %d\nnote of 50 = %d\nnote of 10 = %d\nnote of 5 = %d\nnote of 2 =                                       %d\nnote of 1 = %d\n",a,b,c,d,e,f); return 0; } ----------------------------------------- output : enter total amount of mon...

Q: Two number are input through the keyboard into two two locations C and D. write a program to interchange the contents of C and D.

#include <stdio.h> int main() {     float C,D;    /*C and D are two variables*/         printf("enter value of C and D respectivly:");     scanf("%f%f",&C,&D);         /*steps to interchange value of two variables*/     C=C+D;     D=C-D;     C=C-D;         printf("value of C is %f\nvalue of D is %f\n",C,D);         return 0; } ----------------------------------------- output : enter value of C and D respectivly:5 4 value of C is 4.000000 value of D is 5.000000  

Q: If value of an angle is input through the keyboard, write a program to print all its Trigonometric ratios.

#include <stdio.h> #include <math.h> int main() {     float degree, radian;     float PI = 3.14159;     printf("Enter angle in degree\n");     scanf("%f",&degree);     radian = degree * (PI / 180.0);     printf("Sin(%f) = %f\n", degree, sin(radian));     printf("Cos(%f) = %f\n", degree, cos(radian));     printf("Tan(%f) = %f\n", degree, tan(radian));     printf("Cosec(%f) = %f\n", degree, 1/sin(radian));     printf("Sec(%f) = %f\n", degree, 1/cos(radian));     printf("Cot(%f) = %f\n", degree, 1/tan(radian));     return 0; } ----------------------------------------- output : Enter angle in degree 30 Sin(30.000000) = 0.500000 Cos(30.000000) = 0.866026 Tan(30.000000) = 0.577350 Cosec(30.000000) = 2.000001 Sec(30.000000) = 1.154700 Cot(30.000000) = 1.732052

Q: write a program to recive values of T and V and calculate wind chill factor (wcf).

formula to find wind chill factor :   wcf=35.74+0.6215*T+(0.4275*T-35.75)*pow(V,0.16) #include <stdio.h> #include <math.h> int main() {     float T, V, wcf; /* T is temp and V is velocity of air */         printf("enter value of temp T and velocity of air V\n");         scanf("%f%f",&T,&V);         wcf=35.74+0.6215*T+(0.4275*T-35.75)*pow(V,0.16);  /*formula to find wind chill factor*/         printf("wcf is %f",wcf); return 0; } ----------------------------------------- output : enter value of temp T and velocity of air V 50 23 wcf is 43.074802

Q: The Body Mass Index (BMI) is defined as ratio of the weight of a person (in kilograms) to the square of the height (in meters). Write a c program that receives weight and height, calculates the BMI, and reports the BMI category as per the following table:

Image
#include<stdio.h> #include<math.h>  /*this header file is used to include all predefined maths function*/ int main() {     /*Weight should be in Kilograms*/     /*Height should be in Meters*/     float weight, height, BMI;         printf("Enter the weight of person: ");     scanf("%f", &weight);     printf("Enter the height of person: ");     scanf("%f", &height);     /*BMI stands for Body Mass Index*/     BMI = weight/(pow(height, 2));    /*pow is a function that gives second value peresent in bracket is as power of first value of bracket*/     printf("\n\nThe BMI of person is: %f\n", BMI);     if (BMI>0 && BMI<=15)         printf("BMI Category is Starvation");     else if (BM...

Q: Write a c program, which will require the user to give value of hardness, carbon content and tensile strength of the steel under consideration and output the grade of the steel.

A certain grade of steel is graded according to the following conditions: Hardness must be greater than 50 Carbon content must be less than 0.7 Tensile strength must be greater than 5600 The grades are as follows: Grade is 10 if all three conditions are met Grade is 9 if conditions (i) and (ii) are met Grade is 8 if conditions (ii) and (iii) are met Grade is 7 if conditions (i) and (iii) are met Grade is 6 if and only one conditions is met Grade is 5 is none of the conditions are met #include<stdio.h> int main() {     /*h = Hardness of steel,cc = Carbon content,ts = Tensile strength*/     float h, cc, ts;     int h_f=0,  cc_f=0, ts_f=0;  /*here 0 represent False and one represent for True*/     int grade;     printf("Enter the value of Hardness: ");         scanf("%f", &h);         printf("Enter the value of Carbon Con...

Q: In digital world colors are specified in Red-Green-Blue (RGB) format, with values of R, G, B varying on an integer scale from 0 to 255. In print publishing the colors are mentioned in Cyan-Magenta-Yellow-Black (CMYK) format, with values of C, M, Y, and K varying on a real scale from 0.0 to 1.0. Write a c program that converts RGB color to CMYK color as per the following formulae.

Formulae : White = Max(Red/255, Green/255, Blue/255) Cyan = (White-Red/255)/(White) Magenta = (White-Green/255)/(White) Yellow = (White-Blue/255)/(White) Black = 1-White Note that of the RGB values are all 0, then the CMY values are all 0 and the K value is 1. #include<stdio.h> int main() {     float r, g, b, rf, gf, bf, max, w, c, y, m , k;         /*k stands for black*/     printf("Enter the value of Red(0 to 255): ");     scanf("%f", &r);     printf("Enter the value of Green(0 to 255): ");     scanf("%f", &g);     printf("Enter the value of Blue(0 to 255): ");     scanf("%f", &b);     rf = r/255;     gf = g/255;     bf = b/255;     printf("\nRed: %f\nGreen: %f\nBlue: %f\n", rf, gf, bf);     /*find maximum amoung all of them...

Q: Paper of size A0 has dimensions 1189 mm x 841 mm. Each subsequent size A(n) is defined as A(n-1) cut in half parallel to its shorter sides. Write a program to calculate and print paper sizes A0, A1, A2, ….. A8.

#include<stdio.h> int main() {     int i, w=841, h=1189, k;      for(i=0; i<9; i++)      {          printf("\n A%d: %d x %d", i, w, h);          k = h;          h = w;          w = k/2;      }      return 0; } ----------------------------------------- Output:  A0: 841 x 1189  A1: 594 x 841  A2: 420 x 594  A3: 297 x 420  A4: 210 x 297  A5: 148 x 210  A6: 105 x 148  A7: 74 x 105  A8: 52 x 74

Q: write a program to receive values of latitude (L1,L2) and longitude (G1,G2) in degrees, of two places on the earth and output the distance (D) between them in nautical miles.

#include <stdio.h> #include <math.h> int main() {     float D,L1,L2,G1,G2;         printf("enter the value of L1,L2,G1 and G2 in digree :\n");     scanf("%f%f%f%f",&L1,&L2,&G1,&G2);         /*formula used to find distance between two points on earth in nautical miles*/     D=3963*(acos(sin(L1*3.14/180)*sin(L2*3.14/180)+cos(L1*3.14/180)*cos(L2*3.14/180)*cos(G2*3.14/180-G1*3.14/180)))*180/3.14;         printf("\ndistance is %f",D);         return 0; } ----------------------------------------- output : enter the value of L1,L2,G1 and G2 in digree : 3 4 5 6 distance is 5599.273438

Q: write a program to receive cartesian coordinates and convert them in polar coordinate.

#include <stdio.h> #include <math.h> int main () {     float x,y,r,A;                    printf("enter coordinate of point(x,y) :\n");     scanf("%f%f",&x,&y);         A = atan(y/x);    /*formula used to find inverse*/     A = 180*A/3.14;    /*formula used to convert radian to degree*/     r = sqrt(x*x + y*y);    /*formula used to find dist of point from orgin*/         printf("polar cordinate for given point is (%f,%f)",r,A);     return 0; } ----------------------------------------- output : enter coordinate of point(x,y) : 4 5 polar cordinate for given point is (6.403124,51.366234)

Q: if the length of a triangle are input through the keyboard, write a program to find the area of triangle.

#include <stdio.h> #include <math.h> int main() {     float area,a,b,c,s; // a,b,c are sides of triangle //         printf("enter side of triangle :  ");     scanf("%f%f%f",&a,&b,&c);         if (a+b<=c ||b+c<=a ||c+a<=b ||a<0 ||b<0 ||c<0)    //to check whether the triangle is possible or not//     printf("triangle is not possible");             else  //if the triangle is possible//     {         s=(a+b+c)/2;    /* to find the semi perimeter of triangle denoted as s/2 */         area=sqrt(s*(s-a)*(s-b)*(s-c));    /*formula used to find area of triangle*/                 printf("area of triangle...

Q: if a five digit number is input through the keyboard write a program to reverse the number.

# include <stdio.h> int main() {     int n,rem,rev;         printf("enter any number : ");     scanf("%d",&n);         while(n!=0)              /*condition used until n becomes zero*/         {         rem= n%10;           /*to find the last digit of no*/         n=n/10;                   /*as n is int so n/10 also be int*/         rev=rev*10+rem;    /*to find the reverse of the no entered*/     }         printf("reverse of no is %d",rev);         return 0; } ----------------------------------------- ou...

Q: 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, sum;         printf("enter any number : ");     scanf("%d",&num);         while(num != 0)    /*condition used unti num becomes zero*/     {         /* modulo operator is used to find remainder*/         sum += num%10;   /* sum is increase with new remainder after the no is divide by 10 */         num  =  num/10;     }     printf("sum of digits of given no is %d",sum);     return 0; } ----------------------------------------- output : enter any number : 12345 sum of digits of given no is 15

Q: If the marks obtained by a student in five different subjects are input through the keyboard, write a program to 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 computer, math, english, physics, chemistry, aggregrate;     float percentage;       printf("Enter the marks obtained in Computer: ");     scanf("%d", &computer);     printf("Enter the mark obtained in English: ");     scanf("%d", &english);     printf("Enter the marks obtained in Physics: ");     scanf("%d", &physics);       printf("Enter the marks obtained in Math: ");     scanf("%d", &math);     printf("Enter the marks obtained in Chemistry: ");     scanf("%d", &chemistry);     aggregrate = computer+math+english+physics+chemistry;     percentage =  aggregrate/5;     printf("\n\nAggregate marks obtained by student: %d",aggregrate);     printf("\nPercentage marks obtained by student: %f %%",percentage); ...

Q: The length & breadth of a rectangle and radius of a circle are input through the keyboard. Write a program to calculate area & perimeter of the rectangle and area & circumference of the circle.

#include<stdio.h> int main() {     float l, b, r,ac, cc, ar, pr;  /*l is length,b is breadth,r is radius*/     /*For rectangle*/     printf("Enter the length of rectangle: ");     scanf("%f",&l);       printf("Enter the breadth of rectangle: ");     scanf("%f", &b);     /*For circle*/     printf("\nEnter the radius of circle: ");     scanf("%f", &r);     /*Calculate area & perimeter of the rectangle*/       ar = l * b;    /*ar is Area of Rectangle = Length x Breadth*/       pr = 2 * (l + b);    /*pr is Perimeter of Rectangle = 2 x (L + B) or addition of all sides*/      /*Calculate area & circumference of the circle*/       ac = 3.14 * r * r;   /*ac is Area of Circle = 2 x Pi x r^2 where Pi = 3.14*/       cc = 2 * 3....

Q: Temperature of a City in Fahrenheit degree is input through the keyboard. Write a program to convert this temperature into centigrade degree.

#include<stdio.h> int main() {     float farn, centi;  /*farn=temp in farenheit & centi=temp in centigrade*/     printf("Enter Temperature of city in Fahrenheit: ");     scanf("%f",&farn);     centi = (farn-32)*5/9;     printf("\n\nTemperature of city in Centigrade Degree: %f",centi);          return 0; } ----------------------------------------- output: Enter Temperature of city in Fahrenheit: 67 Temperature of city in Centigrade Degree: 19.444445

Q: 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() {     float km, m, cm, f, in;     /*km=Kilometers,m=Meters,cm=Centimeters,f=Feet,in=Inch*     printf("Enter distance in kilometers: ");     scanf("%f", &km);     /* formulae for distance conversion */     m = km * 1000;     cm = km * 1000 * 100;     f = km * 3280.84;     in = km * 39370.08;     printf("\nThe distance in Feet: %f\n", f);     printf("The distance in Inches: %f\n", in);     printf("The distance in Meters: %f\n", m);     printf("The distance in Centimeters: %f\n", cm);     return 0; } ---------------------------------------- output: Enter distance in kilometers: 5 The distance in Feet: 16404.199219 The distance in Inches: 196850.406250 The distance in Meters: 5000.000000 The distance in Centimeters: 500000.000000

Q: 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() { float bs, da, hr, gs;      /*bs=basic salary,da=dearness allow,hr=house rent, gs=gross salary*/     printf("Enter Basic Salary: ");        scanf("%f",&bs);     da = 0.4 * bs;     hr = 0.2 * bs; gs= bs + da + hr;         printf("\nBasic Salary: %f\n",  bs);     printf("Dearness Allowance: %f\n", da);     printf("House Rent: %f\n", hr);     printf("\n\nGross Salary: %f\n",gs);     return 0; } ----------------------------------------- Output: Enter Basic Salary: 1000 Basic Salary: 1000.000000 Dearness Allowance: 400.000000 House Rent: 200.000000 Gross Salary: 1600.000000

Program to Add Two Integers

#include <stdio.h> int main() {        int number1, number2, sum;         printf("Enter two integers: ");     scanf("%d %d", &number1, &number2);     /* calculating sum*/     sum = number1 + number2;              printf("%d + %d = %d", number1, number2, sum);     return 0; } ----------------------------------------- Output: Enter two integers: 10 22 10 + 22 =32

Program to Print an Integer

#include <stdio.h> int main() {       int number;        printf("Enter an integer.....\n ");          /*reads and stores input give by user*/     scanf("%d", &number);     /* displays output*/     printf("You entered: %d", number);         return 0; } ----------------------------------------- Output: Enter an integer..... 5 You entered: 5 ----------------------------------------- The user is asked to enter an integer number. This number is stored in the number variable . Finally, the value stored in number is displayed on the screen using printf().

Program to Display "Hello World"

#include <stdio.h> int main() {    /* printf() displays the string inside quotation on screen*/    printf("Hello World");    return 0; } ----------------------------------------- Output: Hello World ----------------------------------------- How program works? The #include is a preprocessor command that tells the compiler to include the contents of stdio.h (standard input and output) file in the program. The stdio.h file contains functions such as scanf() and printf() to take input and display output respectively.  If you use the printf() function without writing #include <stdio.h> , the program will not compile. The execution of a C program starts from the main() function.   printf() is a library function to send formatted output to the screen. In this program, printf() displays Hello World text on the screen.     The return 0; statement is the "Exit status" of the progra...