0% found this document useful (0 votes)
15 views36 pages

Gird Har

Uploaded by

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

Gird Har

Uploaded by

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

COMPUTER

PROJECT
2022-23
NAME – GIRDHAR SHUKLA
CLASS – 11-A
ROLL NO. – 12

ACKNOWLEDGEMENT
I would like to express my special thanks of
gratitude to my Computer teacher “Mrs.Rishi
Bala Pandey “ Ma’am for their able guidance and
support in completing my Project.

I would also like to extend my gratitude to the


Principal Mam "Mrs.Marina Cyrill" and Vice
Principal Sir "Mr.Tom Thomas" for providing me
with all the facility that was required.

DATE: 10/11/2022

GIRDHAR SHUKLA 11th "Maths" 'A'


PROGRAM 1
/* Write a program to print the smallest and greatest numbers from a
* single dimensional array*/

import java.util.*;
class small_great
{
public static void main(String [] args)
{
Scanner sc=new Scanner(System.in);
int i;int small,large;
int arr[]=new int[10];
for(i=0;i<10;i++)
{
arr[i]=sc.nextInt();
}
small=arr[0];large=arr[0];
for(i=1;i<10;i++)
{
if(arr[i]>large)
large=arr[i];
else if(arr[i]<small)
small=arr[i];
}
System.out.println("smallest number = "+small+"\ngreatest number ="+large);
}
}
OUTPUT SCREEN:
12
34
56
32
78
99
96
100
346
678
smallest number = 12
greatest number =678
PROGRAM 2
/*Write a program to remove all duplicate elements from a single dimensional array.*/

import java.util.*;
class duplicate
{
public static void main()
{
Scanner sc=new Scanner(System.in);
int arr[]=new int[10];
int i,j;
for(i=0;i<10;i++)
{
arr[i]=sc.nextInt();
}
System.out.println("output");
for(i=0;i<10;i++)
{
int c=0;
for(j=0;j<i;j++)
{
if(arr[i]==arr[j])
c++;
}
if(c==0)
System.out.print(arr[i]+" ");
}
}
}

OUTPUT SCREEN:

1
2
3
4
66
66
56
32
56
32
output
1 2 3 4 66 56 32
PROGRAM 3
/* Write a program to search a desired element from a single dimensional array
already arranged
* in ascending order using bimary search technique.*/

import java.util.*;
class search
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("enter 5 numbers in ascending order");
int arr[]=new int[5];
int i;
for(i=0;i<5;i++)
{
arr[i]=sc.nextInt();
}
System.out.println("Enter number to be searched");
int s=sc.nextInt();
int start=0,last=4;
int mid;int c=0;int p=0;
while(start<=last)
{
mid=(start+last)/2;
if(arr[mid]>s)
last=mid-1;
else if(arr[mid]<s)
start=mid+1;
else if(arr[mid]==s)
{
c++;

p=mid;
break;
}
}
if(c==1)
System.out.println("number found at "+p+" index");
else
System.out.println("number not found");
System.out.println("\t :-) \t ");
}
}
OUTPUT SCREEN:
1
2
3
4
5
Enter number to be searched
6
number not found
:-)
PROGRAM 4
/*Write a program to input a sentence and a word.Find the number of times the word
appears
* in the sentence.
*/

import java.util.*;
class word
{
int FindWords(String str,String w)
{
int i;
int c=0; String word="";
char ch;
str=str+" ";
for(i=0;i<str.length();i++)
{
ch=str.charAt(i);
if(ch!=' ')
{
word=word+ch;
}
else
{
if(word.equals(w))
{
c++;
}
word="";
}
}
return c;
}
public static void main()
{
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();
String w=sc.nextLine();
word ob=new word();
int ans=ob.FindWords(str,w);
System.out.println("number of time = "+ans);
}
}
OUTPUT SCREEN:
YES ! YES ! ILOVE COMPUTER SUBJECT.
YES
number of time = 2
PROGRAM 5
/* Write a program to print the squares of ten elements input by the user.*/

