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?

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

what is associativity explain what is the precidence for * and & , * and ++ how the folloing declaration work 1) *&p; 2) *p++;

2506


can any one please explain, how can i access hard disk(physical address)? it is possible by the use of far,near or huge pointer? if yes then please explain......

1987


How can I implement sets or arrays of bits?

1109


what is ur strangth & weekness

2562


write a program to find out prime number using sieve case?

2157


What are compound statements?

1268


In C language, the variables NAME, name, and Name are all the same. TRUE or FALSE?

1288


Is int a keyword in c?

1052


ATM machine and railway reservation class/object diagram

5328


Sir,please help me out with the code of this question. Write an interactive C program that will encode or decode multiple lines of text. Store the encoded text within a data file, so that it can be retrieved and decoded at any time. The program should include the following features: (a) Enter text from the keyboard, encode the text and store the encoded text in a data file. (b) Retrieve the encoded text and display it in its encoded form. (c) Retrieve the encoded text, decode it and then display the decoded text. (d) End the computation. Test the program using several lines of text of your choice.

2383


what is associativity explain what is the precidence for * and & , * and ++ how the folloing declaration work 1) *&p; 2) *p++;

2722


What is the general form of a C program?

1088


What is the difference between union and anonymous union?

1389


List at least 10 sorting methods indicating their average case complexity, worst case complexity and best case complexity.

2808


What are pointers? What are different types of pointers?

1251