Add Two Complex Numbers Using C

Mandalika
Updated on 05-Mar-2021 10:39:16

457 Views

ProblemHow to add two complex numbers which are entered at run time by the user using C program −SolutionA complex number is a number that can be a combination of real and imaginary parts.It is represented in the form of a+ib.ProgramFor example, let’s take the two complex numbers as (4+2i) and (5+3i) after adding the two complex numbers, the result is 9+5i. Live Demo#include struct complexNumber{    int realnumber, imaginarynumber; }; int main(){    struct complexNumber x, y, z, p;    printf("enter first complex number x and y");    scanf("%d%d", &x.realnumber, &x.imaginarynumber);    printf("enter second complex number z and p"); ... Read More

Print Integers in the Form of Pascal Triangle Using C

Mandalika
Updated on 05-Mar-2021 10:35:57

376 Views

Pascal's triangle is the representation of integers in the form of a triangle. One of the famous representations of it is with binomial equations. We can use combinations and factorials to achieve this.Constructing a Pascal triangleAll values outside the triangle are considered zero (0). The first row is 0 1 0 whereas only 1 acquire a space in Pascal’s triangle, 0s are invisible. The second row is acquired by adding (0+1) and (1+0). The output is sandwiched between two zeroes. The process continues till the required level is achieved.Programmatically, a Pascal triangle is defined as an array constructed by adding ... Read More

Print Floyd's Triangle of Integers Using C Program

Mandalika
Updated on 05-Mar-2021 10:31:09

247 Views

Floyd's triangle is a right-angle triangle of consecutive numbers, starting with a 1 in the top left corner −For example,1 2 3 4 5 6 7 8 9 10Example 1 Live Demo#include int main(){    int rows, i,j, start = 1;    printf("Enter no of rows of Floyd's triangle :");    scanf("%d", &rows);    for (i = 1; i

Check If a Number Is Armstrong Using C

Mandalika
Updated on 05-Mar-2021 10:27:39

11K+ Views

ProblemHow to check whether the given number is an Armstrong number or not using C Programming language?SolutionArmstrong number is the number that is equal to the sum of cubes of its digits.Syntaxpqrs………=pow(p, n)+pow(q, n)+pow(r, n)+……….For example, 153, 371, 1634, etc., are Armstrong numbers.153=1*1*1 + 5*5*5 + 3*3*3    =1+125+27    =153 (Armstrong number)Program Live Demo#include int main(){    int number, remainder, total=0, temp;    printf("enter the number=");    scanf("%d", &number);    temp=number;    while(number>0){       remainder=number%10;       total=total+(remainder*remainder*remainder);       number=number/10;    }    if(temp==total)       printf("This number is Armstrong number");    else   ... Read More

Print Given Number in Reverse Order Using Iterative Function in C

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

415 Views

ProblemHow to print the given in reverse order with the help of iterative function i.e., while loop using C programming language?SolutionSo far, we had seen how to reverse the string using string function and without string function, now let’s see how to reverse a number without using predefined function −AlgorithmInput − give a number at runtimeStep 1: Declare the variable number, reverse Step 2: Initialize reverse= 0 Step 3: while number>0         (a) reverse=reverse*10 + number%10;             reverse = reverse*10 + num%10;         (b) Divide number by 10 Step ... Read More

Print Numbers in Reverse Order Using Division and Modulo Operators in C

Mandalika
Updated on 05-Mar-2021 10:21:24

1K+ Views

ProblemHow to print the given two-digit number in reverse order with the help of division and Modulo operator using C programming language?SolutionSo far, we had seen how to reverse the string using string function and without string function. Now let’s see how to reverse the two-digit number without using the predefined function.The logic we use to reverse the number with the help of operators is −int firstno=number%10; //stores remainder int secondno=number/10;// stores quotientThen print the first number followed by the second number then you will get the reverse number for the given number.Program 1In this example, we will take a ... Read More

Differentiate Modulo and Division in C Programming Language

Mandalika
Updated on 05-Mar-2021 10:04:59

6K+ Views

Modulo − Represents as % operator. And gives the value of the remainder of an integer division.Division − represents as / operator. And gives the value of the quotient of a division.Program 1#include int main(){    int a, b, c;    printf("enter a, b, c values:");    scanf("%d%d%d, &a, &b, &c);    printf("a/b=%d a%b=%d", a/b, a%b);    printf("(a+10)%b=%d (a+10)/b=%d", (a+10)%b, (a+10)/b); }Outputenter a, b, c values:2 4 6 a/b=0 ab=2 (a+10)b=0 (a+10)/b=3Program 2Applying pointer variables to perform modulo and division operation − Live Demo#include void main(){    //Declaring pointers and variables//    int num1, num2;    int *p1, *p2;    p1=&num1;    p2=&num2; ... Read More

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

Library Management System in C using Switch Case

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

10K+ 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

C Program for Electing a Candidate in Elections 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

Advertisements