#include<stdio.h> void main() { int a,b,sum; printf("Enter any two integers: ");
scanf("%d%d",&a,&b); sum = a + ~b + 1; printf("Difference of two integers: %d",sum); }
#include<stdio.h> void main() { int a,b,sum; printf("Enter any two integers: ");
scanf("%d%d",&a,&b); sum = a + ~b + 1; printf("Difference of two integers: %d",sum); }
#include <stdio.h> #include <conio.h> #include <stdlib.h> long double fact( int); int ncr( int ,int); long npr( int ,int); main() { int n,r; printf(" Enter value of n & r \n"); scanf("%d %d",&n ,&r); if( n>= r) { printf( "%d C %d is %d \n",n,r,ncr( n ,r)); printf("%d P %d is %ld\n",n,r,npr( n, r)); } else { printf("\n n should be greater than r"); getch (); }
long double fact( int p) { long double facts = 1; int i; for( i = 1; i<= p; i++) facts = facts * i; return(facts); } int ncr ( int n, int r) { return( fact( n) / (fact( r) * fact(n- r) ) ) ; } long npr( int n ,int r) { return( fact( n) / fact( n- r)); }
# include <stdio.h> # include <conio.h> # include <math.h> void main () { int a,b=0,sum=0; long int n; printf("Enter the number to check\n "); scanf("%i",&n); if(n<1) { printf ("\nThe number should be greater than 0"); } else { a=n; //counting the digits while (a>0) { a=a/10; b++; } a=n; //adding up bth power of digits while(a>0) { sum=sum+pow(( a%10) ,b); a=a/10; } if(sum==n) printf ("\nThe number is an ARMSTRONG number"); else printf ("\nThe number is NOT an ARMSTRONG number"); } getch(); }
#include<stdio.h>
struct student
{
char name[5];
int roll;
int mysize;
};
main()
{
unsigned long int b;
printf("size of variable b: %d",sizeof b);
printf("\nsize of int:%d",sizeof(int));
printf("\nsize of float:%d",sizeof(float));
printf("\nsize of char:%d",sizeof(char));
printf("\nsize of long:%d",sizeof(long));
printf("\nsize of double:%d",sizeof(double));
printf("\nsize of short:%d",sizeof(short));
struct student s1;
s1.mysize=sizeof(s1.name)+sizeof(s1.roll)+sizeof(s1.mysize);
printf("\nSizeof structure student :%d",s1.mysize);
/*see the difference shown in size of structure */
printf("\nsize of structure student : %d",sizeof(struct student));
}
size of variable b: 4
size of int:4
size of float:4
size of char:1
size of long:4
size of double:8
size of short:2
Sizeof structure student :13
size of structure student : 16
#include<stdio.h> #include<math.h> void main() { int n,sum,r,digits; for(n=1;n<=1000;n++)  { digits=0; r=n; sum=0; while(r!=0) //Counting Digits { digits++; r/=10; } r=n; while(r!=0) /*Adding Digits Raised To a Power That Is Equal To Number of Digits * { sum+=pow((r%10),digits); r=r/10; } if(sum==n) { printf("%5d",sum); }
}
}
#include<stdio.h> main() { int a[7][7],i,j,k,m,n,temp; //reading printf("enter number of rows of matrix\n"); scanf("%i",&m); printf("enter number of columns of matrix\n"); scanf("%i",&n); printf("enter the elements\n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) scanf("%d",&a[i][j]); } //displaying printf("the matrix you entered:\n"); for(i=0;i<m;i++) { printf("\n"); for(j=0;j<n;j++) { printf("%4d",*(*(a+i)+j)); } } //sorting for(i=0;i<n;i++) { for(k=0;k<m-1;k++) { for(j=0;j<m-k-1;j++) { //comparison if( *(*(a+j)+i)> *(*(a+(j+1))+i)) { temp=*(*(a+j)+i); *(*(a+j)+i)=*(*(a+(j+1))+i); *(*(a+(j+1))+i)=temp; } } } } //displaying printf("\nSorted Matrix:\n"); for(i=0;i<m;i++) { printf("\n"); for(j=0;j<n;j++) { printf("%4d",*(*(a+i)+j)); } } }
#include<stdio.h> main () { unsigned int a = 60; /* 60 = 0011 1100*/ unsigned int b = 13; /* 13 = 0000 1101 */ printf ("a=60 ( 0011 1100)\nb=13 ( 0000 1101)\n"); int c = 0; c = a&b ; /* 12 = 0000 1100 */ printf ("a&b=%d\n",c ); c = a | b ; /* 61 = 0011 1101 */ printf ("a|b=%d\n",c ); c = a ^ b ; /* 49 = 0011 0001 */ printf ("a^b=%d\n", c ); c = ~ a; /*-61 = 1100 0011 */ printf ("~a=%d\n" , c ); c = a << 2 ; /* 240 = 1111 0000 */ printf ("a<<2=%d\n" , c ); c = a >> 2 ; /*15 = 0000 1111*/ printf ("a>>2=%d\n" , c ); }
#include<stdio.h>
void main() { int a[10][10],i,m,j; int det=0; printf("\nEnter the order of matrix:\n "); scanf("%i",&m); printf("\nenter elements\n"); for(i=0;i<m;i++) { for(j=0;j<m;j++) scanf("%d",&a[i][j]); } printf("\nThe matrix is\n"); for(i=0;i<m;i++) { printf("\n"); for(j=0;j<m;j++) printf("%3d",a[i][j]); } printf("\nthe transpose is\n"); for(i=0;i<m;i++) { for(j=0;j<m;j++) printf("%3i",a[j][i]); printf("\n"); } if(m==1) { det=a[0][0]; printf("det=%i",det); } else if(m==2) { int k=1,l=1; for(i=0;i<2;i++) for(j=0;j<2;j++) { if(i==j) k*=a[i][j]; else l*=a[i][j]; } printf("\ndeterminant=%i",k-l); } else if(m==3) { for(i=0;i<3;i++) det=det+(a[0][i]*(a[1][(i+1)%3]*a[2][(i+2)%3]-a[1][(i+2)%3]*a[2][(i+1)%3])); printf("\nDeterminant of matrix is: %d",det); } else printf("This program can't calculate determinant of matrix of order greater than 3"); }
#include<stdio.h> #include<conio.h> long factorial(int); main() { int i, n, c; printf("Enter the number of rows you wish to see in pascal triangle\n"); scanf("%d", &n); for (i = 0; i < n; i++) { for (c = 0; c <= (n - i - 2); c++) printf(" "); for (c = 0; c <= i; c++) printf("%ld ", factorial(i) / (factorial(c) * factorial(i - c))); printf("\n"); } getch(); } long factorial(int n) { int c; long result = 1; for (c = 1; c <= n; c++) result = result * c; return (result); }