Archive for September, 2010

C program to Print Inverse of a given Number

September 30, 2010

Inversing of a given Number. suppose we gave input 123456 then the output of the program will be 654321.

//C program to print inverse of a given number
#include<stdio.h>
#include<conio.h>
void main()
{
long int n,rn=0,d=0;
clrscr();
printf(“Enter the number\n\n”);
scanf(“%ld”,&n);
while(n>0)
{
d=n%10;
rn=rn*10+d;
n=n/10;
}
printf(“%ld”,rn);
getch();
}
(more…)

c program for to find Prime Number

September 30, 2010
A prime number (or a prime) is a natural number that has exactly two distinct natural number divisors: 1 and itself.
the prime numbers under 100:
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97.
code:
//To Print Prime no. till limit
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,c=1;
clrscr();
printf(“Enter the limit\n\n”);
scanf(“%d”,&n);
while (c<=n)
{
i=2;
while(i<=c)
{
if(c%i==0)
break;
i++;
}
if(i==c)
printf(“\n%d”,c);
c++;
}
getch();
}

c program for Fibonacci Series

September 27, 2010
Fibonacci number
In mathematics, the Fibonacci numbers are the numbers in the following integer sequence:
1, 1, 2, 3, 5, 8, 13, 21, 34,55,89,144,……
(more…)

C program to print number’s till limit, Except those that are divisible by 8

September 22, 2010

//To print no. till limit, except those that are divisible by 8
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i;
clrscr();
printf(“Ener a limit”);
scanf(“%d”,&n);
for(i=1;i<=n;i++)
if(i%8!=0)
printf(“\n%d”,i);
else
continue;
getch();
}

Hope you liked my posts, give comments if you have any doubts…:)

(more…)

c program for Enter values to continuous loop. If value =0 then break & print sum & average.

September 22, 2010
//Enter values to continuous loop. If value =0 then break & print sum & average.
#include<stdio.h>
#include<conio.h>
void main()
{
int i=0,n;
float a,s=0;
clrscr();
while(1)
{
printf(“enter the value”);
scanf(“%d”,&n);
i++;
if(n==0)
break;
else
s=s+n;
a=s/i;
}
printf(“\nsum=%f”,s);
printf(“\navg=%f”,a);
getch();
}
Hope you liked my posts, give comments if you have any doubts…:)

To print pyramid output

September 19, 2010

To Print Output like
*
**
***
****
*****
****** (more…)

c program to prepare Table of any Number using while & for loop

September 10, 2010

using while loop

//Program to prepare Table of any no. using while loop
#include
#include
void main()
{
int n,t,count=1;
clrscr();
printf(“Enter any number\n\n”);
scanf(“%d”,&n);

while(count<=10)
{
t=n*count;
printf(“\n%d*%d=%d”,n,count,t);
count++;
}
getch();
}

(more…)

Factorial Program

September 5, 2010

In mathematics, the factorial of a positive integer n, denoted by n!, is the product of all positive integers less than or equal to n.

For example, 5 ! = 5 * 4* 3 * 2* 1 = 120

Using While Loop

type 1:

//Program for Factorial
#include<stdio.h>
#include<conio.h>
void main()
{
int n,fact=1;
clrscr();
printf(“Enter any Number:\n\n”);
scanf(“%d”,&n);
while(n>1)
{
fact=fact*n;
n–;
}
printf(“\nFactorial is=%d”,fact);
getch();
}

(more…)

c program for Calculate Simple Interest for 3 sets of p, n & r using while & for loop

September 4, 2010

using while loop

/*Calculate Simple Interest for 3 sets of p, n & r
p, n & r represent principle, no. of years & rate of interest*/
#include<stdio.h>
#include<conio.h>
void main()
{
int p,n,count=1;
float r,si;
clrscr();
while(count<=3)
{
printf(“Enter value for p,n & r\n\n”);
scanf(“%d%d%f”,&p,&n,&r);
si=(p*n*r)/100;
printf(“\nSimple Interest =%f”,si);
count++;
}
getch();
}

(more…)

Program to find out Maximum of 3 number’s using Conditional Operator

September 4, 2010

//Program to find out Maximum of 3 number’s using Conditional Operator
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf(“Enter 3 nos:\n \n”);
scanf(“%d%d%d”,&a,&b,&c);
(a>b)?((a>c)?printf(“a is max”):printf(“c is max”)):((b>c)?printf(“b is max”):printf(“c is max”));
getch();
}

Hope you liked my posts, give comments if you have any doubts…:)

(more…)