c language tutorial

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

Integer arithmetic operations Program in C

WAP Integer arithmetic operations in C Language. /*Integer arithmetic operations in C Language*/ #include<stdio.h> int main(void) { int a=17,b=4; printf(“Sum=%d\n”,a+b); printf(“Difference=%d\n”,a-b); printf(“Product=%d\n”,a*b); printf(“Quotient=%d\n”,a/b); printf(“Remainder=%d\n”,a%b); return 0; } Output: Sum=21 Difference=13 Product=68 Quotient=4 Remainder=1

ASCII and Unicode

ASCII defines 128 characters, which map to the numbers 0–127. Unicode defines (less than) 221 characters, which, similarly, map to numbers 0–221 (though not all numbers are currently assigned, and some are reserved). Unicode is a superset of ASCII, and the numbers 0–127 have the same meaning in ASCII as they have in Unicode. For […]

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.

1 2 3 4 5 13