Posts

C program to express number into words.

There is an UNEQUAL amount of good and bad in most things, the trick is to work out the ratio and act accordingly - The Jester This is a program to express number into words. Examples: Input : 123 Output: One Hundred Twenty Three Input 123456 Output : One Hundred Twenty Three Thousand Four Hundred Fifty Six This post is divided into following parts. Expressing two digit number in words. Expressing three digit number in words. Expressing number in words. All code at once. Note : This program was compiled on DEV C++ Expressing Two Digit Number In Words :- Here is the code: char *tens(int n){ int a; char *p,temp[20]; char t1[][10]={"Zero","One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten", "Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen&quo

Difference between pre-increment and post-increment operator in C.

If you're not part of the solution, you're part of the precipitate. -Henry J. Tillman Greetings, today we are going to find out the difference between the pre-increment(++a) and post-increment(a++) operator in C- as the title says. The best way to learn anything is by example, so here it is, Example 1:-  //Pre-increment operator #include <stdio.h> int main(void) { int a=3; printf("%d",++a); return 0; } Output: 4 //Post-increment #include <stdio.h> int main(void) { int a=3; printf("%d",a++); return 0; } Output: 3 Explanation: As you can see there is difference in the output. The printf("%d",a++) is composed of two statements: printf("%d",a); a=a+1; In pre-increment,  a=a+1 ; is evaluated before printf("%d,"a); In post-increment,  printf ("%d",a); is evaluated  before a=a+1;
Greetings folks, today we are going to write a snake game in C. This post is going to be very long, so keep up with me. :) This is the snake game we are going to write. Contents:   Writing our own gotoxy(). Capturing the arrow keys. Moving a character in the screen according the arrow keys.  

Solution of Codeforces Round #244 (Div. 2) - Police Recruits in C.

The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom.” ― Isaac Asimov Again, I found this problem at http://codeforces.com/contest/427/problem/A . Here is the solution:- #include <stdio.h> #include <stdlib.h> int main(){ long police=0,unNoticedCrime=0,n,i; int x; fscanf(stdin,"%ld",&n); if(n>=1 && n<=100000){ for(i=0;i<n;i++){ fscanf(stdin,"%d",&x); switch (x){ case -1: if(police > 0) --police; else ++unNoticedCrime; break; default: police+=x; } } } fprintf(stdout,"%ld",unNoticeCrime); return(0); }

Solution of Codechef - May Challenge 2014 - Chef Jumping in C

"He who is fixed to a star does not change his mind. " -Leonardo da Vinci I found this problem at http://www.codechef.com/MAY14/problems/OJUMPS . Solution:- #include <stdio.h> int main(){ long long a;//i; int flag=0,r; char yes[]="yes",no[]="no"; fscanf(stdin,"%lld", &a); r=a % 6; flag=(r==0 || r==1 || r==3)? 1 : 0; if(flag){ fprintf(stdout,"%s",yes); }else{ fprintf(stdout,"%s",no); } return 0; }

C program to generate Fibonacci Series using recursion.

“Two things are infinite: the universe and human stupidity; and I'm not sure about the universe.” ― Albert Einstein Program 1:- #include <stdio.h> #include <conio.h> void fibo(long,long, long, long); int main(){ long n; printf("\n Enter number of fibonacci series : "); scanf(" %ld", &n); fibo(0,1,1,n); getch(); } void fibo(long a, long b, long i, long n){ long c; if (i<=n){ printf("\n %ld", a); c=a+b; a=b; b=c; fibo(a,b,i+1,n); } } Program 2:-   #include <stdio.h> #include <conio.h> long fibo(long); int main(){ long n,f,i; printf("\n Enter number of fibonacci series : "); scanf(" %l*d", &n); for(i=1;i<=n;i++){ f=fibo(i); printf("\n %ld", f); } getch(); } long fibo(long n){ long c; if (n==1){ return(0

C program to find the determinant of n by n matrix.

Image
Learn from yesterday, live for today, hope for tomorrow. The important thing is not to stop questioning. Albert Einstein Read more at http://www.brainyquote.com/quotes/authors/a/albert_einstein.html#Ib4lbZ3qWL8wS7TE.9 Learn from yesterday, live for today, hope for tomorrow. The important thing is not to stop questioning. Albert Einstein Read more at http://www.brainyquote.com/quotes/authors/a/albert_einstein.html#Ib4lbZ3qWL8wS7TE.99 Learn from yesterday, live for today, hope for tomorrow. The important thing is not to stop questioning. Albert Einstein Read more at http://www.brainyquote.com/quotes/authors/a/albert_einstein.html#Ib4lbZ3qWL8wS7TE.99 “You cannot teach a man anything; you can only help him discover it in himself.” -Galileo This program calculates the determinant of the matrix by using co-factor method which I read in my high school. It utilizes recursion also. Here are some snapshot of the program. Source Code: