C Programming

C Program – Adding two no without using + operator

May 11, 2011

//Downloaded From theonlinetutorials.com //Source code #include<stdio.h> #include<conio.h> int main() { clrscr(); int a=3000,b=20,sum; char *p; p=(char *)a; sum= (int)&p[b]; //adding a & b printf(“Answer is :”); printf(“%d”,sum); getch(); return 0; } Not Satisfied ? Just search & get the result

Read the full article →

C program – Calculate the factorial of a number using recursion

May 11, 2011

//Downloaded From theonlinetutorials.com //Source code #include”stdio.h” #include”conio.h” int fac(int n){ if(n<0) return 0; if(n==1||n==0) return 1; else return n*fac(n-1); } int main() { int n=5; int i; printf(“Enter the no to find the factorail \n”); scanf(“%d”,&n); printf(“Factorail of the no is %d “,fac(n)); getch(); return 0; }

Read the full article →

C Program – Print fun with pyramid

May 9, 2011

//Downloaded From theonlinetutorials.com #include”stdio.h” #include<conio.h> void main() { int a; int i,j,k; clrscr(); printf(” Enter an integer value: “); scanf(“%d”,&a); for(i=0;i<=2*a+1;i++) printf(“*”); printf(“\n”); for(i=1;i<=a-1;i++) { for(j=a;j>=i;j–) printf(“*”); printf(” “); for(j=a;j>=i;j–) printf(“*”); printf(“\n”); } printf(“*Theonlinetutorials.com \n”); for(i=2;i<=a;i++) { for(j=1;j<=i;j++) printf(“*”); printf(” “); for(j=1;j<=i;j++) printf(“*”); printf(“\n”); } for(i=0;i<=2*a+1;i++) printf(“*”); getch(); }

Read the full article →

C Program – Find whether a given number is a multiple of 3 or not

May 9, 2011

//Downloaded From theonlinetutorials.com #include”stdio.h” #include”conio.h” #include”math.h” void main() { int n; clrscr(); printf(” Enter a number: “); scanf(“%d”,&n); n=abs(n); while(n>3) n-=3; if(n==3) printf(“no is multiple of 3″); else printf(“no is not multiple of 3″); getch(); }

Read the full article →

C Program – Timer program with loop breaking

May 9, 2011

//Downloaded From theonlinetutorials.com #include “stdio.h” #include “conio.h” #include “dos.h” int main() { int i,flag=0; char s[100]; clrscr(); for(i=30;i>=0;i–) { if(kbhit()) { scanf(“%s”,s);//User want to take input flag=1;//Call the operation you require break;//Terminate the loop } delay(1000); printf(“\n00:%2d”,i); } if(flag==1) printf(“User entered %s”,s);//If user entered a value display it getch(); return 0; }

Read the full article →

C Program – Timer program

May 9, 2011

//Downloaded From theonlinetutorials.com #include “stdio.h” #include “conio.h” #include “dos.h” int main() { int i; char s[100]; clrscr(); for(i=30;i>=0;i–) { delay(1000); printf(“\n00:%2d”,i); } printf(“Timer finished”); getch(); return 0; }

Read the full article →

C Program – Call a function before main

May 9, 2011

//Downloaded From theonlinetutorials.com #include<stdio.h> #include<conio.h> void v(void); #pragma startup v int main() { printf(“    You are in Main”); getch(); return 0; } void v(void) { clrscr(); printf(“You are in v”); }

Read the full article →

C Program – Display all type of pyramids

May 9, 2011

//Downloaded From theonlinetutorials.com #include<stdio.h> #include<conio.h> void main() { int n=6,k,i,j; clrscr(); printf(“How many star you want “); scanf(“%d”,&n); for(i=1;i<=n;i++) { printf(“\n”); for(j=1;j<=i;j++) printf(” *”); } getch(); for(i=1;i<=n;i++) { printf(“\n”); for(k=n;k>=i;k–) printf(” “); for(j=1;j<=i;j++) printf(” *”); } getch(); for(i=1;i<=n;i++) { printf(“\n”); for(k=n;k>=i;k–) printf(” “); for(j=1;j<=i;j++) printf(“*”); } printf(“\n”); getch(); for(i=1;i<=n;i++) { printf(“\n”); for(k=1;k<=i;k++) printf(” “); for(j=n;j>=i;j–) [...]