import java.util.*;
class printing
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter elements. . . .");
int i;
int arr[]=new int[10];
for(i=0;i<10;i++)
{
arr[i]=sc.nextInt();
}
System.out.println("output");
for(i=0;i<10;i++)
{
System.out.println(arr[i]+"\t"+(arr[i]*arr[i]));
}
}
}
OUTPUT SCREEN:
Enter elements. . . .
34
35
36
37
39
40
42
43
44
45
output
34 1156
35 1225
36 1296
37 1369
39 1521
40 1600
42 1764
43 1849
44 1936
45 2025
PROGRAM 6
/*Write a program to print only armstrong numbers from a single dimensional array.*/

import java.util.*;
class armstrong
{
public static void main()
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
System.out.println("enter size... and then elements");
int arr[]=new int[n];
int i,j,sum=0;
for(i=0;i<n;i++)
{
arr[i]=sc.nextInt();
}
System.out.println("OUTPUT");
for(i=0;i<n;i++)
{ sum=0;
for(j=arr[i];j>0;j/=10)
{
int d=j%10;
sum=sum+(d*d*d);
}
if(sum==arr[i])
{
System.out.println(arr[i]);
}
}
}
}

OUTPUT SCREEN:
enter size... and then elements
6
123
543
153
370
373
565
OUTPUT
153
370
PROGRAM 7
/* Write a program to accept a sentence a sentence from the user and convert each
word into palindrome;
* SAMPLE INPUT : help
* SAMPLPE OUTPUT :helpleh
*/
import java.util.*;
class complex_palin
{
void print(String w)
{
int i; String n=""; String palin=w;
for(i=0;i<w.length();i++)
{
n=w.charAt(i)+n;
}
if(n.equals(w))
{
System.out.println("wrong input");
System.exit(0);
}
else
{
for(i=w.length()-2;i>=0;i--)
{
palin=palin+w.charAt(i);
}
System.out.println(palin);
}
}
public static void main()
{
Scanner sc=new Scanner(System.in);
String st;
System.out.println("enter string......");
st=sc.nextLine();
complex_palin ob=new complex_palin();
StringTokenizer str=new StringTokenizer(st);
int c=str.countTokens();
int i;
for(i=0;i<c;i++)
{
String s=str.nextToken();
ob.print(s);

}
}
}
OUTPUT SCREEN:

enter string......
HELP ME PLEASE
HELPLEH
MEM
PLEASESAELP
PROGRAM 8
/*Write a program to accept a sentence from the user and print the smallest and
longest word from the sentence*/
import java.util.*;
class lon
{
public static void main()
{
Scanner sc=new Scanner(System.in);
String st;
System.out.println("enter a string .......");
st=sc.nextLine();
StringTokenizer str=new StringTokenizer(st);
int c=str.countTokens();
String l="";
String s=st;int i;
for(i=0;i<c;i++)
{
String sr=str.nextToken();
if(l.length()<sr.length())
l=sr;
if(s.length()>sr.length())
s=sr;

}
System.out.println("smallest="+ s);
System.out.println("longest= "+l);
}
}

OUTPUT SCREEN:
YES I LIKE TO MAKE COMPUTER PROGRAMS.
smallest=I
longest= PROGRAMS.
PROGRAM 9
/*Write a program to print the number of times a word appears in a sentence even as
a substring
* in the sentence*/
import java.util.*;
class word_times

{
public static void main()
{
Scanner sc=new Scanner(System.in);
String st=sc.nextLine();
String w=sc.nextLine();
int c=0;int i;int l=w.length();
for(i=0;i<st.length();i++)
{
if(w.charAt(0)==st.charAt(i))
if(w.equals(st.substring(i,i+l)))
c++;
}
System.out.println(" number of times the world appears is "+c);
}
}

OUTPUT SCREEN:
THE CAT HIDDHIDD UNDER THE HIDDENTABLE
HID
number of times the world appears is 3

PROGRAM 10
/*Write a program to print the input string in the following patttern
* SAMPLE INPUT : GIRDHAR
* SAMPLE OUTPUT : G
* II
* RRR
* DDDD
* HHHHH
* AAAAAA
* RRRRRRR
*/
import java.util.*;
class patterning
{
public static void main( )
{
Scanner sc=new Scanner(System.in);
System.out.println("enter string .....");
String st=sc.nextLine();
int i,j,a;a=0;
System.out.println("OUTPUT");
for(i=0;i<st.length();i++)
{
for(j=0;j<st.length();j++)
{
if((i+j)>=st.length()-1)
System.out.print(st.charAt(a));
else
System.out.print(" ");
}
a++;
System.out.println();
}
}
}

