Count Vowels and Consonants in a String in C Language

Bhanu Priya
Updated on 08-Mar-2021 10:19:18

2K+ Views

ProblemHow to write a C program to count numbers of vowels and consonants in a given string?SolutionThe logic that we will write to implement the code to find vowels and consonants is −if(str[i] == 'A' || str[i] == 'E' || str[i] == 'I' || str[i] == 'O' || str[i] == 'U'||str[i] == 'a' || str[i] == 'e' || str[i] == 'i' || str[i] == 'o' || str[i] == 'u' )If this condition is satisfied, we try to increment the vowels. Or else, we increment the consonants.ExampleFollowing is the C program to count the number of vowels and consonants in a ... Read More

Structure Declaration in C Language

Bhanu Priya
Updated on 08-Mar-2021 10:15:03

13K+ Views

The structure is a collection of different datatype variables, grouped together under a single name. It is a heterogeneous collection of data items that share a common name.Features of structureIt is possible to copy the contents of all structural elements of different data types to another structure variable of its type by using an assignment operator.To handle complex datatypes, it is possible to create a structure within another structure, which is called nested structures.It is possible to pass an entire structure, individual elements of structure, and address of structure to a function.It is possible to create structure pointers.The general form ... Read More

Find a Leap Year Using C Language

Bhanu Priya
Updated on 08-Mar-2021 10:09:07

368 Views

Leap year is a year that consists of 366 days. For every four years, we will experience a leap year.The logic we will implement to find whether the given year by the user through the console is a leap or not −if (( year%400 == 0)|| (( year%4 == 0 ) &&( year%100 != 0)))If this condition is satisfied, then the given year is a leap year. Otherwise, it is not.ExampleFollowing is the C program to check leap year with the help of If condition − Live Demo#include int main(){    int year;    printf("Enter any year you wish ... Read More

Display Complete Text One Word Per Line in C Language

Bhanu Priya
Updated on 08-Mar-2021 10:06:44

1K+ Views

First, open the file in write mode. Later on, enter the text until it reaches the End Of File (EOF) i.e. press ctrlZ to close the file.Again, open in reading mode. Then, read words from the file and print each word in a separate line and close the file.The logic we implement to print one word per line is as follows −while ((ch=getc(fp))!=EOF){    if(fp){       char word[100];       while(fscanf(fp, "%s", word)!=EOF) // read words from file{          printf("%s", word); // print each word on separate lines.       }     ... Read More

Accessing Structure Variable in C Language

Bhanu Priya
Updated on 08-Mar-2021 10:05:00

1K+ Views

The structure is a user-defined data type, which is used to store a collection of different data types of data.The structure is similar to an array. The only difference is that an array is used to store the same data types whereas, the structure is used to store different data types.The keyword struct is for declaring the structure.Variables inside the structure are the members of the structure.A structure can be declared as follows −Struct structurename{    //member declaration };ExampleFollowing is the C program for accessing a structure variable − Live Demostruct book{    int pages;    float price;    char author[20]; ... Read More

Access Array Element in C Language

Bhanu Priya
Updated on 08-Mar-2021 10:02:11

7K+ Views

An array is a group of related data items that share a common name. A particular value in an array is identified by using its "index number" or "subscript".The advantage of an array is as follows −The ability to use a single name to represent a collection of items and to refer to an item by specifying the item number enables the user to develop concise and efficient programs.The syntax for declaring array is as follows −datatype array_name [size];For example, float height [50]This declares ‘height’ to be an array containing 50 float elements.int group[10]This declares the ‘group’ as an array ... Read More

Find Profit or Loss in Buying an Article using C Program

Bhanu Priya
Updated on 08-Mar-2021 09:55:39

316 Views

The formula for finding profit is as follows if the selling price is greater than cost price −profit=sellingPrice-CosePrice;The formula for finding loss is as follows if cost price is greater than selling price −loss=CostPrice-SellingPriceNow, apply this logic in the program and try to find whether the person gets a profit or loss after buying any article −ExampleFollowing is the C program to find the profit or loss − Live Demo#include int main(){    float CostPrice, SellingPrice, Amount;    printf(" Enter the product Cost : ");    scanf("%f", &CostPrice);    printf(" Enter the Selling Price) : ");    scanf("%f", &SellingPrice);    if ... Read More

Write Temperature Conversion Table Using Function

Bhanu Priya
Updated on 08-Mar-2021 09:53:40

1K+ Views

Temperature conversion is nothing but converting Fahrenheit temperature to Celsius or Celsius to Fahrenheit.In this programming, we are going to explain, how to convert the Fahrenheit temperature to Celsius temperature and how to represent the same in the form of the table by using a function.ExampleFollowing is the C program for temperature conversion − Live Demo#include float conversion(float); int main(){    float fh,cl;    int begin=0,stop=300;    printf("Fahrenheit \t Celsius");// display conversion table heading    printf("----------\t-----------");    fh=begin;    while(fh

What is a Buffer in C Language?

Bhanu Priya
Updated on 08-Mar-2021 09:50:04

10K+ Views

A temporary storage area is called buffer. All input output (I/O) devices contain I/O buffer.When we try to pass more than the required number of values as input then, the remaining values will automatically hold in the input buffer. This buffer data automatically go to the next input functionality, if it is exists.We have to clear the buffer before the next input is taken in.ExampleFollowing is the C program for buffer −#include void main(){    int a, b;    printf(" Enter a value: ");    scanf("%d", &a);    printf(" Enter b value: ");    scanf("%d", &b);    printf(" a+b=%d ", ... Read More

Custom Header Files in C Language

Bhanu Priya
Updated on 08-Mar-2021 07:20:41

598 Views

ProblemCan the user create his/her own custom header files in the C language? If yes, how can we access the user-defined header files?SolutionYes, the user can create his/her own custom header files in C.It helps you to manage the user-defined methods, global variables, and structures in a separate file, which can be used in different modules.Let’s see an example of how to create and access custom header files −ExampleGiven below is the C program to call an external function named swap in the main.c file.#include #include"swaping.h" //included custom header file void main(){    int a=40;    int b=60;    swaping ... Read More

Advertisements