Afaq Ahmad Khan

Product of digits Program in C

/*Program to find the product of digits of any number*/ #include<stdio.h> int main(void) { int n,prod=1,rem; printf(“Enter a number : “); scanf(“%d”,&n); while(n>0) { rem = n%10; /*taking last digit of n*/ prod*=rem; n/=10; /*skipping last digit of n*/ } printf(“Product of digits = %d\n”,prod); return 0; } Output: Enter a number : 12345 Product […]

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

Binary Search Program in C

#include<stdio.h> void main() { int i,ar[10],pos=-1, n,mid, lb, ub; printf(“Enter array in sorted order:-\n”); for(i=0; i<=9; i++) { printf(“ar[%d]=”,i); scanf(“%d”,&ar[i]); } lb = 0; ub = 9; printf(“Enter number to be search=”); scanf(“%d”,&n); while(lb<ub) { mid = (lb+ub)/2; if(ar[mid]==n) { pos=mid+1; break; } else if(ar[mid]&lt;n) { lb = mid+1; } else { ub = mid-1; […]

Employee Salary Based Program in Java

import java.util.*; /** * Define a class employee with the following members to compute the salary slip of an employee. * @author (Afaq) */ public class Employee { int empno; String name; float salary, hra, da, it, gp; Employee() { empno=0; name = “”; salary = 0.0f; hra = 0.0f; da = 0.0f; it = […]

Decimal to Binary Number Program in Java

import java.util.Scanner; /** * * @author AFAQ */ public class DecimalToBinary { public static void main(String[] args) { int decimal; Scanner sc = new Scanner(System.in); System.out.print(“Enter decimal number=”); decimal = sc.nextInt(); String binary = “”; while (decimal > 0) { binary= decimal % 2 + binary ; decimal = decimal / 2; } System.out.println(“Binary=”+binary); } […]

Binary to Decimal Number Program in Java

import java.util.Scanner; /** * * @author AFAQ */ public class BinaryToDecimal { public static void main(String[] args) { int binary; Scanner sc = new Scanner(System.in); System.out.print(“Enter binary number=”); binary = sc.nextInt(); int decimal = 0; int n = 0; while (binary>0) { int temp = binary % 10; decimal += temp * Math.pow(2, n); binary […]

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

1 3 4 5 6 7 35