Showing posts with label c. Show all posts
Showing posts with label c. Show all posts

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 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 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 find twin prime numbers, twin Prime Numbers by using C language

C Program to find twin prime numbers, twin Prime Numbers by using C language



void main()
{
int n,i,k,r,ary[50],p;
clrscr();
printf(" Enter Maximum Value For Numbers: ");
scanf("%d",&r);
i=1;
p=0;
while(i<=r)
{
k=0;n=1;
while(n<=i)
{
if(i%n==0)
k++;
n++;
}
if(k==2)
{
ary[p]=i;
p++;
}
i++;
}

for(n=0;n<p;n++)
{
if(ary[n+1]-ary[n]==2)
printf("\n %d and %d are TWIN PRIME Numbers ",ary[n],ary[n+1]);
}
getch();
}



Related Links :

Most c compilers Most widely used

Most c compilers Most widely used

There are various c compilers are variables. Some of these are:



S.N.
Name
Microprocessor
OS
1
Turbo c 3.0
8086
MS DOS
2
ANSIC C
80386
LINUX
3
Borland C 4.0
80386
WINDOW
4
Microsoft C
8086
MS DOS
5
Visual C++
80386
WINDOW






Related Links :

while loop without any Loop body



main()
{
int i=0;

while(i++,i<=8);
printf("%d ",i);
return 0;
}



Related Links :

C Program to print or display lower triangular matrix

C Program to print or display lower triangular matrix


#include
int main(){
int a[3][3],i,j;
float determinant=0;

printf("Enter the 9 elements of the matrix: ");
for(i=0;i<3;i++)
for(j=0;j<3;j++)
scanf("%d",&a[i][j]);

printf("\nThe matrix is\n");
for(i=0;i<3;i++){
printf("\n");
for(j=0;j<3;j++)
printf("%d\t",a[i][j]);
}

printf("\nSetting zero in upper triangular matrix\n");
for(i=0;i<3;i++){
printf("\n");
for(j=0;j<3;j++)
if(i<=j)
printf("%d\t",a[i][j]);
else
printf("%d\t",0);
}


return 0;
}



Related Links :

C program to find inverse of a matrix , inverse of a matrix in C

C program to find inverse of a matrix , inverse of a matrix in C


#include

int main(){

int a[3][3],i,j;
float determinant=0;

printf("Enter the 9 elements of matrix: ");
for(i=0;i<3;i++)
for(j=0;j<3;j++)
scanf("%d",&a[i][j]);

printf("\nThe matrix is\n");
for(i=0;i<3;i++){
printf("\n");
for(j=0;j<3;j++)
printf("%d\t",a[i][j]);
}

for(i=0;i<3;i++)
determinant = determinant + (a[0][i]*(a[1][(i+1)%3]*a[2][(i+2)%3] - a[1][(i+2)%3]*a[2][(i+1)%3]));

printf("\nInverse of matrix is: \n\n");
for(i=0;i<3;i++){
for(j=0;j<3;j++)
printf("%.2f\t",((a[(i+1)%3][(j+1)%3] * a[(i+2)%3][(j+2)%3]) - (a[(i+1)%3][(j+2)%3]*a[(i+2)%3][(j+1)%3]))/ determinant);
printf("\n");
}

return 0;
}



Related Links :

C program to print Armstrong numbers from 1 to 500

C program to print Armstrong numbers from 1 to 500



#include
int main(){
int num,r,sum,temp;

for(num=1;num<=500;num++){
temp=num;
sum = 0;

while(temp!=0){
r=temp%10;
temp=temp/10;
sum=sum+(r*r*r);
}
if(sum==num)
printf("%d ",num);
}

return 0;
}


Related Links :

C Program to insert and delete a node from the binary search tree

C Program to insert and delete a node from the binary search tree



