Posts

spoj CPTTRN1 - Character Patterns (Act 1) solution

Image
Using two characters: . (dot) and * (asterisk) print a chessboard-like pattern. The first character printed should be * (asterisk). Input You are given  t < 100  - the number of test cases and for each of the test cases two positive integers:  l  - the number of lines and  c  - the number of columns in the pattern ( l ,  c  < 100). Output For each of the test cases output the requested pattern (please have a look at the example). Use one line break in between successive patterns. Example Input: 3 3 1 4 4 2 5 Output: * . * *.*. .*.* *.*. .*.* *.*.* .*.*.    

POWER OF TWO OR NOT

Image
THE NUMBER IS A POWER OF TWO OR NOT

ASCII VALUE

Image
SOLUTION FOR ASCII VALUE IN HACKEREARTH QUESTION : Given a character  C C , print the ASCII value of that character. Input: First and only line in input contains a character  C C . Output: Print the ASCII value of the character  C C . Constraints: C ∈ C ∈   ASCII characters SAMPLE INPUT   b SAMPLE OUTPUT   98 SOLUTION : #include<stdio.h> int main(){     char t;     scanf("%c",&t);     printf("%d",(int)t);     }

BIRTHDAY PARTY

SOLUTION FOR BIRTHDAY PARTY HACKEREARTH Mr. X's birthday is in next month. This time he is planning to invite N of his friends. He wants to distribute some chocolates to all of his friends after party. He went to a shop to buy a packet of chocolates. At chocolate shop, each packet is having different number of chocolates. He wants to buy such a packet which contains number of chocolates, which can be distributed equally among all of his friends. Help Mr. X to buy such a packet. Input: First line contains T, number of test cases. Each test case contains two integers, N and M. where is N is number of friends and M is number number of chocolates in a packet. Output: In each test case output "Yes" if he can buy that packet and "No" if he can't buy that packet. Constraints: 1<=T<=20 1<=N<=100 1<=M<=10^5 SAMPLE INPUT   2 5 14 3 21 SAMPLE OUTPUT   No Yes SOLUTION : #include<stdio.h> int main(){

ROY AND PROFILE PICTURE

Image
   THE SOLUTION FOR ROY AND PROFILE PICTURE QUESTION : Roy wants to change his profile picture on Facebook. Now Facebook has some restriction over the dimension of picture that we can upload. Minimum dimension of the picture can be  L x L , where  L  is the length of the side of square. Now Roy has  N  photos of various dimensions. Dimension of a photo is denoted as  W x H   where  W  - width of the photo and  H  - Height of the photo When any photo is uploaded following events may occur: [1] If any of the width or height is less than L, user is prompted to upload another one. Print " UPLOAD ANOTHER " in this case. [2] If width and height, both are large enough and  (a) if the photo is already square then it is accepted. Print " ACCEPTED " in this case. (b) else user is prompted to crop it. Print " CROP IT " in this case. (quotes are only for clarification) Given L, N, W and H as input, print appropriate text as output. Input: Firs

pointers basics

Image
HELLO GUYS,HERE I WOULD LIKE TO DISCUSS ABOUT THE BASICS OF THE POINTERS IN DETAIL.IN ADVANCE I WILL DISCUSS LATER. 1)NOW,WHAT IS A POINTER ?? ANS : A POINTER IS NOTHING BUT IT IS A TOOL,WHICH KEEP TRACK OF THE SOMETHING OR IT EXACTLY SPECIFY THE LOCATION IS THE GENERAL DEFINITION OF THE POINTER . SAME IN THE CASE OF PROGRAMMING LANGUAGES . 2)WHAT IS THE POINTER AND HOW WE USE,IT ?? ANS : A POINTER IS VARIABLE(VARIABLE MEANS IT CHANGES TIME TO TIME, IN GENERAL ENGLISH). IN GENERAL,THE POINTER STORES THE ADDRESS OF ANOTHER VARIABLE OR DYNAMICALLY ALLOCATED MEMORY. IF SUPPOSE WE HAVE A POINTER THEN IT IS A TYPE INT POINTER,THEN IT POINTS TO THE ADDRESS OF THE VARIABLE OF THE TYPE INT.IN ABOVE, I DISCUSSED THAT POINTER A TOOL WHICH KEEPS TRACK OF VARIABLE, SO THAT WHICH SPECIFY THE LOCATION OF THE VARIABLE IN THE PROGRAM. NOTE : POINTERS CAN BE INTERCHANGEABLE ONLY IN SOME CASES.   IN GENERAL, POINTERS ARE ALSO MOST DIFFICULT WHILE DEBUGGING THE PROGRAM IF
Image
HI TO EVERY ONE AND ADVANCE IN THANKS FOR YOUR CONSTANT SUPPORT AND TODAY, I WOULD LIKE TO DICUSS ABOUT FUNCTIONS AND ITS DECLARATION AND PROTOTYPES OF FUNCTIONS AND USES. 1)WHAT IS A FUNCTION?? ANS :A function is a group of statements that together perform a task. Every C program has at least one function, which is  main() , and all the most trivial programs can define additional functions. From above  it is concluded that it is set of tasks performed in that program is known as functions. 2)WHAT ARE THE USES OF USING FUNCTIONS IN C?? ANS : The use of these functions is that  a program can be divided into simpler forms or smaller ones; and program can easily be written because while we are performing a subsequently large computing task then there is a necessity of using these functions. I hope , every understood the uses of functions for any more or useful information if have guys then please comment below, which will be beneficial for others guys. 3) HOW TO DEFINE THESE