A passionate CSE graduate from Bangladesh who tries to play with logic, solves puzzle,does code and loves to dream big :)

http://www.techtunes.com.bd/programming/tune-id/125550

https://progkriya.wordpress.com/page/2/http://ask.fm/shanto86

https://blog.codechef.com/2011/04/04/programmer-of-the-month-for-april-2011-md-mahbubul-hasan/

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
#include<stdio.h> int main() { char country[200]; int length; while(1==scanf("%s",country)) { length=string_length(country); printf("length:%d\n",length); } return 0; } int string_length(char str[]) { int i,length=0; for(i=0;str[i]!='\0';i++) { length++; } return length; } |

Another method:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#include<stdio.h> int main() { char country[200]; int length; while(1==scanf("%s",country)) { length=string_length(country); printf("length:%d\n",length); } return 0; } int string_length(char stro[]) { int i; for(i=0; stro[i]!='\0'; i++); return i; } |

With while loop:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
#include<stdio.h> int main() { char country[200]; int length; while(1==scanf("%s",country)) { length=string_length(country); printf("length:%d\n",length); } return 0; } int string_length(char stro[]) { int i; i=0; while(stro[i]!='\0'){ i++; } return i; } |

Lowercase to Uppercase

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#include<stdio.h> int main() { char country[]={'b','a','n','g','l','a','d','e','s','h'}; int i,length; printf("%s\n",country); length=10; for(i=0;i<length;i++){ if(country[i]>=97 && country[i]<=122) { country[i]='A'+(country[i]-'a'); } } printf("%s\n",country); return 0; } |

Uppercase to Lowercase

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#include<stdio.h> int main() { char country[]={'B','A','N','G','L','A','D','E','S','H'}; int i,length; printf("%s\n",country); length=10; for(i=0;i<length;i++) { if(country[i]>=65 && country[i]<=90) { country[i]='a'+(country[i]-'A'); } } printf("%s\n",country); return 0; } |

another method:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#include<stdio.h> int main() { char country[]={'B','A','N','G','L','A','D','E','S','H'}; int i,length; printf("%s\n",country); length=10; for(i=0;i<length;i++) { if(country[i]>=65 && country[i]<=90) { country[i]=country[i]+32; } } printf("%s\n",country); return 0; } |

for formula: http://www.mathsisfun.com/area.htm

code:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#include<stdio.h> double pi=3.1416; double britto(double r) { double area=pi*r*r; return area; } int main() { double r=3; double khetrofol=britto(r); printf("%lf",khetrofol); return 0; } |

We have to always remember that value that define is always pass from main function to customized function named by user so here r=3 is passing to function britto and then the britto formula pi*r*r is applying and returned the value and it is printed in the main function where the variable defined as khetrofol.

Here pi declared as global variable with it’s value.

Did this problem from subeen vai’s book.

For maximum value:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
#include<stdio.h> int find_max(int ara[],int n); int main() { int ara[]={-100,0,53,22,83,23,89,-132,201,3,85}; int n=11; int max=find_max(ara,n); printf("%d\n",max); return 0; } int find_max(int ara[],int n) { int max=ara[0]; //assume that first value of array according to index is maximum we will compare later with this int i; for(i=1;i<n;i++) { if(ara[i]>max) //here it is iterating the whole array { max=ara[i]; } } return max; } |

For minimum value:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
#include<stdio.h> int find_min(int array[],int n); int main() { int array[]= {20,10,-123,980,60,50,70}; int n=7; int min; min=find_min(array,n); printf("%d\n",min); return 0; } int find_min(int array[],int n) { int min=array[0]; int i; for(i=0; i<n; i++) { if(array[i]<min) { min=array[i]; } } return min; } |

Summation:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#include<stdio.h> int find_sum(int ary[],int valu); int main() { int ary[]={10,20,30}; int n=3; int sum; sum=find_sum(ary,n); printf("%d\n",sum); return 0; } int find_sum(int ary[],int n) { int i; int sum=0; for(i=0;i<n;i++) { sum=sum+ary[i]; } return sum; } |

Average:

Will give here

Posted in A ll Codes, ACM-ICPC, Array, Mathematics

My laptop was randomly freezing.So After a lot of hassle I have found that Nvidia graphics driver is the criminal for this situation.May be my laptop hangs for this randomly or bios could not find the real driver to make companion with the Nvidia PhysX GPU.

And another cause I have found that my old version adobe master collection CS 6 also making deadlocking situation with.windows.

Solution:

First clean install windows then update it fully.Then install driver one by one that is needed.Then install software you need and keep records.If anything harms for you then uninstall this soft after a hard restart if it is freezed thatt time.Or you can make login to ubuntu if it is installed in your pc then delete those files are hampering your work.And work perfectly in windows

Now everything is fine.Alhamdulillah

