0% found this document useful (0 votes)
53 views31 pages

Pro Final

This document contains 17 programming assignments related to computer science concepts like arrays, loops, functions, and conditionals. The assignments include tasks like displaying numbers, calculating salary, checking if a number is prime, sorting arrays, and searching arrays. Each assignment is presented with sample code and expected output to demonstrate how to solve the programming problem.

Uploaded by

Meghashiree R
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views31 pages

Pro Final

This document contains 17 programming assignments related to computer science concepts like arrays, loops, functions, and conditionals. The assignments include tasks like displaying numbers, calculating salary, checking if a number is prime, sorting arrays, and searching arrays. Each assignment is presented with sample code and expected output to demonstrate how to solve the programming problem.

Uploaded by

Meghashiree R
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

COMPUTER ASSIGNMENTS

XI STD

2023 - 2024
Table of contents

SNO NAME OF THE PROGRAM Page No. Teacher’s


signature

1 Displaying Numbers

2 Calculating Salary

3 Displaying f(x) value

4 Calculating Bonus

5 Calculating Grade

6 Calculating Power to the number

7 Counting digits of number

8 Checking Prime Number

9 Discount Calculation

10 Library Management

11 Ascending order

12 Searching in an array

13 Symmetric Matrix

14 Salary bill generation

15 Sum of series
16 Frequency of characters
17 Frequency of vowels
Ex. No. 1 Displaying Numbers

Program to find two, three and four digit numbers


import java.util.*;
public class digit
{
public static void main()
{
Scanner sc=new Scanner(System.in);int f,s,t;
System.out.println("Enter the number:-");
int n=sc.nextInt();
f=(n*10)+n;
s=(n*10*10)+f;
t=(n*10*10*10)+s;
System.out.println( f +","+s+","+t);
}
}
OUTPUT
Ex. No. 2 Calculating Salary

Program to calculate Gross salary and Net salary


import java.util.*;
public class basic
{
public static void main()
{
Scanner sc=new Scanner(System.in);double da,hra,pf,epf,cta,gross,net;
System.out.println("Enter the Basic salary:-");
int b=sc.nextInt();
da=40*b/100;
hra=12*b/100;
pf=8.33*b/100;
epf=1.67*b/100;
cta=8*b/100;
gross=b+hra+da+cta;
net=gross-(pf+epf);
System.out.println("The gross salary: Rs."+gross);
System.out.println("The net salary: Rs."+net);
}
}

OUTPUT
Ex. No. 3 Displaying f(x) value

Program to calculate the value of function f(x) according to value of x entered


import java.util.*;
public class fun
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number:");
int x=sc.nextInt();
double fx=0;
if(x>=-3&&x<=-1)
fx=(x+2)/((2*x)+1);
else if(x==0)
fx=((2*x)-1)/(x+1);
else if(x>=1&&x<=3)
fx=((2*x)+1)/((2*x)-1);
else
System.out.println("Incorrect value has been entered");
System.out.println("The value of f(x)="+fx);
}
}

OUTPUT
Ex. No. 4 Calculating Bonus

import java.util.*;
class kepler_195_2
{
public static void main()
{ double b;
Scanner sc=new Scanner(System.in);
System.out.println("enter your grade(a or b or c)");
char ch=sc.next().charAt(0);
System.out.println("enter your basic ammount(annual)");
double bas=sc.nextDouble();
switch(ch)
{
case 'a': b=(0.12*bas);
if(b>50000)
{
b=50000; System.out.println("your bonus amount is="+b);
}
else
System.out.println("your bonus amount is="+b);
break;
case 'b': b=(0.1)*bas;
if(b>40000)
{
b=40000; System.out.println("your bonus amount is="+b);
}
else
System.out.println("your bonus amount is="+b);
break;
case 'c': b=(0.0833)*bas;
if(b>30000)
{
b=30000; System.out.println("your bonus amount is="+b);

}
else
System.out.println("your bonus amount is="+b);
break;
}

}
}