#include
#include
#include
#define TRUE 1
#define FALSE 0
struct btreenode
{
struct btreenode *leftchild;
int data;
struct btreenode *rightchild;
};
void insert(struct btreenode **,int);
void del(struct btreenode **,int);
void search(struct btreenode **,int,struct btreenode **,struct btreenode **,int *);
void inorder(struct btreenode *);
void main()
{
struct btreenode *bt;
int req;
int i=0,num,a[]={10,7,11,5,8,12,16,15,6};
bt=NULL; /* Empty Tree */
clrscr();
while(i<=8) { insert(&bt,a[i]); i++; } clrscr(); printf(" Binary tree before deletion :\n"); inorder(bt); del(&bt,11); printf("\n Binary tree after deletion :\n"); inorder(bt); del(&bt,10); printf("\n Binary tree after deletion :\n"); inorder(bt); del(&bt,6); printf("\n Binary tree after deletion :\n"); inorder(bt); del(&bt,16); printf("\n Binary tree after deletion :\n"); inorder(bt); getch(); } /* inserts a new node in a binary search tree */ void insert(struct btreenode **sr,int num) { if(*sr==NULL) { (*sr)=malloc(sizeof(struct btreenode)); (*sr)->leftchild=NULL;
(*sr)->data=num;
(*sr)->rightchild=NULL;
}
else /* Search the node to whilch new node will be attatched */
{
/* If new data is less, traverse to left*/
if(num<(*sr)->data)
insert(&((*sr)->leftchild),num);
else
/* Else traverse to right */
insert(&((*sr)->rightchild),num);
}
}
/* Deletes a node from the binary search tree */
void del(struct btreenode **root,int num)
{
int found;
struct btreenode *parent,*x,*xsucc;
/* If tree is empty */
if(*root == NULL)
{
printf("\n Tree is Empty ");
return;
}
parent=x=NULL;
/* Call to search function to find the node to be deleted */
search(root,num,&parent,&x,&found);
/* If the node to be deleted is not found */
if(found == FALSE)
{
printf("\n Data to be deleted , not found ");
return;
}
/* If the node to be deleted has two children */
if(x->leftchild !=NULL && x->rightchild!=NULL)
{
parent=x;
xsucc=x->rightchild;
while(xsucc->leftchild != NULL)
{
parent=xsucc;
xsucc=xsucc->leftchild;
}
x->data=xsucc->data;
x=xsucc;
}
/* If the node to be deleted has no child */
if(x->leftchild==NULL && x->rightchild==NULL)
{
if(parent->rightchild==x)
parent->rightchild=NULL;
else
parent->rightchild=NULL;
free(x);
return;
}
/* If the node to be deleted has only right child */
if(x->leftchild==NULL && x->rightchild !=NULL)
{
if(parent->leftchild==x)
parent->leftchild=x->rightchild;
else
parent->rightchild=x->rightchild;
free(x);
return;
}
/* If the node to be deleted has only left child */
if(x->leftchild != NULL && x->rightchild==NULL)
{
if(parent->leftchild==x)
parent->leftchild=x->leftchild;
else
parent->rightchild=x->rightchild;
free(x);
return;
}
}

/* Returns the address of the node to be deleted ,address of its parent and whether the node is found or not */
void search(struct btreenode **root,int num,struct btreenode **par,struct btreenode **x,int *found)
{
struct btreenode *q;
q=*root;
*found=FALSE;
*par=NULL;
while(q!=NULL)
{
/* If the node to be deleted is found */
if(q->data == num)
{
*found=TRUE;
*x=q;
return;
}
if(q->data==num)
{
*found=TRUE;
*x=q;
return;
}
*par=q;
if(q->data > num)
q=q->leftchild;
else
q=q->rightchild;
}
}
/* Traverse a binary search tree in an LDR(Left-Data-Right) fashion */
void inorder(struct btreenode *sr)
{
if(sr!=NULL)
{
inorder(sr->leftchild);
/* Print the data of the node whose leftchild is NULL or the path has already been traversed */
printf("%d\t",sr->data);
inorder(sr->rightchild);
}
}



Related Links :

C PROGRAMS TO FIND EFFICIENCY AND OUTLET TEMP OF COMPRESSOR


#include
#include
#include
main()
{
float ti,to,pi,po,e,g=1.4;
clrscr();
printf("enter ti,pi,and po Values...");
scanf("%f%f%f",&ti,&pi,&po);
to=ti *pow(po/pi,(g-1)/ g);
e=l-pow(pi/po,(g-1 )/g);
printf("outlet temp=%f efficiency=%f" ,to,e);
getch();
}



Related Links :

C program to convert Days into Year months, weeks and leftover days

C program to convert Days into Year months, weeks and leftover days