OUTPUT SCREEN:
enter string .....
GIRDHAR
OUTPUT
G
II
RRR
DDDD
HHHHH
AAAAAA
RRRRRRR
PROGRAM 11
/* Write a program to input element in a matrix of size 3x4.Print the transpose of
* the matrix.
* SAMPLE INPUT : 1234
* 5678
* 2456
*SAMPLE OUTPUT : 152
* 264
* 375
* 486
*/
import java.util.*;
class transpose
{
public static void main()
{
Scanner sc=new Scanner(System.in);
int i,j;
System.out.println("enter 12 elemnts....");
int arr[][]=new int[3][4];
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
arr[i][j]=sc.nextInt();
}
}
System.out.println("ORIGINAL MATRIX...");
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
System.out.print(arr[i][j]);
}
System.out.println();
}
System.out.println("OUTPUT");
for(i=0;i<4;i++)
{
for(j=0;j<3;j++)
{
System.out.print(arr[j][i]);
}
System.out.println();

}
}
}
OUTPUT SCREEN:
enter 12 elemnts....
1
2
3
4
5
6
7
8
9
0
2
3
ORIGINAL MATRIX...
1234
5678
9023
OUTPUT
159
260
372
483
PROGRAM 12
/* Write a program to print the following pattern
* 0
* 12
* 345
* 6789
*/
class pattern
{
public static void main()
{
int i,j;
int a=0;

for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
if(i+j>=3)
{
System.out.print(a);
a++;
}
else
{
System.out.print(" ");
}
}
System.out.println();
}
}
}

OUTPUT SCREEN:
0
12
345
6789
PROGRAM 13

/*Write a program to print the following pattern


* 10000
* 11000
* 11100
* 11110
* 11111
*/
class pattern_2
{
public static void main()
{
int arr[][]=new int[4][4];
int i,j;
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
if(i>=j)
{
System.out.print(1);
}
else
{
System.out.print(0);
}
}
System.out.println();
}
}
}

OUTPUT SCREEN:
1000
1100
1110
1111
PROGRAM 14
/*Write a program to reverse a sentence input by the user.*/

import java.util.*;
class reverse
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("enter string");
String st=sc.nextLine();
String w=""; String ne=""; st=st+" ";
char ch; int i;
for(i=0;i<st.length();i++)
{
ch=st.charAt(i);
if(ch!=' ')
{
w=w+ch;
}
else
{
ne=w+" "+ne;
w="";
}
}
System.out.println("reverse string = "+ne);
}
}

OUTPUT SCREEN:
enter string
I LIKE COMPUTER SCIENCE.
reverse string = SCIENCE. COMPUTER LIKE I
PROGRAM 15
/* Write aprogram to make a scientific calculator*/
import java.util.*;
class calculator
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("enter \n 1.sum\n2.differnce\n3.product\n4.sine function\
n5.cos function");
int c=sc.nextInt();int a,b;

switch(c)
{
case 1:
System.out.println("enter 2 numbers ");
a=sc.nextInt();
b=sc.nextInt();
System.out.println("sum ="+(a+b));
break;
case 2:
System.out.println("enter 2 numbers ");
a=sc.nextInt();
b=sc.nextInt();
System.out.println("difference ="+(a-b));
break;
case 3:
System.out.println("enter 2 numbers ");
a=sc.nextInt();
b=sc.nextInt();
System.out.println("product ="+(a*b));
break;
case 4:
System.out.println("enter angel in radians ");
a=sc.nextInt();

System.out.println("sine ="+Math.sin(a));
break;
case 5:
System.out.println("enter angel in radians ");
a=sc.nextInt();

System.out.println("cos ="+Math.cos(a));
break;
}
}
}
OUTPUT SCREEN:
enter
1.sum
2.differnce
3.product
4.sine function
5.cos function
4
enter angel in radians
3
sine =0.1411200080598672

You might also like