Output :
Ex. No. 5 Calculating Grade
import java.math.*;
import java.util.*;
class kepler_233_1
{
public static void main()
{
Scanner sc=new Scanner(System.in);
int i,t=1;double s=0;
System.out.println("ent value of n followed by value of a");
int n=sc.nextInt();
int a=sc.nextInt();
for(i=0;i<n;i++)
{
s=s+Math.pow(a,t);
t++;
}
System.out.println("value="+(s+1));
}
}
Output :
Ex. No. 6 Calculating Power to the number
import java.util.*;
import java.math.*;
class kepler_233_2
{
public static void main()
{
Scanner sc= new Scanner(System.in);
int i,t=2;
double s=0;
System.out.println("ent value of n and a");
int n=sc.nextInt();
int a=sc.nextInt();
for(i=0;i<n;i++)
{
if(i%2==0)
s=s-Math.pow(a,2)/t;
else
s=s+Math.pow(a,2)/t; t++;
}
System.out.println("value="+(s+1));
}
}
Output :-
Ex. No. 7 Counting digits of number
import java.util.*;
class digit
{
int c=0;
int digitnum(int n)
{
if(n==0)
return(c);
else
{
c++;
return(digitnum(n/10));
}
}
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.print("enter a number: ");
int num;int k;
num=sc.nextInt();
digit ob=new digit();
k=ob.digitnum(num);
System.out.println("The number of digits present: "+k);
}
}
Output:
Ex. No. 8 Checking Prime Number
import java.util.*;
class PRIME
{
int factor(int n,int i)
{
if (n==i)
return(2);
if (n==0)
return(2);
if (n==1)
return(2);
if (n%i==0)
return(1);
if (n%i!=0)
i++;
return(factor(n,i));
}
public static void main()
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter a number");
int m,j,k;
k=0;
j=2;
m= sc.nextInt();
PRIME ob=new PRIME();
k=ob.factor(m,j);
if(k==2)
System.out.println("Prime number");
else
System.out.println("Not a prime number");
}
}

Output:
Ex. No. 9 Discount Calculation
import java.util.*;
class Discount
{
int cost;String name;double dc;double amt;
Scanner in=new Scanner(System.in);
void input()
{
System.out.println("Enter the name of the customer");
name=in.next();
System.out.println("Enter the cost of article purchased");
cost=in.nextInt();
}
void cal()
{
if(cost<=5000)
{
dc=0;
}
if(cost>=5001&&cost<=10000)
{
dc=cost*0.10;
}
if(cost>=10001&&cost<=15000)
{
dc=cost*0.15;
}
if(cost>15000)
{
dc=cost*0.20;
}
amt=cost-dc;
}
void display()
{
System.out.println("Name of the customer="+name);
System.out.println("Cost="+cost);
System.out.println("Discount="+dc);
System.out.println("Amount to be paid="+amt);
}
public static void main()
{
Discount ob=new Discount();
ob.input();
ob.cal();
ob.display();
}
}

Output:
Ex. No. 10 Library Management
import java.util.*;
class Library
{
int day;String name;double fine;
Scanner in = new Scanner(System.in);
void input()
{
System.out.println("Enter the name");
name=in.next();
System.out.println("Enter the number of days for which fine is to be paid");
day=in.nextInt();
}
void cal()
{
if(day<=7)
fine=day*25;
if(day>=8&&day<=15)
fine=day*40;
if(day>=16&&day<=30)
fine=day*60;
if(day>30)
fine=day*80;
}
void display()
{
System.out.println("Name of the book="+name);
System.out.println("Fine to be paid="+fine);
}
public static void main()
{
Library ob=new Library();
ob.input();
ob.cal();
ob.display();
}
}

Output:
Ex. No. 11 Ascending order

