Skip to main content

Posts

Showing posts from January, 2019

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]); } }                                         exit if you have any doubt pl

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<stdio.h> int main( ) { if(condition1) { statement1; } else if(condition 2) {

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 searching  11.link list  1.singly link l

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; }

solution of TRICOUNT - Counting Triangles on spoj

  TRICOUNT - Counting Triangles solution- #include<stdio.h> int main() {     int t;     scanf("%d",&t);     while(t--)     {         long long unsigned num,sum;         scanf("%llu",&num);         if(num%2==0)         sum=(num*(num+2)*((2*num)+1))/8;         else         sum=((num*(num+2)*((2*num)+1))-1)/8;         printf("%llu\n",sum);     }     return 0; }

MAXLN - THE MAX LINES on spoj

question-MAXLN - THE MAX LINES sol- #include<stdio.h> #include<math.h> int main() {int t,i; long long int r; double s; scanf("%d",&t); for(i=1;i<=t;i++) { scanf("%lld",&r); s=(4*r*r)+0.25; printf("Case %d: %0.2lf",i,s); printf("\n"); } }

solution of GERGOVIA - Wine trading in Gergovia on spoj

solution-GERGOVIA - Wine trading in Gergovia #include <stdio.h> #include <math.h> int main(void) { while(1){     int n;     scanf("%d",&n);     if(n==0)     break;     int i,a[n],j,g;     for(i=0;i<n;i++)     scanf("%d",&a[i]);          long long int s=0;          for(i=0;i<n;i++){              g=abs(a[i]);              s=s+g;              a[i+1]=a[i+1]+a[i];          }            printf("%lld\n",s); } return 0; }

solution-FASHION - Fashion Shows on spoj

solution-FASHION - Fashion Shows #include<stdio.h> int main() {int m[1001],w[1001],i,j,temp,t,n; scanf("%d",&t); while(t--) { int sum=0; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&m[i]); } for(i=0;i<n;i++) { scanf("%d",&w[i]); } for(i=0;i<n-1;i++) { for(j=i+1;j<n;j++) if(m[i]>m[j]) { temp=m[i]; m[i]=m[j]; m[j]=temp; } } for(i=0;i<n-1;i++) { for(j=i;j<n;j++) if(w[i]>w[j]) { temp=w[i]; w[i]=w[j]; w[j]=temp; } } for(i=0;i<n;i++) { sum=sum+m[i]*w[i]; } printf("%d\n",sum); } }

solution of CEQU - Crucial Equation on spoj

solution -CEQU - Crucial Equation  #include<stdio.h> int main() { long long int a,b,x,c,i,t; scanf("%lld",&t); for(i=1;i<=t;i++) { scanf("%lld%lld%lld",&a,&b,&c); while(b!=0) { x=a%b; a=b; b=x; } if(c%a==0) { printf("Case %lld: Yes",i); printf("\n"); } else     {printf("Case %lld: No",i); printf("\n");     } } return  0; }

solution of ATOMS - Atoms in the Lab on spoj

SOLUTION-ATOMS - Atoms in the Lab #include <stdio.h> #include<math.h> int main() {     long long int p,n,k,m,i;     scanf("%lli",&p);     while(p--)     {         scanf("%lld %lld %lld",&n,&k,&m);         i=1;         while(pow(k,i)<=(m/n))          i++;         printf("%lld\n",i-1);     }     return 0; }

solution of-AP2 - AP - Complete The Series (Easy) on spoj

AP2 - AP - Complete The Series (Easy) solution- #include<stdio.h> int main() { int i,t,j; long long int n,a,k,b,d,o,sum; scanf("%d",&t); for(j=0;j<t;j++) {  scanf("%lld%lld%lld",&a,&b,&sum); n=2*sum/(a+b);    d=(b-a)/(n-5);    k=a-2*d;    printf("%lld\n",n);    for(i=1;i<=n;i++)    {     o=k+(i-1)*d;   printf("%lld ",o);    }    printf("\n");    } return 0; }

solution of ADDREV - Adding Reversed Numbers on spoj

ADDREV - Adding Reversed Numbers on spoj- #include<stdio.h> int main () {   int n,k,p = 0,q=0,x,a,y,t=0,z,s,i;   scanf("%d\n",&k);   for(i=0;i<k;i++)  { scanf ("%d%d", &n,&a); {while (n != 0)     {       x = n % 10;       p = p * 10 + x;       n = n / 10;     }         while(a!=0)     {         y=a%10;         q=q*10+y;         a=a/10;     }     z=p+q; while(z!=0) {     s=z%10;     t=t*10+s;     z=z/10;     }     printf("%d\n",t); t=0; p=0; q=0; }}   return 0; }