Skip to main content

Posts

Showing posts from September, 2019
STRUCTURE:BUILDING Structures : Building Create a structure called Building. struct Building { char name[100]; float length; float width; float height; float ratePerSqFt; }; Write a program to get the details of 'n' buildings and to display the name, area and rate for painting the inner side of the building per square feet of each building, sorted by name in ascending order. Length, width and height of the building are given in feet. The flooring is also done with the same rate. Input and Output Format: Refer sample input and output for formatting specification. All float values are displayed correct to 2 decimal places. All text in bold corresponds to input and the rest corresponds to output. Sample Input and Output: Enter the number of buildings 2 Enter the details of building 1 Enter name Vikram Enter length 200 Enter width 150 Enter height 10 Enter rate per square feet 650.5 Enter the details of building 2 Enter name Ganesh Enter length 1...
CROP STRUCTURE Crop structure Jack is an application software developer recently he has been assigned to a new project for crop management by the government. Actually, his task is to develop an app which will maintain the crop details like required rainfall, the temperature suitable for the growth of the plant, sow date, and harvest date. The Government would need to plan the budget for crops during the start of the financial year, for which required water quantity, pesticide, infrastructure to maintain temperature all are factors that affect harvest date of a crop. So help Jack in building filters by temperature and rainfall and sort the crops by sow date, harvest date. This will help the government to plan budget according to the sow and harvest date. Create a structure called Date. struct Date{ int dd; int mm; int yyyy; }; Create a structure called Crop. struct Crop{ char name[30]; float rainfall; int temperature; Date sowDate; Date ...
CROP DETAILS Crop Details A small farmer, Mr.John, use to grow different crops every year in his field. All the crops are being grown using goat manure, farmyard manure, groundnut and neem cake. All the crops are grown organically. He got high yield by using sufficient water and fertilizers at in this year. He will sell his crops in the market. In the market, he wants to maintain the details of each crop that are purchased by customers. Details like crop name, the weight of the crop, cost of the crop Display the details of crops in ascending order of crop names. Create a structure called crop. struct crop{ char cropName[30]; float weight; int cost; }; Input and Output Format: Refer sample input and output for formatting specification. All float values are displayed correctly to 2 decimal places. All text in bold corresponds to the input and the rest corresponds to output. Sample Input and Output: Enter the number of Crops 2 Enter the details of Crop 1 Enter name...
EXAMINATION SCAM 3 Examination Scam 3 Now a days in online examination there has been many fraudulent activities.Since online examination takes place virtualy its easy for the corrupts to gain money from it. One such fraudulent activity is providing fake registration links to the participants and collecting the fee from them.Due to this activity the legitimate online examination boards are hindered.As they are the once held responsible for the fees collected.There is also the case of an applicant registering using fake credentials.Applying more then once for a particular examination. To curb such bogus registration, the government has decided to tag the Aadhar number with every application. Then it collates the list of Aadhar numbers available in all application in the region. The authorities want to detect whether a particular Aadhar number appears multiple times in the list. Can you help them by writing a program to count the number of times 5 appears in an array? Note :...
EXAMINATION SCAM 1 Examination Scam 1 Now a days in online examination there has been many fraudulent activities.Since online examination takes place virtualy its easy for the corrupts to gain money from it. One such fraudulent activity is providing fake registration links to the participants and collecting the fee from them.Due to this activity the legitimate online examination boards are hindered.As they are the once held responsible for the fees collected.There is also the case of an applicant registering using fake credentials.Applying more then once for a particular examination. To curb such bogus registration activity,the online examination board has decided to allot a random number to each applicants. This random number is valid only if it contains a specific number of 5’s. (digit 5). Can you help them by writing a program to count the occurrences of 5 as a digit in the random number ‘n’ that is generated? Note : Formulate a RECURSIVE Algorithm Function name: int f...
COMBINATION OF CROPS Combination Of Crops John is a young farmer. He practiced precision farming in turmeric and he sowed the turmeric rhizomes after plowing the land well. He also grew onion, coriander, chilies, and red gram as intercrops. He got high yield by using sufficient water and fertilizers at a correct time. From the profit, he purchased N number of fields.So he is planning to grow different crops in that purchased fields. There are 'n' fields and 'r' crops. Help him to find the total number of different combinations in which the crops can be planted in the purchased fields. Hint: Use the formula nCr = (n-1)Cr+(n-1)C(r-1). Note: Function name: int combination(int n,int r); Input Format: The first input is an integer which corresponds to the 'n' value indicates a number of fields. The second input is an integer which corresponds to the 'r' value indicates a number of crops. Output Format: The output is an integer that corresponds to...
TOTAL Total One day John bought a bag full of different variety of apples. He wanted to sell them, but he doesn't know the total number of apples in the bag. He asks for Jack's help to find the total number of apples in the bag. Write a program to find the total number of apples using recursion. Note : Formulate a RECURSIVE Algorithm. Note: 1) Use the function, int sumOfArray(int *a,int n), with 2 parameters. First parameter is an integer pointer(representing the array), and the second paramenter is an integer(representing the size of the array). 2) Use malloc method to create the array. Input Format: The first line of input consists of integer 'N' (number of a variety of apples). The second line of input consists of 'N' values (number of apples of each variety). Output Format: The output consists of integer (total sum). Sample Input: 4 2 3 2 1 Sample Output: 8 #include #include #include int sumOfArray(int *a,int n) { if(n
FACTORIAL Factorial A farmer used to grow the same crop every year. This year because of better water availability, he decides to grow different crops. He doesn't know how to arrange those crops in the field. Assume the number of distinct crops he wants to grow is N. Can you help the farmer to find the total number of ways N distinct crops can be arranged in the field? Note : Formulate a RECURSIVE Algorithm Function name: int nWays(int n); Input Format: Input consists of a single integer N. Output Format: Refer the sample output for specification. Sample Input: 5 Sample Output: 120 ways #include int nWays(int n) { if(n>=1) return(n*nWays(n-1)); else return 1; } int main() { int N; scanf("%d",&N); printf("%d ways",nWays(N)); return 0; }
NUMBER OF BITS TO BE FLIPPED TO CONVERT A TO B Number of bits to be flipped to convert A to B Given two numbers A and B, write a program to find the number of bits to be flipped to convert A to B.Using EX-OR(^) and bitwise AND(&) operator. Input Format: Input consists of 2 integers --- A , B Output Format: Output is an integer that corresponds to the number of bits to be flipped to convert A to B. Refer sample input and output for formatting specifications. Sample Input 1 : 2 4 Sample Output 1 : 2 Explanation for Sample 1: A=2 B=4 Binary representaion of 2 = 00000010 Binary representaion of 4 = 00000100 To convert A to B, 2 bits needed to be shifted.(00000010) #include int bitcount(int); int main() { int A,B,c,y; scanf("%d",&A); scanf("%d",&B); c=A^B; y=bitcount(c); printf("%d",y); return 0; } int bitcount(int x) { int i; for(i=0;x!=0;x>>=1) if(x&01) i++; return i; ...
SMALLEST NUMBER Smallest Number Write a program to find the smallest of two numbers.Using EX-OR(^) and bitwise AND(&) operator. Input Format: First line of input is an integer that corresponds to the first number. Second line of input is an integer that corresponds to the second number. Output Format: Output consists of an integer that corresponds to the smallest of the two numbers. Refer sample input and output for formatting specifications. Sample Input 1: 15 5 Sample Output 1: 5 Sample Input 1: 25 64 Sample Output 1: 25 #include int main() { int x,y; scanf("%d%d",&x,&y); printf("%d",(y^((x^y) & -(x
TOTAL SET BITS Total Set Bits Given the number N, write a program to count the total set bits in all the numbers from 1 to N.Using Right Shift (>>) and Bitwise AND(&) operators. Input Format: Input consists of an integer that corresponds to the value of N. Output Format: Output consists of an integer that corresponds to the number of set bits from 1 to N. Sample Input 1 : 3 Sample Output 1: 4 Sample Input 2: 6 Sample Output 2: 9 Explanation for Sample 1: N = 3 No of 1's in 1 = 1 (00000001) No of 1's in 2 = 1 (00000010) No of 1's in 3 = 2 (00000011) Total 1's = 1+1+2 = 4 #include int main() { unsigned int c,n,i,r=0; scanf("%d",&n); for(i=1;i >=1) { p+=c&1; } r+=p; } printf("%d",r); return 0; }
Carrot Plantation After calculating the yield from each plant John found that too much water flow to the carrot plants has reduced the yield from carrot plants. So he puts the meshes before and after each carrot plant position. Symbol of each vegetable is given below P = Potato O = Onion C = Carrot R = Raddish Help John in writing a program for making safety precautions for stopping more amount of water flow by '#' symbol before and after the Carrot plant position. Assume the maximum length of the string to be 100. Input format: The input is the string. Output format: The output is the string which includes the # symbol before and after 'C'. Sample Input 1: RRORPCOPCP Sample Output 1: RRORP#C#OP#C#P Sample Input 2: PCCOP Sample Output 2: P#C#C#OP #include int main() { char s1[20],s2[50]; scanf("%s",s1); char *p1=s1; char *p2=s2; while(*p1 != '\0') { if(*p1 != 'C') { *p2=(*p1); ...
Crop Rotation Crop rotation is the practice of growing a series of dissimilar or different types of crops in the same area in sequenced seasons. It is done so that the soil of farms is not used for only one set of nutrients. It helps in reducing soil erosion and increases soil fertility and crop yield. In crop rotation technique, there are four strategies. Out of those, 1) Two field system 2) Three field system are popularly followed. Two Field System: Under a two-field rotation, half the land was planted in a year, while the other half lay fallow. Then, in the next year, the two fields were reversed. Three-field system: Dividing available lands into three parts. One section was planted in the autumn with rye or winter wheat, followed by spring oats or barley; the second section grew crops such as peas, lentils, or beans; and the third field was left fallow. The three fields were rotated in this manner so that every three years, a field would rest and...
Weed Removal A farmer removes the weeds from the square field in the reverse spiral format. Given the weed allignment in the field, determine the order in which he removes the weeds. Input Format: The first line of input consists of a number corresponding to the square field. From the second line, the input consists of values in the square matrix. Output Format: The order of the weed in which it is removed. Sample Input: 4 12 32 34 13 23 15 55 21 21 14 16 51 66 23 34 32 Sample Output: 12 23 21 66 23 14 15 32 34 55 16 34 32 51 21 13 #include #include int main() { int i,j,m,*p; scanf("%d",&m); p=(int*)malloc(m*m*sizeof(int)); for(i=0;i =0;i--) { printf(" %d ",*(p+i*m+j)); } } j++; } return 0; }
Natural Pest Control Measure If a plant at a given coordinate in the field is damaged by the pest, then farmer removes all the plants in that row and column, where the damaged plant is present. The plants are denoted by numbers. Given the arrangement of plants in the matrix format and the coordinates of the damaged plant, write a program to remove all plants in that row and column. The removed plants are denoted by '0'. Input Format: The first line of input consists of two integers m and n(rows and column of the matrix). The next m lines of input consists of values in the matrix. The last line of input is row and column number where the infected plant is present. Output Format: Refer sample output . Sample Input : 5 4 12 32 34 12 23 15 55 21 21 14 16 51 12 23 34 32 12 32 43 64 2 3 Sample Output: 12 32 34 0 23 15 55 0 0 0 0 0 12 23 34 0 12 32 43 0 #include #include int main() { int i,j,m,n,*p,a,b; scanf("%d",&m); scanf("%d",...
MATRIX SUM Matrix Sum Write a program to find the sum of the elements in the matrix. Input Format: The input consists of (m*n+2) integers. The first integer corresponds to m, the number of rows in the matrix and the second integer corresponds to n, the number of columns in the matrix. The remaining integers correspond to the elements in the matrix. The elements are read in row-wise order, first row first, then second row and so on. Assume that the maximum value of m and n is 10. Output Format: Refer sample output for details. Sample Input 1: 3 2 4 5 6 9 0 3 Sample Output 1: The sum of the elements in the matrix is 27 #include #include int ** createMatrix(int,int); void readMatrix(int **, int, int); int findSum(int **, int, int); int main() { int m,n; //printf("Enter Rows"); scanf("%d",&m); //printf("Enter Columns"); scanf("%d",&n); int **p = createMatrix(m,n); readMatrix(p,m,n); int sum = findSum...
Pairs of Files The files related to the exminations are arranged in a separate shelf.There is a separate file for each examination.All these files are given a unique number which is the same as the examination Id . At a pariticular day two examinations took place.The files consisted of the details about the examination.The Files Incharge was given the 2 examination ID's and he was asked to bring the 2 files. But unfortunately he forgot the 2 examination ID's but he remembers that the difference between the 2 examination ID's is K. Can you help him in finding the number of pairs of files where the difference between the 2 examination ID's is K? Input Format : The first line of the input consists of an integer ‘n’ that corresponds to the number of files. The next ‘n’ lines of the input correspond to the numbers written on the files. The last line of the input consists of an integer K that corresponds to the difference. Output Format: Output consists of a single ...
TABLETS Tablets The exams were conducted through the means of tabs,the examiners provided tabs to the candidates taking the online exam in each center. They have sourced around ‘X’ tabs. There are ‘n’ examination centres in the region.There is a list that gives the details of the candidates strength in each of these centers. The tabs has to be distributed in as many centers as possible.Each candidate receives a tablet to take on the test. Tablets are provided to the exam centers only when it is possible to give a tab to all the candidates or else the candidates in those center will take part in the online exams through other means. What would be the maximum number of exam centers to which he can provide the tabs? Input Format : The first line of the input consists of an integer ‘n’ that corresponds to the number of exam centers in that region. The next n lines of the input consists of one integer each that correspond to the candidate strength in the n centers. The last line of...
BATCH FILE Batch File The candidates registered for the online examinations,are split into batches.There is a separate file for each batch . All these files are marked by a number which denotes the number of days to go for the examination.If a batch finished their exam, then that particular file is numbered as 0. The files incharge need to rearrange the files such that all files numbered 0 should be placed at the end of the shelf. The order of the other files should not be changed. Find the order in which the files will be placed in the shelf after rearrangement. Input Format : The first line of the input consists of an integer n that corresponds to the number of files. The next ‘n’ lines of the input correspond to the numbers written on the files. Output Format: Output consists of ‘n’ integers. Refer Sample Output. Sample Input 1: 4 1 3 0 2 Sample Output 1: 1 3 2 0 Sample Input 2 : 4 1 2 3 0 Sample Output 2 : 1 2 3 0 Sample Input 3 : 4 1 2 3 4 Sample Output 3 : 1 2 3 4 ...
INTELLIGENCE BUREAU III Intelligence Bureau III The Intelligence Bureau (IB) is India's internal intelligence agency. It was recast as the Central Intelligence Bureau in 1947 under the Ministry of Home Affairs. In 1909, the Indian Political Intelligence Office was established in England in response to the development of Indian revolutionary activities, which came to be called the Indian Political Intelligence (IPI) from 1921. This was a state-run surveillance and monitoring agency. The IPI was run jointly by the India Office and the Government of India and reported jointly to the Secretary of the Public and Judicial Department of the India Office, and the Director of Intelligence Bureau (DIB) in India, and maintained close contact with Scotland Yard and MI5. The Assistant Central Intelligence Officer(ACIO) exam is conducted every year, in one such exam, the marks were distributed as X,Y,Z. A person from exam centre was interested in finding whether these 3 values X,Y,Z are eve...
INTELLIGENCE BUREAU I Intelligence Bureau I The Intelligence Bureau (IB) is India's internal intelligence agency. It was recast as the Central Intelligence Bureau in 1947 under the Ministry of Home Affairs. In 1909, the Indian Political Intelligence Office was established in England in response to the development of Indian revolutionary activities, which came to be called the Indian Political Intelligence (IPI) from 1921. This was a state-run surveillance and monitoring agency. The IPI was run jointly by the India Office and the Government of India and reported jointly to the Secretary of the Public and Judicial Department of the India Office, and the Director of Intelligence Bureau (DIB) in India, and maintained close contact with Scotland Yard and MI5. The Assistant Central Intelligence Officer(ACIO) exam is conducted every year in which the exam fees differ for men,women and sc/st. Let A denote the exam fees for women. Let B denote the exam fees for sc/st. Let C denote the...
FARM DEVELOPMENT Farm development Jack made the list of naturally occurring pesticides and wanted to use the best and most used pesticide worldwide. So he did a survey from 'n' countries to know which pesticide is used in major. Naturally occurring Pesticides 1) Bacillus thuringiensis 2) Pyrethrum 3) Spinosad 4) Neem 5) Rotenone In the survey, he found all the pesticides were rated closely. Help him decide which one to use by writing a program with sorting. Input format: The first line of the input corresponds to n. The next n inputs correspond to the naturally occurring pesticide number used in major. Output format: The output is an integer which corresponds to the naturally occurring pesticide number and the frequency used. If a particular pesticide is not used at all, don't display it in the output. Sample Input: 10 1 2 1 3 2 4 3 5 4 2 Sample Output: 1 - 2 2 - 3 3 - 2 4 - 2 5 - 1 include #include int main() { int *p; ...
FRUIT YIELDING TREE Fruit yielding tree Jack owned a farm which had ‘n’ fruit trees. He sold a tree from the farm which yielded the maximum number of fruits. Now, he wanted to find the tree that yielded the second maximum number of fruits. Write a program to help Jack in finding the second largest fruit yielding tree without sorting. Function Specification: int secondLargest(int *, int); Input format: The first line of the input corresponds to the n. The next n inputs correspond to the number of fruits yielded by each tree.(Assume number of fruits yielded by each tree is unique) Output format: The output is an integer which corresponds to the second largest fruit yielding tree from the farm. Sample Input: 7 7 5 8 6 9 4 3 Sample Output: 8 #include #include int secondLargest(int*a,int n); int main() { int i,n; int *p; scanf("%d",&n); p=(int*)malloc(n*sizeof(int)); for(i=0;i f) ...
SEARCHING AN ARRAY Write a program to search for an element ‘a’ in the array. Assume that the maximum size of the array is 15. Input Format: Input consists of n+2 integers. The first integer corresponds to ‘n’ , the size of the array. The next ‘n’ integers correspond to the elements in the array. The last integer corresponds to ‘a’, the element to be searched. Output Format: Refer sample output for details. Sample Input 1: 5 2 3 6 8 1 6 Sample Output 1: 6 is present in the array Sample Input 2: 5 2 3 6 8 1 9 Sample Output 2: 9 is not present in the array #include int main() { int i,n,a,A[30]; //printf("enter the value n"); scanf("%d",&n); //printf("enter elements"); for(i=0;i