http://www.prothom-alo.com/bangladesh/article/580627/%E0%A6%97%E0%A6%A3%E0%A6%BF%E0%A6%A4-%E0%A6%85%E0%A6%B2%E0%A6%BF%E0%A6%AE%E0%A7%8D%E0%A6%AA%E0%A6%BF%E0%A7%9F%E0%A6%BE%E0%A6%A1%E0%A7%87%E0%A6%B0-%E0%A6%A4%E0%A6%BE%E0%A6%B0%E0%A6%95%E0%A6%BE%E0%A6%B0%E0%A6%BE-%E0%A6%95%E0%A7%87-%E0%A6%95%E0%A7%8B%E0%A6%A5%E0%A6%BE%E0%A7%9F

code:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#include<stdio.h> int main() { int ara[]={10,20,30,40,50,60,70,80,90,100}; //took this array for various limit int ara2[10]; //max value here will be 10 int i,j; for(i=0,j=9;i<10;i++,j--) //here in for loop will i value increase array index and j value will decrease array index { ara2[j]=ara[i]; //copying the values of ara[] to ara2[] } for(i=0;i<10;i++) { ara[i]=ara2[i]; //now after copying the value of ara2[i] where index i to 10 has took all the reverse value of ara[] to ara[i] directly it is copying now to ara[i] index i will be followed } for(i=0;i<10;i++){ printf("%d\n",ara[i]); //now printing from ara[i] value the reverse of ara[] finally } return 0; } |

Used Subeen vai’s book for the example

another:

1 2 3 4 5 6 7 8 9 10 11 12 |
#include<stdio.h> int main(){ int i,j,a1[]={10,20,40,60,70}; int a2[5]; for(i=0,j=4;i<5,j>=0;i++,j--){ a2[j]=a1[i]; } for(j=0;j<5;j++){ printf("%d\t",a2[j]); } return 0; } |

Multiple of 3 is

3×1=3

3×2=6

3×3=9

3×4=12

3×5=15

3×6=18

3×7=21

3×8=24

3×9=27

3×10=30

Multiple of 4 is

4×1=4

4×2=8

4×3=12

4×4=16

4×5=20

4×6=24

4×7=28

4×8=32

4×9=36

4×10=40

Here in 3 and 4 mutilples common is 12

and it is only one value and so it is the lowest also then but if there were some more values than result could be something changed.

So here LCM=12

Here I implemented the code

applied this formula

lcm(a,b)=a*b/gcd(a,b);

code goes here :

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
#include<stdio.h> int main() { int a,b,x,gcd,lcm; scanf("%d %d",&a,&b); if(a<b)//it is not possible for gcd to be greater than the lowest value { x=a; } else { x=b; } for( ;x>=1;x--){ //here i haven't initialized the value of x as x is first at outside if(a%x==0 && b%x==0){ gcd=x; break; //here i have used break as if it is not here then when the division will happen it will run the loop till 1 so answer will be always 1 } } printf("GCD is %d\n",gcd); lcm=a*b/gcd; printf("LCM is %d\n",lcm); return 0; } |

এখানে লজিকটা হচ্ছে…Here the logic is:

For 12:

1×12=12

2×6=12

3×4=12

So factor of 12=1,2,3,4,6,12

(We don’t need the negative values here)

For 30:

1×30=30

2×15=30

3×10=30

5×6=30

So factor of 30=1,2,3,5,6,10,15,30

Now which is the common factor among 12 and 30

So factor of 12=1,2,3,4,6,12

So factor of 30=1,2,3,5,6,10,15,30

common factor=1,2,3,6

Largest common factor here=6

So now if we divide 12/6 then we get 2

and for 30/6 we get 5

that is all divided perfectly so the logic should be like this

1.Find all the factors of each number

2. Circle the common factors

3. Choose the greatest of those

4. Divide the existing number with greatest common factor thern also get a perfect divide

Here is my code:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
#include<stdio.h> int main() { int a,b,x,gcd; scanf("%d %d",&a,&b); if(a<b)//it is not possible for gcd to be greater than the lowest value { x=a; } else { x=b; } for( ;x>=1;x--){ //here i haven't initialized the value of x as x is first at outside if(a%x==0 && b%x==0){ gcd=x; break; //here i have used break as if it is not here then when the division will happen it will run the loop till 1 so answer will be always 1 } } printf("GCD is %d\n",gcd); return 0; } |

Here is a link that described many thinks about this clearly: http://www.mathsisfun.com/greatest-common-factor.html

Another method can also apply here:

link for understanding the modarithmetic euclidean algorithmhttps://www.khanacademy.org/computing/computer-science/cryptography/modarithmetic/a/the-euclidean-algorithm

Code:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
#include<stdio.h> int main() { int a,b,t,x,gcd; scanf("%d %d",&a,&b); if(a==0) gcd=a; else if(b==0) gcd=b; else { while(b!=0) { t=b; b=a%b; a=t; } gcd=a; } printf("GCD is %d\n",gcd); return 0; } |