study c language

Print numbers from 1 to 10 using while loop Program in C

/*Program to print numbers from 1 to 10 using while loop*/ #include<stdio.h> int main(void) { int i=1; while(i<=10) { printf(“%d\n”,i); i = i+1; /*Statement that changes the value of condition*/ } printf(“\n”); return 0; } Output: 1 2 3 4 5 6 7 8 9 10

Find out the grade of a student Program in C

/*Program to find out the grade of a student when the marks of 4 subjects are given. The method of assigning grade is – percentage>=85 grade=A percentage<85 and percentage>=70 grade=B percentage<70 and percentage>=55 grade=C percentage<55 and percentage>=40 grade=D percentage

Find biggest number from three given numbers Program in C

/*Program to find biggest number from three given numbers*/ #include<stdio.h> int main(void) { int a,b,c,big; printf(“Enter three numbers : “); scanf(“%d%d%d”, &a, &b, &c); if(a>b) { if(a>c) big=a; else big=c; } else { if(b>c) big=b; else big=c; } printf(“Biggest number is %d\n”,big); return 0; }/*End of main()*/ Output: Enter three numbers : 5 10 14 […]

Find quotient and remainder Program in C

/*Program to find quotient and remainder*/ #include<stdio.h> int main(void) { int x,y,quo,rem; printf(“Enter two numbers : “); scanf(“%d%d”,&x,&y); if(y) /*if y is non-zero*/ { quo=x/y; rem=x%y; printf(“Quotient=%d, Remainder=%d\n”,quo,rem); } else printf(“Divide by zero error\n”); return 0; } Output: Enter two numbers : 25 7 Quotient=3, Remainder=4

Print a message if negative number is entered Program in C

/*Program to print a message if negative number is entered */ #include<stdio.h> int main(void) { int num; printf(“Enter a number : “); scanf(“%d”,&num); if(num<0) { printf(“Number entered is negative\n”); num=-num; } printf(“Value of num is : %d\n”, num); return 0; } Output: Enter a number : -15 Number entered is negative Value of num is […]

Print whether a number is even or odd Program in C

/*Program to print whether a number is even or odd */ #include<stdio.h> int main(void) { int num; printf(“Enter a number : “); scanf(“%d”,&num); if(num%2 == 0) /*test for even */ printf(“Number is even\n”); else { printf(“Number is odd\n”); num*=2; printf(“Now the number is %d\n”,num); } return 0; } Output: Enter a number : 15 Number […]

Print the bigger number Program in C

/*Program to print the bigger number*/ #include<stdio.h> int main(void) { int a,b; printf(“Enter two numbers : “); scanf(“%d%d”,&a,&b); if(a>b) printf(“Bigger number=%d\n”,a); else printf(“Bigger number=%d\n”,b); return 0; } Output: Enter two numbers : 5 15 Bigger number=15

BODMAS expressions Program in C

/*P4.12 Program to evaluate some expressions*/ int main(void) { int a,b,c,d,e,f,g,h,k; a=8, b=4, c=2, d=1, e=5, f=20; printf(“%d\t”, a+b-(c+d)*3%e+f/9); a=17, b=5, c=6, d=3, e=5; printf(“%d\t”,a%6-b/2+(c*d-5)/e); a=4, b=5, c=6, d=3, e=5, f=10; printf(“%d\t”,a*b-c/d

use of cast operator Program in C

/*P4.11 Program to illustrate the use of cast operator*/ #include<stdio.h> int main(void) { int x=5,y=2; float p,q; p=x/y; printf(“p=%f\n”,p); q=(float)x/y; printf(“q=%f\n”,q); return 0; } Output: p=2.000000 q=2.500000

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 […]

1 2 3 4 12