C Articles - Page 17 of 95

Write a C program to maintain cricketer’s information in tabular form using structures

Mandalika
Updated on 05-Mar-2021 12:14:40

8K+ Views

ProblemHow to store the cricketer’s data in tabular form in sorted order based on average runs using structures in C Programming language.SolutionLet’s try to enter the cricketer information such as name, age, no of matches and average runs he scored. It will be entered in the console at runtime using the structure concept.And try to display the information in tabular form in sorted order based on average runs scored by each person so that it is easy to identify each person's details clearly.The logic we used to sort the cricketers in ascending order based on average runs they scored is ... Read More

Write a C program to calculate the average word length of a sentence using while loop

Mandalika
Updated on 05-Mar-2021 12:11:51

1K+ Views

ProblemEnter a sentence at run time and write a code for calculating the average length of words that are present in a sentenceSolutionAlgorithmSTART Step 1: declare character, int and double variables Step 2: Enter any statement Step 3: while loop        Check condition stmt[i]=getchar()) != ''        True then enter into loop        Increment I and call the function at step 5 Step 4: Print the average length return by function        From step 5 Step 5: called function calculatewordlength          i. declare and initialize         ... Read More

Write a C program to print numbers in words using elseif statements

Mandalika
Updated on 05-Mar-2021 12:08:07

5K+ Views

ProblemWithout using a switch case, how can you print a given number in words using the C programming language?SolutionIn this program, we are checking three conditions to print a two-digit number in words −if(no99)entered number is not a two digitelse if(no==0)print first number as zeroelse if(no>=10 && no=20 && no=10 && no=20 && no

Write a C program to print the message in reverse order using for loop in strings

Mandalika
Updated on 05-Mar-2021 12:05:26

848 Views

Here we write a program to reverse the sentence without predefined functions. By using for loop, we can easily print statement in reverse order.Program 1#include int main(){    char stmt[100];    int i;    printf("enter the message:");    for(i=0;i=0;i--) //printing each char in reverse order    putchar(stmt[i]);    putchar('');    return 0; }Outputenter the message: Hi welcome to my world the reverse statement is: dlrow ym ot emoclew iHProgram 2Here, we will write a C program to reverse a string using strrev library function −#include #include void main(){    //Declaring two strings//    char result[50], string[25];    //Reading string 1 ... Read More

How to print a one-month calendar of user choice using for loop in C?

Mandalika
Updated on 06-Mar-2021 18:36:13

6K+ Views

The logic to print a one-month calendar is as follows −for(i=1;i

Generate an even squares between 1 to n using for loop in C Programming

Mandalika
Updated on 05-Mar-2021 11:56:52

1K+ Views

Even square numbers are - 22, 42, 62, 82,……… = 4, 16, 36, 64, 100, ………AlgorithmSTART Step 1: declare two variables a and n Step 2: read number n at runtime Step 3: use for loop to print square numbers         For a=2; a*a

Swapping numbers using bitwise operator in C

Mandalika
Updated on 05-Mar-2021 11:50:12

22K+ Views

ProblemHow to swap the numbers using the bitwise operator in the C programming language?SolutionThe compiler swap the given numbers, first, it converts the given decimal number into binary equivalent then it performs a bitwise XOR operation to exchange the numbers from one memory location to another.AlgorithmSTART Step 1: declare two variables a and b Step 1: Enter two numbers from console Step 2: swap two numbers by using BITWISE operator         a=a^b         b=a^b         a=a^b Step 3: Print a and b values STOPProgram Live Demo#include int main(){    int a, b; ... Read More

Write a C program to reduce any fraction to least terms using while loop

Mandalika
Updated on 05-Mar-2021 11:47:58

2K+ Views

Reducing the fraction to the lowest terms means that there is no number, except 1, that can be divided evenly into both the numerator and the denominator.For example, 24/4 is a fraction, the lowest term for this fraction is 6, or 12/16 is a fraction the lowest term is 3/4.Now let’s write a c program to reduce the fraction into their lowest terms.Example 1 Live Demo#include int main(){    int x, y, mod, numerat, denomi, lessnumert, lessdenomi;    printf("enter the fraction by using / operator:");    scanf("%d/%d", &x, &y);    numerat=x;    denomi=y;    switch(y){       case 0:printf("no zero's ... Read More

Converting digits to word format using switch case in C language

Mandalika
Updated on 05-Mar-2021 11:06:39

7K+ Views

ProblemIs it possible to convert the given one or two-digit numbers into English words by using the C Programming language?SolutionWe can easily convert the given two-digit number into English word format with the help of a switch case. Not only two digits, but any number can also convert into English like a statement in C.In this program, we will convert one or two-digit numbers into English word format.Example Live Demo#include int main(){    int no;    printf("enter any 1 or 2 digit number:");    scanf("%d", &no);    if(no=99) //finding out whether enter no is 2 digit or not       ... Read More

Write a C program to find out the largest and smallest number in a series

Mandalika
Updated on 05-Mar-2021 11:00:04

19K+ Views

ProblemLet the user enter four series of integers in the console, find out a number which is smallest and largest in a seriesSolutionTo calculate the small and large number, we use if conditions. The logic we use to find the largest and smallest number is −if(minno>q) //checking 1st and 2nd number    minno=q; else if(maxno&l;q)    maxno=q; if(minno>r) //checking 1st and 3rd number    minno=r;Program 1 Live Demo#include int main(){    int minno, maxno, p, q, r, s;    printf("enter any four numbers:");    scanf("%d%d%d%d", &p, &q, &r, &s);    minno=p;    maxno=p;    if(minno>q) //checking 1st and 2nd number   ... Read More

Advertisements