learn c language

Type conversion in assignment Program in C

/*P4.10 Program to understand type conversion in assignment*/ #include<stdio.h> int main(void) { char c1,c2; int i1,i2; float f1,f2; c1=’H’; i1=80.56; /*float converted to int, only 80 assigned to i1 */ f1=12.6; c2=i1; /*int converted to char */ i2=f1; /*float converted to int */ /*Now c2 has the character with ASCII value 80, i2 is assigned […]

sizeof operator Program in C

/*Program to understand the sizeof operator*/ #include<stdio.h> int main(void) { int var; printf(“Size of int=%u\n”,sizeof(int)); printf(“Size of float=%u\n”,sizeof(float)); printf(“Size of var=%u\n”,sizeof(var)); printf(“Size of an integer constant=%u\n”,sizeof(45)); return 0; } Output: Size of int=4 Size of float=4 Size of var=4 Size of an integer constant=4

Comma operator Program in C

/*Program to understand the use of comma operator*/ #include<stdio.h> int main(void) { int a,b,c,sum; sum = (a=8,b=7,c=9,a+b+c); printf(“Sum=%d\n”,sum); return 0; } Output: Sum=24

Print the larger of two numbers using conditional operator Program in C

/*Program to print the larger of two numbers using conditional operator */ #include<stdio.h> int main(void) { int a,b,max; printf(“Enter values for a and b :”); scanf(“%d%d”,&a,&b); max = a>b ? a : b; /*ternary operator*/ printf(“Larger of %d and %d is %d\n”,a,b,max); return 0; } Output: Enter values for a and b :5 7 Larger […]

Relational operators Program in C

/*Program to understand the use of relational operators*/ #include<stdio.h> int main(void) { int a,b ; printf(“Enter values for a and b : “); scanf(“%d%d”,&a,&b); if(a<b) printf(“%d is less than %d\n”,a,b); if(a<=b) printf(“%d is less than or equal to %d\n”,a,b); if(a==b) printf(“%d is equal to %d\n”,a,b); if(a!=b) printf(“%d is not equal to %d\n”,a,b); if(a>b) printf(“%d is […]

Prefix increment/decrement Program in C

/*WAP for Prefix increment/decrement*/ #include<stdio.h> #include<stdio.h> int main(void) { int x=8; printf(“x=%d\t”,x); printf(“x=%d\t”,++x); /*Prefix increment*/ printf(“x=%d\t”,x); printf(“x=%d\t”,–x); /*Prefix decrement*/ printf(“x=%d\n”,x); return 0; } Output: x=8 x=9 x=9 x=8 x=8

Understand the floating point arithmetic operations Program in C

/*Write a Program to understand the floating point arithmetic operations */ #include<stdio.h> int main(void) { float a=12.4,b=3.8; printf(“Sum=%.2f\n”,a+b); printf(“Difference=%.2f\n”,a-b); printf(“Product=%.2f\n”,a*b); printf(“a/b=%.2f\n”,a/b); return 0; } Output: Sum=16.20 Difference=8.60 Product=47.12 a/b=3.26

Check whether a given word exists in a file or not Program in C

WAP to check whether a given word exists in a file or not. If yes then find the number of times it occurs.

Compare the contents of two files Program in C

WAP to compare the contents of two files and determine whether they are same or not.

Swap two elements using the concept of pointers Program in C

WAP to swap two elements using the concept of pointers.

1 2 3 4 5 12