Found 1401 Articles for C

Write a C program to perform 3X3 matrix operations

Mandalika
Updated on 05-Mar-2021 10:01:49

2K+ Views

ProblemEnter any 9 numbers at runtime and add the numbers in a row, column, and diagonal wise by using C Programming languageAlgorithmStep 1: Declare 9 variables Step 2: enter 9 numbers at runtime Step 3: store the numbers in 3 X 3 matrix form         //x y z         p q r         a b c Step 4: Do row calculation: add all the numbers in a row and print         // (x+y+z), (p+q+r), (a+b+c) Step 5: Do column calculation: add all the numbers in a Column and ... Read More

Write a C program of library management system using switch case

Mandalika
Updated on 05-Mar-2021 09:57:47

7K+ Views

ProblemHow to store the books-related information of library using C programming.AlgorithmStep 1: Declare a structure which holds data members Step 2: declare variables which are used for loop Step 3: use switch case to work on each module Step 4: case 1- for Adding book information         Case 2- for Display book information         Case 3- for Finding number for books in library         Case 4- for EXITProgram#include #include #include #include struct library{    char bookname[50];    char author[50];    int noofpages;    float price; }; int main(){    struct library ... Read More

Write a C program for electing a candidate in Elections by calling functions using Switch case

Mandalika
Updated on 05-Mar-2021 09:30:26

5K+ Views

ProblemHow to cast vote, count, and display the votes for each candidate that participates in elections using C language?SolutionLet’s consider three persons who participated in elections. Here we need to write a code for the following −Cast vote − Selecting a candidate by pressing the cast voteFind vote count − Finding the total number of votes each candidate gains declaring the winner.ExampleAll these operations are performed by calling each function using Switch case −#include #define CANDIDATE_COUNT #define CANDIDATE1 "ABC" #define CANDIDATE2 "XYZ" #define CANDIDATE3 "PQR" int votescount1=0, votescount2=0, votescount3=0; void castvote(){    int choice;    printf(" ### Please choose your ... Read More

How to align the output using justificationsin C language?

Mandalika
Updated on 05-Mar-2021 08:46:09

15K+ Views

By using justifications in printf statement we can arrange the data in any format.Right JustificationTo implement the right justification, insert a minus sign before the width value in the %s character.printf("%-15s", text);Program 1Let’s take an example to print data in row and column-wise with the help of justification. Live Demo#include int main(){    char a[20] = "Names", b[20]="amount to be paid";    char a1[20] = "Bhanu", b1[20]="Hari", c1[20]="Lucky", d1[20]="Puppy";    int a2=200, b2=400, c2=250, d2=460;    printf("%-15s %-15s", a, b);    printf("%-15s %-15d", a1, a2);    printf("%-15s %-15d", b1, b2);    printf("%-15s %-15d", c1, c2);    printf("%-15s %-15d", d1, d2);    return ... Read More

Write C program to calculate balance instalment

Mandalika
Updated on 05-Mar-2021 08:40:51

613 Views

ProblemWrite a C program to calculate a balance installment that is to be paid after every month for a particular loan amount (with interest).SolutionFollowing is the formula to calculate interest when the loan amount is given −i=loanamt * ((interest/100)/12);Following calculation gives amount with interest −i=i+loanamt; firstmon=i-monthlypayment; //first month payment with interest i=firstmon * ((interest/100)/12);Program Live Demo#include int main(){    float loanamt, interest, monthlypayment;    float i, firstmon, secondmon;    printf("enter the loan amount:");    scanf("%f", &loanamt);    printf("interest rate:");    scanf("%f", &interest);    printf("monthly payment:");    scanf("%f", &monthlypayment);    //interest calculation//    i=loanamt * ((interest/100)/12);    //amount with interest    i=i+loanamt; ... Read More

C program on calculating the amount with tax using assignment operator

Mandalika
Updated on 05-Mar-2021 08:38:24

2K+ Views

ProblemWrite a C Program to enter the amount in dollars and then display the amount by adding 18% as tax.SolutionLet’s consider the restaurant person adding 18% tax to every bill of the customer.The logic applied to calculate tax is −value=(money + (money * 0.18));The money should be multiplied by 18% and add to the money, then the restaurant person can receive the amount from a customer with tax.Example Live Demo#include int main(){    float money, value;    printf("enter the money with dollar symbol:");    scanf("%f", &money);    value=(money + (money * 0.18));    printf("amount after adding tax= %f", value);    return ... Read More

How to calculate the volume of a sphere using C programming language?

Mandalika
Updated on 05-Mar-2021 08:35:37

3K+ Views

The volume of sphere is nothing but the capacity of the shape.Volume of a sphere formula is −$$V\:=\:\frac{4}{3}\Pi\:r^{3}$$AlgorithmStep 1: Enter radius of sphere at runtime Step 2: Apply the formula to variable         Volume=(4/3)*3.14*rad*rad*rad Step 3: print the volume Step 4: stopProgram 1 Live Demo#include int main(){    float vol;    int rad;    rad=20;    vol=((4.0f/3.0f) * (3.1415) * rad * rad * rad);    printf("the volume of a sphere is %f", vol);    return 0; }Outputthe volume of a sphere is 33509.335938Program 2Following is an example to find Volume and Surface Area of Sphere − Live Demo#include ... Read More

Write an example program on structure using C language

Mandalika
Updated on 05-Mar-2021 08:27:11

436 Views

The structure is a collection of different datatype variables, grouped together under a single name Syntax.Declaration and initialization of structuresThe general form of structure declaration is as follows −datatype member1; struct tagname{    datatype member2;    datatype member n; };Here, struct - keyword         tagname - specifies name of structure         member1, member2 - specifies the data items that makeup structure.Examplestruct book{    int pages;    char author [30];    float price; };Structure variablesThere are three ways of declaring structure variables. They are as follows −1) struct book{    int pages;    char author[30];    float ... Read More

What is the use of sprintf() and sscanf() functions in C language?

Mandalika
Updated on 05-Mar-2021 08:22:29

4K+ Views

The sscanf() functionIt reads data from a character string.Syntaxsscanf(string, formatspecifier, &var1, &var2, ……..)String refers to the char string to read from.Format string refers to char string containing certain required formatting information.Var1, var2 etc., represent the individual input data items.For example, sscanf(string, "%d%d", &hours, &minutes);The sprintf() functionThis function is used to write data to a character string.Syntaxsprintf(string, format specifier, &var1, &var2…….);String refers to char string to write.Format specifier refers to char string containing certain required formatting information.Var1, var2 etc., represent the individual input data items.Example − sprint(value, "cube of two is %d and square of two is %d", 2*2*2 ,2*2);//value=cube of ... Read More

Explain reference and pointer in C programming?

Bhanu Priya
Updated on 09-Mar-2021 06:31:53

720 Views

ProblemExplain the concept of reference and pointer in a c programming language using examples.ReferenceIt is the alternate name for the variable that we declared.It can be accessed by using pass by value.It cannot hold the null values.Syntaxdatatype *variablenameFor example, int *a; //a contains the address of int type variable.PointerIt stores the address of variable.We can hold the null values using pointer.It can be access by using pass by reference.No need of initialization while declaring the variable.Syntaxpointer variable= & another variable;Example Live Demo#include int main(){    int a=2, b=4;    int *p;    printf("add of a=%d", &a);    printf("add of b=%d", &b); ... Read More

Advertisements