Write a c program | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

Write a c program

8. There are four types of fruits Apples, Oranges, Bananas and Grapes. Each student can pick up two fruits. There are some conditions which have to be used to pick up the fruits. Draw a flow chart which can take the name of first fruit as an input and print the names of second fruit or fruits that can be picked up. The conditions are: • If you pick an apple you can pick banana. • If you pick orange you can pick grapes. • If you pick grapes you can pick banana. Hint: There will be one input box to read the first fruit, three decision boxes and four output boxes in the flowchart. Use “ “ for string and == operator.

26th Apr 2021, 3:57 AM
KODURU VIVEK SAI REDDY
KODURU VIVEK SAI REDDY - avatar
14 Answers
+ 8
If you are a beginner, just go through the tutorials first.. It's the program which covers the basic concept of conditional stmts.. Go through them and try it first.. If you still stuck anywhere then come here.. As they mentioned, try the flowchart first.. Using that you can automatically convert it into code by yourself. It's not that hard!!!
26th Apr 2021, 4:03 AM
sarada lakshmi
sarada lakshmi - avatar
+ 5
I did it is their any worng in this
26th Apr 2021, 4:19 AM
KODURU VIVEK SAI REDDY
KODURU VIVEK SAI REDDY - avatar
+ 3
// Created by Vivek #include<stdio.h> #include<string.h> int main() { printf("Picking of fruit\n"); printf("PICK ANY TWO FRUITS FROM \nAPPLE\nBANANA\nGRAPE\nORANGE\n"); char i[10]; int n; gets(i); n = 0; while(n<2) { if (!strcmp(i,"apple")||!strcmp(i,"Apple")) { printf("U CAN PICK BANANA also\n"); } else if(!strcmp(i,"orange")||!strcmp(i,"Orange")) { printf("U CAN PICK GRAPES also\n"); } else if(!strcmp(i,"grapes")||!strcmp(i,"Grapes")) { printf("U CAN PICK BANANA also\n"); } else if(!strcmp(i,"banana")||!strcmp(i,"Banana")) { printf("U CAN PICK APPLE also\n"); } n+=1; if(n<2) { gets(i); } } return 0; }
26th Apr 2021, 6:54 PM
KODURU VIVEK SAI REDDY
KODURU VIVEK SAI REDDY - avatar
+ 2
Just tell it
26th Apr 2021, 4:19 AM
KODURU VIVEK SAI REDDY
KODURU VIVEK SAI REDDY - avatar
+ 2
Onwards
26th Apr 2021, 4:27 AM
KODURU VIVEK SAI REDDY
KODURU VIVEK SAI REDDY - avatar
26th Apr 2021, 4:30 AM
KODURU VIVEK SAI REDDY
KODURU VIVEK SAI REDDY - avatar
+ 1
Vivek Start learning C from here and write program https://www.sololearn.com/Course/C/?ref=app
26th Apr 2021, 4:03 AM
A͢J
A͢J - avatar
+ 1
Vivek It would be better & easy to trace if you provide the i/p and o/p formats..
26th Apr 2021, 4:22 AM
sarada lakshmi
sarada lakshmi - avatar
+ 1
Guys if know tell me or leave it guys
26th Apr 2021, 4:27 AM
KODURU VIVEK SAI REDDY
KODURU VIVEK SAI REDDY - avatar
+ 1
I am asking yesterday onwary
26th Apr 2021, 4:27 AM
KODURU VIVEK SAI REDDY
KODURU VIVEK SAI REDDY - avatar
+ 1
You have to make variables to assign values to them (so you can't write char "Apple"), you can't save strings inside char, char stores single chraracter. Make char array or char pointers to save these strings. You also can't compare strings in C using == operator. This operator is comparing adresses of strings (you can compare characters, but not strings with it!) Use strcmp to compare these strings (strcmp is inside string.h header file).
26th Apr 2021, 5:14 AM
Michal Doruch
+ 1
This is the right answer
26th Apr 2021, 6:54 PM
KODURU VIVEK SAI REDDY
KODURU VIVEK SAI REDDY - avatar
0
#include<stdio.h> #include<string.h> void main() { printf("Picking of fruit\n"); printf("PICK ANY TWO FRUITS FROM \nAPPLE\nBANANA\nGRAPE\nORANGE\n"); char "apple","orange","banana","grape"; char i[10]; int n; gets(i); n = 0; while(n<2) { if (i=="apple"||i=="Apple") { printf("U CAN PICK BANANA also\n"); } else if(i=="orange"||i=="Orange") { printf("U CAN PICK GRAPES also\n"); } else if(i=="grapes"||i=="Grapes") { printf("U CAN PICK BANANA also\n"); } else if(i=="banana"||i=="Banana") { printf("U CAN PICK APPLE also\n"); } n+=1; if(n<2) { gets(i); } } } '
26th Apr 2021, 4:18 AM
KODURU VIVEK SAI REDDY
KODURU VIVEK SAI REDDY - avatar
0
In turbo c++ pluss output comes hello why can u explain this main() { for(;0;) { printf("hello"); } } Output in TC++ ??
27th Apr 2021, 3:56 AM
Abhishek
Abhishek - avatar