afaq

Menu driven Program in C

/*P5.36 A menu driven program using infinite loop and switch*/ #include<stdio.h> int main(void) { int choice; while(1) { printf(“1.Create database\n”); printf(“2.Insert new record\n”); printf(“3.Modify a record\n”); printf(“4.Delete a record\n”); printf(“5.Display all records\n”); printf(“6.Exit\n”); printf(“Enter your choice : “); scanf(“%d”,&choice); switch(choice) { case 1: printf(“Database created…..\n\n”); break; case 2: printf(“Record inserted…..\n\n”); break; case 3: printf(“Record modified…..\n\n”); […]

Vowel or consonant Program in C

/*P5.35 Program to find whether the alphabet is a vowel or consonant*/ #include<stdio.h> int main(void) { char ch; printf(“Enter an alphabet : “); scanf(“%c”,&ch); switch(ch) { case ‘a’: case ‘e’: case ‘i’: case ‘o’: case ‘u’: printf(“Alphabet is a vowel\n”); break; default: printf(“Alphabet is a consonant\n”); } return 0; } Output: Enter an alphabet : […]

Perform arithmetic calculations on integers Program in C

/*Program to perform arithmetic calculations on integers*/ #include<stdio.h> int main(void) { char op; int a,b; printf(“Enter number,operator and another number : “); scanf(“%d%c%d”,&a,&op,&b); switch(op) { case ‘+’: printf(“Result = %d\n”,a+b); break; case ‘-‘: printf(“Result = %d\n”,a-b); break; case ‘*’: printf(“Result = %d\n”,a*b); break; case ‘/’: printf(“Result = %d\n”,a/b); break; case ‘%’: printf(“Result = %d\n”,a%b); break; […]

Multiply two positive numbers without using “*” operator

/*Multiply two positive numbers without using * operator*/ #include<stdio.h> int main(void) { int a,b,i; int result=0; printf(“Enter two numbers to be multiplied : “); scanf(“%d%d”,&a,&b); for(i=1; i

Count digits Program in C

/*Program to count digits in a number */ #include<stdio.h> int main(void) { int n,count=0,rem; printf(“Enter a number : “); scanf(“%d”,&n); do { n/=10; count++; }while(n>0); printf(“Number of digits=%d\n”,count); return 0; } Output: Enter a number : 24512 Number of digits=5

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

1 4 5 6 7 8 36