Skip to main content

Posts

solution of -CIRCLE_E - Three Circle Problem (EASY) on spoj

solution- Given 3 distinct circles with positive integer radius  R1 ,  R2 , and  R3 , and arranged like in the picture below: Now, your task is to compute radius of small circle that can be created like yellow circle in the picture above. All circles in the picture above tangent each other. Input- The first line in the input data, there is an integer  T (0 <  T  ≤ 10 3 ) denoting number of test cases, than  T  lines follow. For each lines, there are three integer   R1 ,  R2 , and  R3 , (0 < { R1 , R2 , R3 } < 10 9 ) denoting radius of each circle like in the picture above. ATTENTION- take input in float- SYNTAX- #include<stdio.h> #include<math.h> #include<stdlib.h> int main() {double a,b,c,t; double r; scanf("%lf",&t); while(t--) { scanf("%lf%lf%lf",&a,&b,&c); if(a>0&&b>0&&c>0) { r=a*b*c/(2*sqrt(a*b*c*(a+b+...

solution of-BOMARBLE - D - Playing with Marbles on spoj

BOMARBLE - D - Playing with Marbles Pablo was assigned in his class to construct pentagons inside pentagons with marbles but he doesn’t know how many marbles he will need. He knows that for one pentagon he needs 5 marbles The only way he knows to insert a second pentagon is putting a marble in the middle of each segment and drawing three lines as shown. He puts a marble in the intersecting lines and removes them. To insert a third pentagon inside he first divides all segments in two including the ones that are not needed, and repeats the procedure. Drawing a second pentagon will require 12 marbles. A third pentagon will require 22 marbles. Given the information of how many pentagons will be created, write a program to calculate the number of marbles needed. solution- #include<stdio.h> int main() {int n,k; while(scanf("%d",&n)!=EOF) { if(n==0) break; else { k=5*n+((n-1)*(3*n-2))/2; printf("%d\n",k); } ...

Insertion sorting in c language

Insertion sorting in c language Sorting is the process of arrenging data in ascending or decending order. Like- dictionary You think that if alphabets is not in sorted way how you can find any word. To handle it we can sorted char,int. THEORY- in insertion sorting each next element is compare all element behind it. syntax- #include<stdio.h> int main() { int n,i,j,a[1000],temp; printf("enter how many no you wanted to sort\n"); scanf("%d",&n); printf("ENTER NO FOR SORTING\N"); for(i=0;i<n;i++) { scanf("%d",&a[i]); } for(i=0;i<n;i++) { temp=a[i]; for(j=i-1;j>=0;j--) if(a[j]>temp) { a[j+1]=a[j]; } else break; a[j+1]=temp; } printf("SORTED \n"); for(i=0;i<n;i++) { printf("%d\n",a[i]); } }                                      ...

Conditional statement in c language

Conditional statement This is very simple.you face these problem daily.if you want to go to market and go to park . But at a time you can go only one place either market or park. In programming you also face these problems. These are given below 1 .if 2.if-else 3.if-else-if 4.nested if If statement- statement is execute when condition is true other wise it will terminated from loop. #include<stdio.h> int main( ) { if(condition)           {              statement;           } } FLOW CHART OF IF STATEMENT- 2.if-else statement- general syntax of if-else statement- #include<stdio.h> int main( ) { if(condition) { statement1; } else { statement 2; } EXPLAINATION- if condition true than  statement 1 execute otherwise it will be terminated. flow chart of if-else- 3.if-else-if General  syntax of if else if #include...

Basic of c language

The general syntax of c language is- #include <stdio.h> int main () { } Firstly we should know about the data type There are several data type 1.int Int is used for integer variable 2.char Char is used for char value 3.float - Float is used for decimal value Basically they define what type of data .And then do operation on it. Variables - Variable is a word that store value. Header file- For example- #include <stdio.h> It means that what type of operation We do and that operation is define in that header file Terminating semicolons- ; Is mean that statement is end. Int main( ) Is should be added in every c program. S ize of data type- Type Storage size Value range char 1 byte -128 to 127 or 0 to 255 unsigned char 1 byte 0 to 255 signed char 1 byte -128 to 127 int 2 or 4 bytes -32,768 to 32,767 or -2,147,483,648 to 2,147,483,647 unsigned int 2 or 4 bytes 0 to 65,535 or 0 to 4,294,967,295 short 2 bytes -3...

Best introduction to c language

Introduction to C language c language is a programming language that  is used to solve problem.to make operator system.etc If you are beginner in programming your language should be c. Becuase it provide you all the basic concept of other languages like --python It provide you basic error understanding ability. Before moving on programming you should know about what topic is in c language. If you want to do any field of computer science you should learn c in very effective way. I promise you after reading whole blog you feel like a programmer. 1.Basic in this section we learn about type of data .thier size . 2.Arithmatic operator  in this section we learn about simple +,-,×,%,/ 3.For loop  4.while loop 5.do -while loop  6.Array  7.function 8.pointer  9.Sorting in this section we will talk about  1.quick sort 2.selection sort 3.insertion sort  10.searching 1.linear searching 2.binary searc...

solution of PRIME1 - Prime Generator on spoj

PRIME1 - Prime Generator solution- #include<stdio.h> #include<math.h> int main() {int t; long long int l,h,i,flag; scanf("%d",&t); while(t--) { scanf("%lld%lld",&l,&h); while(l<=h) { flag=0; for(i=2;i<=sqrt(l);i++) { if(l%i==0) { flag=1;     break; } } if(flag==0) { if(l!=1) printf("%lld\n",l); } l++; } printf("\n"); } return 0; }