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.
4/26/2021 3:57:12 AM
vivek_sai 0449
16 Answers
New AnswerIf 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!!!
// 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; }
Vivek Start learning C from here and write program https://www.sololearn.com/Course/C/?ref=app
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).
#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); } } } '
In turbo c++ pluss output comes hello why can u explain this main() { for(;0;) { printf("hello"); } } Output in TC++ ??