Posts

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 ...

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 i...

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. ...

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