Read the full article →

C Program – Print the number which are not occurred in Fibonacci Series

May 9, 2011

//Downloaded From theonlinetutorials.com #include<stdio.h> int fib(int n) { if(n==1) return 0; if(n==2) return 1; else return fib(n-2)+fib(n-1); } int main() { int n,on=0,nn,cou,i; printf(“Enter the no to which you want to print all no which did not occur in fib series”); scanf(“%d”,&n); cou=1; printf(“\nNumber which are not occured in the series are\n”); while((nn=fib(cou))<=n) { cou++; [...]

Read the full article →

C Program – Random Float number Generator

May 9, 2011

//Downloaded From theonlinetutorials.com #include”stdio.h” #include”stdlib.h” #include”time.h” #include”limits.h” float Frand(int n) { float m; m=(float)(rand())/RAND_MAX; m+=rand()%n; return m; } float Frand1(int n) { float m,temp; temp=(float)rand()/RAND_MAX; m=n*temp; return m; } int main() { int  n,i; printf(“Enter a int no to which you want to generate an random float no”); scanf(“%d”,&n); printf(“This program will be tested 10 [...]

Read the full article →

C Program to find the biggest and smallest of three numbers

April 18, 2011

The entered three numbers N1, N2, N3 are compared in such an order, where the first comparison checks if  N1  largest. If so, prints it out and exists; if not so, it omits N1 from further comparison and checks with N2 and N3 only. The same logic but with complement operator, the program finds the [...]

Read the full article →

C Program to calculate area and circumference of the circle

April 18, 2011

#include<stdio.h> void main() { float area, radius, circum; clrscr(); printf(“nnt ENTER THE RADIUS OF THE CIRCLE…:”); scanf(“%f”, &radius); area = 3.142 * radius * radius; circum = 2 * 3.142 * radius; printf(“nnt THE AREA OF THE CIRCLE IS…: %f”, area); printf(“nnt THE CIRCUMFERENCE OF THE CIRCLE IS…: %fn”, circum); getch(); }

Read the full article →

C Program to find the roots of a quadratic equation

April 18, 2011

#include<stdio.h> #include<math.h> void main() { int A, B, C; float disc, deno, x1, x2; clrscr(); printf(“nnt ENTER THE VALUES OF A,B,C…”); scanf(“%d,%d,%d”, &A, &B, &C); disc = (B * B) – (4 * A * C); deno = 2 * A; if(disc > 0) { printf(“nt THE ROOTS ARE REAL ROOTS”); x1 = (-B/deno) + [...]

Read the full article →

C Program to find the gross and net salary

April 18, 2011

Here we divided the the employee into three categories according to his basic pay. The first category is getting the basic pay less than Rs.5000/-. Second category is having the basic between Rs.5000/- to Rs.10000/-, and the third is getting the basic more than Rs.10000/-. Basic idea here is to calculate the DA and TAX [...]

Read the full article →

C Program To find the biggest and smallest number and positions in the given array

April 18, 2011

#include<stdio.h> void main() { int A[25], max, min, maxpos, minpos, n, i; clrscr(); printf(“nnt ENTER THE SIZE OF THE ARRAY…: “); scanf(“%d”, &n); printf(“nnt ENTER THE ELEMENTS OF THE ARRAY…: “); for(i=1; i<=n; i++) { gotoxy(25, 15+i); scanf(“%d”, &A[i]); } max = A[1]; maxpos = 1; for(i=1; i<=n; i++) { if(max<A[i]) { max = A[i]; [...]

Read the full article →

C Program for prime numbers

April 18, 2011

Program to find whether a number is a prime or not #include<stdio.h> void main() { int i, prime = 1, n; clrscr(); printf(“nnt ENTER A NUMBER…: “); scanf(“%d”, &n); for(i=2; i<n; i++) { if(n%i == 0) { prime = 0; break; } } if(prime) printf(“nnt THE NUMBER %d IS A PRIME NUMBER”, n); else printf(“nnt [...]

Related Posts Plugin for WordPress, Blogger...
Read the full article →