Skip to main content

Posts

Showing posts from December, 2019

FEATURED POST

Why the World is Running Out of Computers

How do I write a program binary search in C?

#include<stdio.h> main() {     int i,val,n,a[90],first,last,mid;     printf("Enter the value of n: ");     scanf("%d",&n);     printf("Enter the elements:\n");         for(i=0; i<n; i++)         {             scanf("%d",&a[i]);         }         printf("Enter the value to be searched: ");         scanf("%d",&val);         first=0;         last=n-1;         mid=(first+last)/2;         while(first<=last)         {             if(a[mid]<val)                 first=mid+1;             else if(a[mid]==val){                 printf("Positi...

How do I write a program using the Euler method?

#include<stdio.h> #include<math.h> float f(float x, float y) { return (x*x-y); } main() { float x0,y0,h,xn,y1; printf("enter te value of x0, xn and y0: "); scanf("%f%f%f",&x0,&xn,&y0); printf("enter the value of h: "); scanf("%f",&h); while(x0<xn) { y1=y0+h*f(x0,y0); y0=y1; x0=x0+h; } printf("Value of y is: %f",y1); } OUTPUT:

How do I write a program using the bisection method?

#include<stdio.h> #include<math.h> #define EPSILON 1e-5f float f(float); float f(float x) { return ((x*x*x)-3*x-5); } main() { int i=0; float a,b,c1,c2; printf("Enter a & b: "); scanf("%f%f",&a,&b); do { i++; c1=(a+b)/2; printf("\nIteraton %d & Root %1.4f",i,c1); if(f(a)*f(c1)<0) b=c1; else a=c1; c2=(a+b)/2; } while(fabs(c1-c2)>EPSILON); } OUTPUT:

Question: Develop an applet that receives an integer in one text field,and computes its factorial value and return it in another text field, when the button named “Compute” is clicked

Question: Develop an applet that receives an integer in one text field,and computes its factorial value and return it in another text field, when the button named “Compute” is clicked import java.awt.*; import java.awt.event.*; import java.applet.*; public class Factorial extends Applet implements ActionListener {     Label l1,l2; TextField t1,t2;     Button com;         public void init()     {          l1=new Label("Enter a no.");         add(l1);         l2=new Label("Factorial");         add(l2);         t1=new TextField(10);         add(t1);         t2=new TextField(10);      ...

Question: Write a program to create a moving string by applet.

Question: Write a program to create a moving string by applet. import java.applet.Applet; import java.awt.*; import java.awt.event.*; public class MovingString extends Applet implements Runnable { String msg="Hey it's me Gargi....";       Thread t=null;       public void init()       {       setBackground(Color.cyan);                   setBackground(Color.red);                   t=new Thread(this);                   t.start();       }       public void run()       {      ...

Question: Write a program to draw a face by applet.

Question: Write a program to draw a face by applet.      import java.awt.*; import java.applet.*; public class Face extends Applet { public void paint(Graphics g)       { g.setColor(Color.black);                   g.drawOval(40,40,120,150); //head                   g.setColor(Color.black);                   g.drawOval(57,75,30,20); //left eye                   g.setColor(Color.black);                   g.drawOval(110,75,30,20); //right eye                   g.setColo...

Question: Write a program to implement synchronization.

Question: Write a program to implement synchronization. class Callme {                        public synchronized void call(String msg)                        {                         System.out.print("["+msg);                         try                         {                        ...