#include
main()
{
int a[20],b[20],n,i,j,temp,sb,ss,sbp,ssp;
clrscr();
printf("ENTER HOW MANY ELEMENTS\n");
scanf("%d",&n);
printf("ENTER %d ELEMENTS\n",n);
for (i=0;i<n;i++)
scanf("%d",&a[i]);
for (i=0;i<
b[i]=a[i];
for (i=0;i
{
for (j=i+1;j
if (a[i]
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
sb=a[1];
ss=a[n2];
for (i=0;i
{
for (j=i+1;j
{
if (b[i]==sb)
sbp=i;
if (b[i]==ss)
ssp=i;
}
}
b[sbp]=ss;
b[ssp]=sb;
printf("AFTER INTERCHANGING THE SECOND BIGGEST ELEMENT AND\n");
printf("THE SECOND SMALLEST ELEMENT THE ARRAY IS\n");
for (i=0;i
printf("%d\n",b[i]);
getch();
}
C Program on array manipulations
array manipulations in C , C Assignment array manipulations
C Program to find frequency table, frequency table in C Language, C assignment to find frequency table
C Program to find frequency table, frequency table in C Language, C assignment to find frequency table
#include
main()
{
int a[20],c=0,d=0,i,j=0,n;
clrscr();
printf("ENTER ANY NUMBER\n");
scanf("%d",&n);
printf("ENTER %d NUMBERS\n",n);
for (i=0;i<n;i++)
scanf("%d",&a[i]);
do
{
j++;
for (i=0;i
if (a[i]==j)
{
c++;
d++;
}
if (c!=0)
{
printf("%d OCCURED %d TIMES\n",j,c);
c=0;
}
}
while(n!=d);
getch();
}
Related Links :
C Program to print the triangle
C Program to print the triangle, creating a triangle in C
#include
main()
{
int n,i,j,k=5;
clrscr();
printf("ENTER THE NUMVER OF LINES ");
scanf("%d",&n);
for(i=n;i>0;i)
{
for(j=0;j
printf(" ");
for(j=1;j<=i;j++)
printf("%2d",i);
k++;
printf("\n");
}
getch();
}
Related Links :
Program adding two polynomials in C, add two polynomials using array
adding two polynomials in C, C Program to add two polynomials using array, adding two polynomials in C, Addition of 2 polynomials in C
#include
#include
#define MAX 10
struct term
{
int coeff;
int exp;
};
struct poly
{
struct term t[10];
int totalterms;
};
void initpoly(struct poly*);
void polycreate(struct poly*,int c,int e);
struct poly addpoly(struct poly,struct poly);
void display(struct poly);
void main()
{
struct poly p1,p2,p3;
clrscr();
initpoly(&p1);
initpoly(&p2);
initpoly(&p3);
polycreate(&p1,1,7);
polycreate(&p1,2,6);
polycreate(&p1,3,5);
polycreate(&p1,4,4);
polycreate(&p1,5,2);
polycreate(&p2,1,4);
polycreate(&p2,1,3);
polycreate(&p2,1,2);
polycreate(&p2,1,1);
polycreate(&p2,2,0);
p3=addpoly(p1,p2);
printf("\n First polynomial :\n ");
display(p1);
printf("\n Second polynomial :\n ");
display(p2);
printf("\n\n Resultant Polynomial :\n");
display(p3);
getch();
}
/* Initializes elements of struct poly */
void initpoly(struct poly *p)
{
int i;
p>totalterms=0;
for(i=0;i{
p>t[i].coeff=0;
p>t[i].exp=0;
}
}
/* Add the term of polynomial to the array t */
void polycreate(struct poly *p,int c,int e)
{
p>t[p>totalterms].coeff=c;
p>t[p>totalterms].exp=e;
(p>totalterms)++;
}
/* DISPLAY the polynomial equation */
void display(struct poly p)
{
int flag=0,i;
for(i=0;i{
if(p.t[i].exp != 0)
printf("%d x^%d + ",p.t[i].coeff,p.t[i].exp);
else
{
printf("%d",p.t[i].coeff);
flag=1;
}
}
if(!flag)
printf("\b\b");
}
/* ADD two polynomials p1 and p2 */
struct poly addpoly(struct poly p1,struct poly p2)
{
int i,j,c;
struct poly p3;
initpoly(&p3);
if(p1.totalterms>p2.totalterms)
c=p1.totalterms;
else
c=p2.totalterms;
for(i=0,j=0;i<=c;p3.totalterms++)
{
if(p1.t[i].coeff==0 && p2.t[j].coeff==0)
break;
if(p1.t[i].exp>=p2.t[j].exp)
{
if(p1.t[i].exp==p2.t[j].exp)
{
p3.t[p3.totalterms].coeff=p1.t[i].coeff + p2.t[j].coeff;
p3.t[p3.totalterms].exp=p1.t[i].exp;
i++;
j++;
}
else
{
p3.t[p3.totalterms].coeff=p1.t[i].coeff;
p3.t[p3.totalterms].exp=p1.t[i].exp;
i++;
}
}
else
{
p3.t[p3.totalterms].coeff=p2.t[j].coeff;
p3.t[p3.totalterms].exp=p2.t[j].exp;
j++;
}
}
return p3;
}
Related Links :
Program to show the use of static variables in C Language
Program to show the use of static variables in C Language
#include
#incl.ude
void stat();
void main()
{
int c;
clrscr();
for(c=1;c<=3;c++)
stat();
getch();
}
void stat()
{
static int sv=0;
sv=sv+1;
printf("%d\n",sv);
}
Related Links :
Mouse Programming in C,mouseposi, mousehide, mouseposi, setposi Function in C
Mouse Programming in C,mouseposi, mousehide, mouseposi, setposi Function in C
#include
#include
#include
#include
union REGS in,out;
int callmouse()
{
in.x.ax=1;
int86(51,&in,&out);
return 1;
}
void restrictmouseptr(int x1,int y1,int x2,int y2)
{
in.x.ax=7;
in.x.cx=x1;
in.x.dx=x2;
int86(51,&in,&out);
in.x.ax=8;
in.x.cx=y1;
in.x.dx=y2;
int86(51,&in,&out);
}
int main()
{
int x,y,cl,a,b;
clrscr();
int g=DETECT,m;
initgraph(&g,&m,"c:\tc\bgi");
rectangle(100,100,550,400);
callmouse();
restrictmouseptr(100,100,550,400);
getch();
}
Related Links :
callmouse() Function in C
callmouse() Function in C
callmouse() : In this function AX is set to "1". When this function is called in main() it displays the mouse pointer. The position of the pointer can be changed by using the mouse.
callmouse() : In this function AX is set to "1". When this function is called in main() it displays the mouse pointer. The position of the pointer can be changed by using the mouse.
Related Links :
Labels:
callmouse() Function in C
C Program to Find prime numbers in an array using function
C Program to Find prime numbers in an array using function, find Prime Numbers from array, given array find prime numbers, Prime Number calculation from array
#include
int prime(int n)
{
int i,flag=1;
for(i=2;i<=n/2;i++)
{
if(n%i==0)
{
flag=0;
break;
}
}
return flag;
}
main()
{
int arr[50],l,i,count=0;
printf(“Enter number of elementsn”);
scanf(“%d”,&l);
printf(“Enter %d numbersn”,l);
for(i=0;i<l;i++)
{
scanf(“%d”,&arr[i]);
}
for(i=0;i<l;i++)
{
if(prime(arr[i])==1)
count++;
}
if(count==0)
{
printf(“There are no prime numbers in the listn”);
}
else
{
printf(“There are %d prime number(s) in the listn”,count);
for(i=0;i<l;i++)
{
if(prime(arr[i])==1)
printf(“%dn”,arr[i]);
}
}
}
Related Links :
C PROGRAM TO READ A FLOATING POINT NUMBER AND DISPLAYS THE RIGHT MOST DIGIT OF THE INTEGRAL PART OF THE NUMBER
C PROGRAM TO READ A FLOATING POINT NUMBER AND DISPLAYS THE RIGHT MOST DIGIT OF THE INTEGRAL PART OF THE NUMBER
#include
main()
{
float num;
int ip,rm;
printf(“Enter a floating point number”);
scanf(“%f”,&num);
ip=(int)num;
rm=ip%10;
printf(“Right most digit of integral part=%dn”,rm);
}
Related Links :
C program using do…while loop to print the first m Fibonacci numbers, Fibonacci numbers Series
C program using do…while loop to print the first m Fibonacci numbers, Fibonacci numbers Series
#include
main()
{
int a=1,b=1,c=0,m,i=0;
printf(“Enter limitn”);
scanf(“%d”,&m);
do
{
printf(“%dt”,a);
i++;
c=a+b;
a=b;
b=c;
}
while(i
Related Links :
C program to convert a decimal number to binary number, decimal number to binary number Conversion in C, C assignment to convert Decimal to binary
C program to convert a decimal number to binary number, decimal number to binary number Conversion in C, C assignment to convert Decimal to binary
#include
main()
{
int tenpow=1,num,i,bin=0;
printf(“Enter a decimal number”);
scanf(“%d”,&num);
do
{
bin+=(num%2)*tenpow;
tenpow*=10;
num/=2;
}
while(num>0);
printf(“Binary equivalent=%dn”,bin);
}
Related Links :
c assignment to find the sum of primary diagonal of a matrix
c assignment to find the sum of primary diagonal of a matrix
#include
void main()
{
int A[5][5],i,j,m,n,sum = 0;
clrscr();
printf("\n\n\t ENTER A ORDER OF THE MATRIX M,N...: ");
scanf("%d,%d",&m,&n);
printf("\n\n\t ENTER THE ELEMENTS OF THE MATRIX..:\n\n");
if(m == n)
{
for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
{
gotoxy(20+j*4,12+i*2);
scanf("%d",&A[i][j]);
}
printf("\n");
}
for(i=1;i<=m;i++)
sum = sum + A[i][i];
printf("\n\t THE SUM OF PRIMARY DIAGONAL OF A MATRIX IS...: %d", sum);
}
else
{
printf("\n\t THE ORDER OF THE MATRIX IS NOT CORRECT");
printf("\n\n\t HELP : 'M' SHOULD BE EQUAL TO 'N'");
}
getch();
}
Related Links :
C Program to find the sum of the cos series
C Program to find the sum of the cos series , COS series in C, C Language Cos Series calculation.
#include
#include
void main()
{
float pow = 2.0, nr, dr = 1.0, x1, sum;
int i = 1,n,s = 1,x;
clrscr();
printf("\n\n\t ENTER THE ANGLE...: ");
scanf("%d", &x);
x1 = 3.142 * (x / 180.0);
sum = 1.0;
nr = x1*x1;
printf("\n\t ENTER THE NUMBER OF TERMS...: ");
scanf("%d",&n);
while(i<=n)
{
dr = dr * pow * (pow  1.0);
sum = sum + (nr / (dr * s));
s = s * (1);
pow = pow + 2.0;
nr = nr * x1 * x1;
i++;
}
printf("\n\t THE SUM OF THE COS SERIES IS..: %0.3f", sum);
getch();
}
Related Links :
C Program to find the sum of the sine series
C Program to find the sum of the sine series , Sine Series In C, Sum of Sine Series In C Language, C Assignment to find Sin Series in C .
#include
#include
#include
void main()
{
int i = 2, n, s = 1, x, pwr = 1, dr;
float nr = 1, x1, sum;
clrscr();
printf("\n\n\t ENTER THE ANGLE...: ");
scanf("%d", &x);
x1 = 3.142 * (x / 180.0);
sum = x1;
printf("\n\t ENTER THE NUMBER OF TERMS...: ");
scanf("%d", &n);
while(i <= n)
{
pwr = pwr + 2;
dr = dr * pwr * (pwr  1);
sum = sum + (nr / dr) * s;
s = s * (1);
nr = nr * x1 * x1;
i+= 2;
}
printf("\n\t THE SUM OF THE SINE SERIES IS..: %0.3f",sum);
getch();
}
Related Links :
C Assignment to Find Given Year leap year or Not
C Assignment to Find Given Year leap year or Not
#include
#include
void main()
{
int yr;
clrscr();
printf("Please enter the year");
scanf("%d",&yr);
if((yr%400==0)&&(yr/4==0))
printf("leap year");
else
printf("not leap year");
getch();
}
Related Links :
Program to Check whether First number is divisible by second number or not
#include
#include
void main()
{
int n1,n2;
clrscr();
printf("enter the values of Number1 and Number 2");
scanf("%d %d",&n1,&n2);
if(n1%n2==0)
printf("First no is divisible by second");
else
printf("Sorry !!! not divisible");
getch();
}
Program to Check whether First number is divisible by second number or not
Related Links :
C Program to print ASCII value of given character
C Program to print ASCII value of given character
#include
#include
void main()
{
char ch;
clrscr();
printf("please enter any character");
scanf("%c",&ch);
printf("The ASCII Value =%d",ch);
getch();
}
Related Links :
C Program to Perform Arithmetic operations
C Program to Perform Arithmetic operations
#include
#include
void main()
{
int a,b,add,sub,mul,div;
clrscr();
printf("Enter any 2 numbers");
scanf("%d %d", &a,&b);
add=a+b;
printf("The addition of numbers=%d",add);
sub=ab;
printf("The substraction of number=%d",sub);
mul=a*b;
printf("The multiplication of number=%d",mul);
div=a/b;
printf("The division of numbers=%d",div);
getch();
}
Related Links :
C Program to find absolute value
C Program to find absolute value
#include
#include
void main()
{
int a,b;
clrscr();
printf("enter the value of a");
scanf("%d",&a);
if(a<0)
{
b=a*1;
printf("\nabsolute value of %d is %d",a,b);
}
else
{
printf("\nabsolute value=%d",a);
}
getch();
}
Related Links :
C Program to calculate Discount in Bill
#include
#include
main()
{
float ttamt,qnt,rate,dis;
clrscr();
printf ("enter the value of rate and qty");
scanf ("%f%f",&rate,&qnt);
ttamt=qnt*rate;
if(ttamt>2000)
{
ttamt=ttamt(ttamt*10)/100;
printf(" \n ttamt=%f",ttamt);
}
else
{
printf(" \n ttamt=%f",ttamt);
}
getch();
}
Related Links :
Convert string to integer without using library functions in c
Convert string to integer without using library functions in c
#include
int stringToInt(char[] );
int main(){
char str[10];
int intValue;
printf("Enter any integer as a string: ");
scanf("%s",str);
intValue = stringToInt(str);
printf("Equivalent integer value: %d",intValue);
return 0;
}
int stringToInt(char str[]){
int i=0,sum=0;
while(str[i]!='\0'){
if(str[i]< 48  str[i] > 57){
printf("Unable to convert it into integer.\n");
return 0;
}
else{
sum = sum*10 + (str[i]  48);
i++;
}
}
return sum;
}
Related Links :
C Program to print STAR PATTERNS and pyramids
C Program to print STAR PATTERNS and PYRAMIDS
main()
{
char prnt = '*';
int i, j, k, s, c = 1, numb = 9;
for (i = 1; c <= 4; i++)
{
if ((i % 2) != 0)
{
for (j = 1; j <= i; j++)
{
printf("%2c", prnt);
}for (s = numb; s >= 1; s)
{
if (c == 4 && s == 1)
{
break;
}
printf(" ");
}
for (k = 1; k <= i; k++)
{
if (c == 4 && k == 5)
{
break;
}
printf("%2c", prnt);
}
printf("\n");
numb = numb  4;
++c;
}
}
}
Related Links :
C Program to evaluate the power series
C Program to evaluate the power series , power of series in C, C Assignment to calculate power of series
#include
#include
#define EXA 0.0001
void main()
{
int n,count;
float x,term,sum;
printf("Please Enter value of x : ");
scanf("%f",&x);
n=term=sum=count=1;
while(n<=100)
{
term=term*(x/n);
sum=sum+term;
count=count+1;
if(term<EXA)
n=999;
else
n=n+1;
}
printf(" TERMS = %d SUM = %f\n",count,sum);
getch();
}
Related Links :
C Program to print asterisk, star patterns
Subscribe to:
Posts (Atom)
If you face any Problem in viewing code such as Incomplete "For Loops" or "Incorrect greater than or smaller" than equal to signs then please collect from My Web Site CLICK HERE
More Useful Topics... 

History Of C..
In the beginning was Charles Babbage and his Analytical Engine, a machine
he built in 1822 that could be programmed to carry out different computations.
Move forward more than 100 years, where the U.S. government in
1942 used concepts from Babbage’s engine to create the ENIAC, the first
modern computer.
Meanwhile, over at the AT&T Bell Labs, in 1972 Dennis Ritchie was working
with two languages: B (for Bell) and BCPL (Basic Combined Programming
Language). Inspired by Pascal, Mr. Ritchie developed the C programming
language.
he built in 1822 that could be programmed to carry out different computations.
Move forward more than 100 years, where the U.S. government in
1942 used concepts from Babbage’s engine to create the ENIAC, the first
modern computer.
Meanwhile, over at the AT&T Bell Labs, in 1972 Dennis Ritchie was working
with two languages: B (for Bell) and BCPL (Basic Combined Programming
Language). Inspired by Pascal, Mr. Ritchie developed the C programming
language.
My 1st Program...
#include
#include
void main ()
{
clrscr ();
printf ("\n\n\n\n");
printf ("\t\t\t\"Life is Good...\"\n");
printf ("\t\t\t********************************");
getch ();
}