Posts

Showing posts from October, 2011

To display sum of first n numbers using while loop #c

//The Program By Tittu Varghese // To display the sum of first n numbers. #include<stdio.h> #include<math.h> #include<conio.h> void main() {int i,n,s; i = 0; s = 0; printf("Enter the value of n to find sum of n numbers\n"); scanf("%d",&n); while (i <= n) {s = s+i; i = i+1; } printf("The sum of first %d numbers is %d\n",n,s); getch(); } //The Program By Tittu Varghese // To display the sum of first n even numbers. #include<stdio.h> #include<math.h> #include<conio.h> void main() {int i,n,s; i = 2; s = 0; printf("Enter the value of n to find sum of n even numbers\n"); scanf("%d",&n); while (i <= n+n) {s = s+i; i = i+2; } printf("The sum of first %d even numbers is %3d\n",n,s); getch(); } //The Program By Tittu Varghese // To display the sum of first n odd numbers. #include<stdio.h> #include<math.h> #include<conio.h>

To display n numbers using while loop. #c

//The Program By Tittu Varghese //To display n numbers. #include<stdio.h> #include<conio.h> void main() { int a,b,i,n; i = 1; printf("How many numbers you need to display ?"); scanf("%d",&n); while (i <= n) {b = i;  printf("%d,",b);  i = i+1;   }  getch(); } //The Program By Tittu Varghese //To display n even numbers.     #include<stdio.h> #include<conio.h> void main() { int a,b,i,n; i = 2; printf("How many even numbers you need to display ?"); scanf("%d",&n); while (i <= (n+n)) {b = i;  printf("%d,",b);  i = i+2;   }  getch(); } //The Program By Tittu Varghese //To display n odd numbers.     #include<stdio.h> #include<conio.h> void main() { int a,b,i,n; i = 1; printf("How many even numbers you need to display ?"); scanf("%d",&n); while (i <= ((n+n)-1)) {b = i;  printf("%d,",b);

Roots of a Quadratic Equation

/* The Program By Tittu Varghese */ // Roots of a Quadratic Equation #include<stdio.h> #include<math.h> #include<conio.h> void main() { float a,b,c,r,r1,r2,d; printf("Enter the Value of a , b and c"); scanf("%f %f %f ",&a,&b,&c); d = (b * b) - (4 * a * c); if (d < 0)   { r1 = (-b)/(2*a); r2 = (sqrt(-1*d))/ (2*a); printf("The Roots are Imaginary\n"); printf("R1 is %f+i%f\n",r1,r2); printf("R2 is %f-i%f",r1,r2); else if (d == 0)    { r = (-b + sqrt (d)) / (2 * a);       printf("The roots are equal and R is %f",r);                else             { r1 = (-b + sqrt (d)) / (2 * a);               r2 = (-b - sqrt (d)) / (2 * a);                printf("The roots are real and r1 is %f and r2 is %f",r1,r2);              } getch(); } //**sqrt" is used to find square root of a number.sqrt function is in math.h header.** //here getch() is used to

Hello World (Bsic C Program)

/* To Print a Text using C */   #include<stdio.h> void main () { printf("Hello World\n"); printf("I am Crazy"); }      ***Here \n used for display the next printf statement in the next line.           /*To Print Sum Of Two Numbers*/ #include<stdio.h> void main () { int a,b,s; printf("Enter Two Numbers"); scanf("%d %d",a,b); s = a + b; printf(" The sum of %d and %d is %d",a,b,s); }

