Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


how to write a c program to print list of fruits in
alpabetical order?



how to write a c program to print list of fruits in alpabetical order?..

Answer / Ajay Shankar Yadava

To create a C program that prints a list of fruits in alphabetical order, you can use an array or linked list and sort the elements using a comparison function such as 'qsort' from the standard library. Here's a simple example:

```c
#include <stdio.h>
#include <string.h>

struct Fruit {
char name[20];
};

int compare(const void *a, const void *b) {
return strcmp(((struct Fruit *)a)->name, ((struct Fruit *)b)->name);
}

void printFruits(struct Fruit fruits[], int size) {
qsort(fruits, size, sizeof(fruits[0]), compare);
for (int i = 0; i < size; ++i) {
printf("%sn", fruits[i].name);
}
}

int main() {
struct Fruit fruits[] = {"apple", "banana", "grape", "kiwi", "orange"};
printFruits(fruits, sizeof(fruits) / sizeof(fruits[0]));
return 0;
}

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

Explain what is the difference between a free-standing and a hosted environment?

1 Answers  


Write a program that his output * *** *****

1 Answers  


Famous puzzles which are generally asked by companies during interviews ?

1 Answers   3D PLM, Yahoo,


Name the language in which the compiler of "c" in written?

3 Answers   Bajaj,


What is function prototype in c language?

1 Answers  


how to implement stack operation using singly linked list

2 Answers  


What are high level languages like C and FORTRAN also known as?

1 Answers  


What is a keyword?

1 Answers  


What is c preprocessor mean?

1 Answers  


Write a C program to fill a rectangle using window scrolling

1 Answers  


how to make c program without a libary? e.g.#include<stdio.h> libary is not in c progaram.

2 Answers  


What is actual argument?

1 Answers  


Categories