import java.util.*;
class arrsere
{
public static void main()
{Scanner sc=new Scanner(System.in);
int a[]=new int[4];
System.out.println("enter 4 numbers");
for(int e=0;e<4;e++)
a[e]=sc.nextInt();
int min,i,j,t,m,n;
for(i=0;i<4;i++)
{
for(j=0;j<3;j++)
{
if(a[j]>a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}System.out.println("Ascending Order=");
for(m=0;m<4;m++)
{if(m!=3)
System.out.print(a[m]+" , ");
else
System.out.print(a[m]);
}
System.out.println();
System.out.println("Required output");
for(i=0;i<3;i++)
{m=a[i]+1;
for(j=m;j<a[i+1];j++)
{
System.out.print(j+" , ");
}
}
}
}
Output :
Ex. No. 12 Searching in an array
import java.util.*;
class school
{
public static void main()
{
Scanner sc=new Scanner(System.in);
String name[]=new String[5];
String town[]=new String[5];
int pos=-1;
System.out.println("enter the list of 5 school and the towns in which they are
located");
for(int i=0;i<5;i++)
{
name[i]=sc.next();
town[i]=sc.next();
}
System.out.println("enter the school to be searched.");
String s=sc.next();
for(int i=0;i<5;i++)
{
if(s.compareTo(name[i])==0)
{
pos=i;
}
}
if(pos>=0)
{
System.out.println("Name of the school= "+name[pos]);
System.out.println("Location= "+town[pos]);
}
else
{
System.out.println("Not Found . ");
}
}
}
Output :
Ex. No. 13 Symmetric Matrix
import java.util.*;
class atrix
{
public static void main()
{
Scanner sc=new Scanner(System.in);
int m,i,j,n=0,t;
System.out.println("Enter the number of rows .");
m=sc.nextInt();
int a[][]=new int[m][m];
System.out.println("Enter the elements . ");
for(i=0;i<m;i++)
{
for(j=0;j<m;j++)
{
a[i][j]=sc.nextInt();
}
}
for(i=0;i<m;i++)
{

for(i=0;i<m;i++)
{
for(j=0;j<m;j++)
{
if(a[i][j]==a[j][i])
n++;
}
}
t=m*m;
if(n==t)
System.out.println("It is a Symmetric Matrix .");
else
System.out.println("It is not a Symmetric Matrix .");
}
}
}
Output :
Ex. No. 14 Salary bill generation
import java.io.*;
import java.util.*;
class company
{
public static void main()
{
int cat,bp,y;double ea=0.0;
Scanner in=new Scanner(System.in);
System.out.println("enter your category (1or2or3)");
cat=in.nextInt();
System.out.println("enter your basic salary");
bp=in.nextInt();
System.out.println("enter your years of service");
y=in.nextInt();
if(cat==1)
{
System.out.println("QUALIFICATION::Primary");
ea=y*500;
}
if(cat==2)
{
System.out.println("QUALIFICATION::TGT");
ea=y*700;
}
if(cat==3)
{
System.out.println("QUALIFICATION::PGT");
ea=y*900;
}

System.out.println("EXPERIENCE ALLOWANCE="+ea);
double tb=bp+ea;
System.out.println("TOTAL BASIC="+tb);
double da=0.4*tb;
System.out.println("DEARNESS ALLOWANCE="+da);
double hr=0.2*tb;
System.out.println("HRA="+hr);
double ct=0.1*tb;
System.out.println("CTA="+ct);
double pf=0.0833*tb;
System.out.println("P.F.="+pf);
double GR=tb+da+hr+ct;
System.out.println("GROSS="+GR);
double N=GR-pf;
System.out.println("NET="+N);
}
}
OUTPUT:
Ex. No. 15 Sum of series
import java.io.*;
import java.util.*;
class series
{
public static void main()
{
double a,n,s=0;int i;
Scanner in=new Scanner(System.in);
System.out.println("enter the value of 'a':");
a=in.nextDouble();
for(i=2;i<=10;i++)
{
if(a%2==0)
s=s-((Math.pow(a,2))/i);
if(a%2!=0)
s=s+((Math.pow(a,2))/i);
}
System.out.println("SUM OF THE SERIES="+(s+1));
}
}
OUTPUT:
Ex. No. 16 frequency of characters
import java.util.*;
public class frequency
{
public static void main()
{
Scanner sc=new Scanner(System.in);
int a[]=new int[30];
char d[]=new char[30];
int i,l,c=0,h=0;
String s;
System.out.println("Enter a sentence");
s=sc.nextLine();
s=s+" ";
l=s.length();
for(int j=65;j<=90;j++)
{
char t=(char)j;
char m=(char)(j+32);
for(int k=0;k<l;k++)
{
char ch=s.charAt(k);
if(ch==t||ch==m)
c++;}
if(c!=0)
{
a[h]=c;
d[h]=t;
h++;
c=0;}
}
int max=a[0],pos=0;
for(i=0;i<h;i++)
{if(a[i]>max)
{
max=a[i];
pos=i;}}
for(int f=0;f<h;f++)
{System.out.println(d[f]+"-"+a[f]);}
System.out.println("The character "+d[pos]+" has the highest
frequency of"+max);
}}
Output:
Ex. No. 17 Frequency of vowels
import java.util.*;
public class alpha
{
public static void main()
{
Scanner sc=new Scanner(System.in);
String s,w="",w1="",w2="",k="";
int i,l,c=0;
System.out.println("Enter a sentence");
s=sc.nextLine();
s=s+" ";
l=s.length();
for(i=0;i<l;i++)
{
char ch=s.charAt(i);
if(ch!=' ')
{
w=w+ch;}
else
{
int l1=w.length();
char ch1=w.charAt(0);
char ch2=w.charAt(l1-1);

if((ch1=='a'||ch1=='e'||ch1=='i'||ch1=='o'||ch1=='u'||ch1=='A'||ch1=='E'||ch1=='I'||ch1
=='O'||ch1=='U')&&(ch2=='a'||ch2=='e'||ch2=='i'||ch2=='o'||ch2=='u'||ch2=='A'||ch2=
='E'||ch2=='I'||ch2=='O'||ch2=='U'))
{w1=w1+w+" ";c++;}
else
w2=w2+w+" ";
w="";}}
k=w1+w2;
System.out.println(“Number of words beginning and ending with a vowel=”+c);
System.out.println(k);
}}
Output:

You might also like