Lets Start C programming

                  Lets start our first program. Before it you need a compiler to compile our program. Commonly used C compiler is Turbo C (* It's not working in windows vista or windows 7. But can work using some techniques). Click here to download C compiler will not working  in windows 7 or in vista. First of all we need to know some keywords to communicate with computer. ****The downloaded file must save in c drive of your computer.**** Then open TC/BIN/TC.EXE. Some basic C commands are :-  Printf  :- To print something                eg. printf("Something to display") Scanf  :- To accept some inputs.                eg. scanf("%d",a);                * Here %d is used for show a is an intiger. Some Data type  Data Type Range Data Type Range char or signed char -128 to 127 unsigned char 0 to 255 int or signed int -32768 to 32767 unsigned int 0 to 65535 long int or signed int -2147483648 to 2147483647

Algorithm Average of a set of numbers numbers #c

/* To display Average of a set of given numbers. */ 1. Read the value of n. 2. i = 1 , SUM = 0. 3. if  i > n go to 9 4. Read the value of x. 5. SUM = SUM + x 6. i = i + 1 7. go to 3 8. AVERAGE = SUM / n 9. Display AVERAGE. 10. Stop * x is user defined numbers. /* To display Largest of a set of given positive numbers. */  1. Read the value of n. 2. i = 0 , Y= 0 3. if i <= n go to 7 4. Read the value of X 5. If X > Y then Y = X 6. go to 3 7. Display Y 8. Stop /* To display Latgest of a set of given numbers. */   1. Read the value of n. 2. i = 0 3. if i <= n go to 7 4. Read the first number in X 5. S = X 6. i = i + 1 7. If  i > n go to 8. Read the Second number in X 9. If X > S then S = X 10. go to 4 11. Display S 12. Stop /* To display Smallest of a set of given numbers. */   1. Read the value of n. 2. i = 0 3. if i <= n go to 7 4. Read the first number in X 5. S = X 6. i = i + 1 7. If  i > n go to 8. Read the Se

Algorithm to display the sum of n natural numbers #c

/* Sum of n natural numbers */ 1. Read the value of n. 2. i = 1 , SUM = 0 3. if ( i > n ) go to 7 4. S = S + i 5. i = i + 1 6. go to 3 7. Display the value of S 8. Stop /* Factorial of n numbers */ 1. Read the value of n. 2. i = 1 , F =1 3. if ( i > n ) go to 7 4. F = F * i 5. i = i + 1 6. go to 3 7. Display the value of S 8. Stop /* To Find the value of  x n */ 1. Read the value of n. 2. i = 1 , m = 1 3. If i > n then go to 7 4. m = m * x 5. i = i + 1 6. go to 3 7. Display m 8. Stop

Algorithm to display "n" natural numbers #c

/* Algorithm For print "n" numbers */ 1. Read the value of n. 2. i = 1 3. if ( i > n ) go to step 7 4. Display value of i 5. i = i + 1 6. go to step 3 7. Stop /* Algorithm For print "n even" numbers */ 1. Read the value of n. 2. i = 2 3. if ( i > n ) go to step 7 4. Display value of i 5. i = i +2 6. go to step 3 7. Stop /* Algorithm For print "n odd" numbers */ 1. Read the value of n. 2. i = 1 3. if ( i > n ) go to step 7 4. Display value of  i 5. i = (2n - 1) 6. go to step 3 7. Stop

Algorithm for display roots of a quadratic equation #c

1. Read the value of a , b , c 2. d = b*b - 4*a*c 3. if d < 0 then display The Roots are Imaginary.            else if d = 0                      then dispaly Roots are Equal.                                        r = -b / 2*a                                        display r                  else r1 = -b + √d / 2*a                         r2 = -b - √d / 2*a                     display Roots are real and r1 , r2 4. Stop

Algorithm For Compare two numbers #c

/* To display the largest one from given two numbers. */ 1. Read the value of a and b. 2. if a>b then display a        else display b /* To display the smallest one from given two numbers. */  1. Read the value of a and b. 2. if a<b then display a        else display b

Algorithm for Sum of two numbers

It's an algorithm for to find sum of two user defined numbers. *Not a program. To add two numbers. Read the Value of A and B. SUM = A+B. Display SUM. Stop. Similarly to Multiply two numbers. Read the Value of A and B. PRODUCT = A*B. Display PRODUCT. Stop. For Divide two numbers. Read the Value of A and B. DIV = A/B. Display DIV. Stop. For Subtract two Numbers. Read the Value of A and B. SUB = A-B. Display SUB. Stop. * You can change SUM, PRODUCT, DIV amd SUB with your variables and note that you must to change the 3. Dispaly SUM / PRODUCT /DIV/ SUB.

What is C {Program Language} ?

C (pronounced like the letter C) is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system. Although C was designed for implementing system software, it is also widely used for developing portable application software. C is one of the most widely used programming languages of all time and there are very few computer architectures for which a C compiler does not exist. C has greatly influenced many other popular programming languages, most notably C++, which began as an extension to C. Like most imperative languages in the ALGOL tradition, C has facilities for structured programming and allows lexical variable scope and recursion, while a static type system prevents many unintended operations. In C, all executable code is contained within subroutines, which are called "functions" (although not in the strict sense of functional programming). Function paramete