Calculate Range of Values and Average Cost of a Personal System in C

Bhanu Priya
Updated on 25-Mar-2021 11:31:49

727 Views

ProblemA personal system is sold at different costs by the vendors.Let’s take the list of costs (in hundreds) quoted by some vendors −25.00, 30.50, 15.00, 28.25, 58.15, 37.00, 16.65, 42.00 68.45, 53.50SolutionCalculate the average cost and range of values.The difference between the highest and the lowest values in the series is called range Hence, Range = highest value - lowest value.Now, find the highest and the lowest values in the series.ExampleFollowing is the C program to calculate the range of values and average cost of a personal system − Live Demo#include main(){    int count;    float value, high, low, sum, ... Read More

Print Characters and Strings in Different Formats Using C

Bhanu Priya
Updated on 25-Mar-2021 11:22:17

16K+ Views

An algorithm is given below to explain the process which is included in the C programming language to print the characters and strings in different formats.Step 1: Read a character to print.Step 2: Read a name at compile time.Step 3: Output of characters in different formats by using format specifiers.printf("%c%3c%5c", x, x, x);printf("%3c%c", x, x);printf("");Step 4: Output of strings in different formats by using format specifiers.printf("%s", name);printf("%20s", name);printf("%20.10s", name);printf("%.5s", name);printf("%-20.10s", name);printf("%5s", name);ExampleFollowing is the C program to print the characters and strings in different formats − Live Demo#include main(){    char x = 'T';    static char name[20] = "Tutorials Point"; ... Read More

Calculate Salesmen Salary with Macro Functions in C

Bhanu Priya
Updated on 25-Mar-2021 11:18:21

2K+ Views

ProblemA laptop manufacturing company has the monthly compensation policy for their salespersons as mentioned below −Minimum base salary: 3000.00Bonus for every computer sold: 200.00Commission on the total monthly sales: 5 per centSince the prices of laptops are changing, the sales price of each laptop is fixed at the beginning of every month.SolutionThe logic for finding the bonus and commission is as follows −bonus = BONUS_RATE * quantity ; commission = COMMISSION * quantity * price ;The gross salary is calculated by using the formula given below −Gross salary = basic salary + (quantity * bonus rate) + (quantity * Price) ... Read More

Find Cosine and Sine Values Using math.h Library in C

Bhanu Priya
Updated on 25-Mar-2021 11:15:44

6K+ Views

ProblemTo find the cosine and sine values for every 10 degrees from 0 to 150.SolutionThe logic used to find the cosine values is as follows −Declare MAX and PI value at the starting of a programwhile(angle

Multiply Two Matrices Using Pointers in C

Bhanu Priya
Updated on 25-Mar-2021 11:11:05

14K+ Views

Pointer is a variable that stores the address of another variable.Features of PointersPointer saves the memory space.The execution time of a pointer is faster because of the direct access to a memory location.With the help of pointers, the memory is accessed efficiently i.e. memory is allocated and deallocated dynamically.Pointers are used with data structures.Pointer declaration, initialization and accessingConsider the following statement −int qty = 179;In the memory, the variable can be represented as shown below −DeclarationDeclaring a pointer can be done as shown below −Int *p;It means ‘p’ is a pointer variable which holds the address of another integer variable.InitializationThe ... Read More

C Program to Print All Files and Folders

Bhanu Priya
Updated on 25-Mar-2021 11:06:11

1K+ Views

File is a collection of records (or) a place on hard disk where the data is stored permanently.By using C commands, we can access the files in different ways.Operations on filesGiven below are the operations which can be performed on files in the C programming language −Naming the fileOpening the fileReading from the fileWriting into the fileClosing the fileSyntaxThe syntax for opening and naming a file respectively is given below −FILE *File pointer;For example, FILE * fptr;File pointer = fopen (“File name”, “mode”);For example, fptr = fopen (“sample.txt”, “r”);FILE *fp; fp = fopen (“sample.txt”, “w”);The syntax for reading from file ... Read More

Print ASCII Values in a String Using C

Bhanu Priya
Updated on 25-Mar-2021 09:10:40

9K+ Views

An array of characters is called a string.Given below is the declaration of a string −char stringname [size];For example, char string[50]; string of length 50 characters.InitializationUsing single character constant.char string[10] = { ‘H’, ‘e’, ‘l’, ‘l’, ‘o’ ,‘\0’}Using string constants.char string[10] = “Hello”:;AccessingThere is a control string “%s” used for accessing the string till it encounters ‘\0’.The logic we used to print the ASCII values of a given string at runtime is as follows −while(str[i]!='\0'){    printf("ASCII Value of %c = %d", str[i], str[i]);    i++; }ExampleFollowing is the C program to print the ASCII values of a given string ... Read More

Print All ASCII Values in C Program

Bhanu Priya
Updated on 25-Mar-2021 09:07:46

5K+ Views

ProblemPrint the American Standard Code for Information Interchange (ASCII) values of 0 to 255 characters without initializing the character to integer type variable. Simply, use the format specifier.SolutionHere we are writing a program to print only from 65 to 122.If you want to see all ASCII values, in for loop you can write as follows −For(i=0;i

Remove Extra Spaces Using String Concepts in C

Bhanu Priya
Updated on 25-Mar-2021 08:32:55

6K+ Views

ProblemRemove all the extra spaces from an entered string at runtime with the help of while loop by checking the spaces at each index of a character.SolutionConsider an example given below −It removes all the spaces from a given string. The given string is Tutorials Point C Programming. The result after removing spaces is TutorialsPointCProgramming.An array of characters is called a string.Given below is the declaration of a string −char stringname [size];For example, char string[50]; string of length 50 characters.InitializationUsing single character constant.char string[10] = { ‘H’, ‘e’, ‘l’, ‘l’, ‘o’ ,‘\0’}Using string constants.char string[10] = “Hello”:;AccessingThere is a control ... Read More

Remove Spaces in a Sentence Using String Concepts in C

Bhanu Priya
Updated on 25-Mar-2021 08:29:22

4K+ Views

ProblemRemove all the spaces from an entered string at runtime with the help of while loop by checking spaces at each index of a character.SolutionConsider an example given below −It removes all the spaces from a given string. The given string is Tutorials Point C Programming. The result after removing spaces is TutorialsPointCProgramming.An array of characters is called a string.Given below is the declaration of a string −char stringname [size];For example, char string[50]; string of length 50 characters.InitializationUsing single character constant.char string[10] = { ‘H’, ‘e’, ‘l’, ‘l’, ‘o’ ,‘\0’}Using string constants.char string[10] = “Hello”:;AccessingThere is a control string “%s” ... Read More

Advertisements