#include
#include
main()
{
int days,month,week,year;
clrscr();
year=0;
printf("enter days");
scanf("%d" ,&days);
month=days/30;
days%=30;
week=days/7;
days%=7;
year=month/12;
printf("equivalent months=%d weeks=%d and·
leftoverdays=%d" ,month,week,days);
if (year>0)
{
printf("\n The Years are %d",year);
}
getch();
}



Related Links :

C PROGRAM TO CREATE Triangle USING FOR LOOP TO OBTAIN THE Triangle

C PROGRAM TO CREATE Triangle USING FOR LOOP TO OBTAIN THE Triangle


#include



main()
{
int i,j;
for(i=7;i>0;i–)
{

for(j=i;j>0;j–)



{

printf(“*\t”);

}

printf(“\n\v”);

}

}





Related Links :

C Program to RECURSIVE FUNCTION FIND FACTORIAL OF A NUMBER

C Program RECURSIVE FUNCTION TO FIND FACTORIAL OF A NUMBER


#include

int fact(int n)
{
int factor=1;
if(n==1)
{
return 1;
}
else
{
factor=n*fact(n-1);
return factor;
}
}
main()
{
int n;
printf(“Enter a number\n”);
scanf(“%d”,&n);
printf(“Factorial of %d = %d\n”,n,fact(n));
}



Related Links :

C Program TO REPLACE A PARTICULAR WORD BY ANOTHER WORD IN GIVEN STRING

C Program TO REPLACE A PARTICULAR WORD BY ANOTHER WORD IN GIVEN STRING


#include
#include
main()
{
int lr,m,x,t,l,ll,ls,i,j,k,flag,count=0;
char line[200],str[20],rep[20];
printf(“Enter line of text\n”);
gets(line);
printf(“Enter the word to replace\n”);
scanf(“%s”,str);
printf(“Enter the word to replace with\n”);
scanf(“%s”,rep);
ll=strlen(line);
ls=strlen(str);
lr=strlen(rep);
for(i=0;i<ll;i++)
{
if(line[i]==str[0]&&((line[i-1]==’ ‘||i==0)&&(line[i+ls]==’ ‘||line[i+ls]==’\0′)))
{
for(flag=0,k=i,j=0;j{
if(line[k]==str[j])
{
flag++;
}
}
if(flag==ls)
{
if(lr>ls)
{
for(m=lr-ls;m>0;m–)
{
ll=strlen(line);
for(l=ll;l>i;l–)
{
line[l+1]=line[l];
}
}
}
else if(lr{
for(m=ls-lr;m>0;m–)
{
ll=strlen(line);
for(l=i;l<ll;l++)
{
line[l]=line[l+1];
}
}
}
else
{
}
for(x=0,t=i;x<lr;x++,t++)
{
line[t]=rep[x];
}
}
}
}
printf(“Text\n”);
puts(line);
}





Output :


Enter line of text

Snehal IS A GOOD GIRL

Enter the word to replace

GIRL

Enter the word to replace with

BOY

Text

Snehal IS A GOOD BOY

Related Links :

C Program using RECURSIVE FUNCTION TO FIND FACTORIAL OF A NUMBER


#include

int fact(int n)
{
int factor=1;
if(n==1)
{
return 1;
}
else
{
factor=n*fact(n-1);
return factor;
}
}

main()
{
int n;
printf(“Enter a number\n”);
scanf(“%d”,&n);
printf(“Factorial of %d = %d\n”,n,fact(n));
}




OUTPUT:



Enter a number

7

Factorial of 7 = 5040

Related Links :

C Program to Print Acsii Value of Given Number

C Program to Print Acsii Value of Given Number

#include
#include
void main()
{
char ch;
clrscr();
printf("enter any character");
scanf("%c",&ch);
printf("ch=%d",ch);
getch();
}



Related Links :

C Program to find absolute value of given number

C Program to find absolute value of given number




#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 accept arithmetic operator, accept two numbers and perform given operation

C Program to accept arithmetic operator, accept two numbers and perform given operation



#include
main()
{
char ch;
int num1,num2;
clrscr();

printf("\nEnter number ,another number and operator:");
fflush(stdin);
scanf("%d%d",&num1,&num2);
ch=getchar();
switch(ch)
{
case '+':
printf("\n addition of 2 numbers=%d",num1+num2);
break;
case '-':
printf("\n subtraction of 2 numbers=%d",num1-num2);
break;
case '/':
printf("\n division of 2 numbers=%d",num1/num2);
break;
case '*':
printf("\n multiplication of 2 numbers=%d",num1*num2);
break;
default:
printf("\n wrong choice!");
}
getch();
}




Related Links :

C Program to calculate length of given string in C without using STRLEN function

C Program to calculate length of given string in C without using STRLEN function



main ( )
{
char s1[6] = “abcde ”;
int cnt = 0;
cnt = cnt_str(s1);
printf( “ total characters are %d \n”, cnt);
}

int cnt_str(char s1[]);
{
int cn = 0;
while ( (cn < 6) && s1[cn]! = ‘\0’) cn++; return(cn); }

Related Links :


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.

My 1st Program...


#include
#include
void main ()
{
clrscr ();
printf ("\n\n\n\n");
printf ("\t\t\t*******Pankaj *******\n");
printf ("\t\t\t********************************\n");
printf ("\t\t\t\"Life is Good...\"\n");
printf ("\t\t\t********************************");
getch ();
}

Next Step...


#include
#include

void main ()
{
clrscr ();
printf ("\n\n\n\n\n\n\n\n");
printf ("\t\t\t --------------------------- \n\n");

printf ("\t\t\t | IGCT, Info Computers, INDIA | \n\n");
printf ("\t\t\t --------------------------- ");

getch ();

}

Hits!!!