Menus

Thursday, 30 January 2020

Write c program to print multiplication table of a number


#include<stdio.h>

void main()
{

int n,i;

printf("Enter number ");
scanf("%d",&n);


for(i=1;i<=10;i++)
{

printf("%d * %d = %d\n",i,n,i*n);

}


}





Wednesday, 15 January 2020

Android WebView


Android – How to display information with justify alignment?






Android WebView is used to display web page in android. The web page can be loaded from same application or URL. It is used to display online content in android activity.



WebviewActivity.java 


package com.example.root.shaneeshprograms;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;

public class WebviewActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_webview);

        //create html page
        String htmlPage = "<html><body style=\" text-align:justify\">" +
                "<p style=\"text-align: center; font-size: 30px; \">WebView</p>" +
                "<p style=\" font-size: 22px;  LINE_HEIGHT: 32px;\">"+
                "Android <b>WebView</b> is used to display web page in android. The web page can be loaded from same application or URL. It is used to display online content in android activity."+
                "Android WebView is used to display web page in android. The web page can be loaded from same application or URL. It is used to display online content in android activity."+
                "Android WebView is used to display web page in android. The web page can be loaded from same application or URL. It is used to display online content in android activity."+
                "</p>"+
                "<body></html>";



        //add to webview
        WebView webView = (WebView) findViewById(R.id.webView);
        webView.loadData(htmlPage,"text/html","utf-8");


    }

}



activity_webview.xml


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.root.shaneeshprograms.WebviewActivity">


    <WebView
        android:id="@+id/webView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"></WebView>

</RelativeLayout>



How to load a webpage in android activity





Java code


WebView webView = (WebView)findViewById(R.id.webView);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("http://yii2ideas.blogspot.com/p/blog-page.html");

xml code

<WebView
    android:id="@+id/webView"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
</WebView>




Wednesday, 25 December 2019

Android load image from url


How to load image from a URL or internet in android


Subscribe Here


To add internet permission in your android Manifest file.

<uses-permission android:name="android.permission.INTERNET" />


Add ImageView on your xml file.

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        >

        <ImageView
            android:id="@+id/ivPhoto"
            android:layout_width="120dp"
            android:layout_height="120dp"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="10dp"
            android:padding="5dp"
            android:layout_gravity="center"
            android:src="@drawable/photo"

            />

    </LinearLayout>


To create an Async class as an inner class in our MainActivity class. The use of Asyn class is very important since it prevents us from downloading our remote image using the main application thread.

Code :


import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;

import java.io.InputStream;

public class ImageloadActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_imageload);

        ImageView imgPhoto = (ImageView)findViewById(R.id.ivPhoto);

        String urlPath = "http://10.42.0.1/dsms/backend/web/stud_photos/119426.jpg";

        Downloadimagefromurl downloadTask = new Downloadimagefromurl(imgPhoto);
        downloadTask.execute(urlPath);

    }



    private class Downloadimagefromurl extends AsyncTask<String,Void,Bitmap>{

        ImageView bmImg;

        public Downloadimagefromurl(ImageView bmImg) {
            this.bmImg = bmImg;
        }

        @Override
        protected Bitmap doInBackground(String... urls) {
            String pathFile = urls[0];
            Bitmap bitmap = null;

            try {
                InputStream inp = new java.net.URL(pathFile).openStream();
                bitmap = BitmapFactory.decodeStream(inp);
            } catch (Exception e){
                Log.e("Error",e.getMessage());
                e.printStackTrace();
            }

            return bitmap;
        }

        @Override
        protected void onPostExecute(Bitmap bitmap) {
            bmImg.setImageBitmap(bitmap);
        }

    }




}

Subscribe Here Output





Display default image in imageview if no image returned from server


 @Override
    protected void onPostExecute(Bitmap bitmap) {
        if(bitmap != null)
            bmImg.setImageBitmap(bitmap);
        else
            bmImg.setImageResource(R.drawable.photo);

    }




Saturday, 14 December 2019

c program to find area of circle


Code

#include<stdio.h>

void main()
{

float area,radius,pi=3.14;

printf("Enter the radius of a circle : ");
scanf("%f",&radius);

area = pi * radius * radius;

printf("Area of Circle is %f\n",area);

}


Video




Friday, 13 December 2019

Write a c program to find whether a number odd or even


Code


#include<stdio.h>

void main()
{
int a;
printf("Enter a number ");
scanf("%d",&a);

if(a%2==0)

  printf("The %d is even number\n",a);

else

  printf("The %d is odd number\n",a);

}

Video





Monday, 9 December 2019

Write a C program for to find largest among three numbers


#include<stdio.h>

void main()
{

int x,y,z;

printf("Enter three numbers : ");
scanf("%d,%d,%d",&x,&y,&z);

if((x>y) && (x>z))
{
printf("The greater value is %d\n",x);
}
else if(y>z)
{
printf("The greater value is %d\n",y);
}
else
{
printf("The greater value is %d\n",z);
}

}







Monday, 2 December 2019

Write a C program for Arithmetic Operations



Arithmetic Operators: These are used to perform arithmetic/mathematical operations on operands. 


  • Addition: The ‘+’ operator adds two operands. For example, x+y.
  • Subtraction: The ‘-‘ operator subtracts two operands. For example, x-y.
  • Multiplication: The ‘*’ operator multiplies two operands. For example, x*y.
  • Division: The ‘/’ operator divides the first operand by the second. For example, x/y.
  • Modulus: The ‘%’ operator returns the remainder when first operand is divided by the second. For example, x%y.


Program

#include<stdio.h>

void main()
{

int a,b,c,d,f,g,h;


printf("Enter first number ");
scanf("%d",&a);
printf("Enter Second number ");
scanf("%d",&b);

c=a+b;
printf("Sum %d ",c);

d=a-b;
printf("\nDifference %d ",d);

f=a*b;
printf("\nProduct %d ",f);

g=a/b;
printf("\nDiv %d ",g);

h=a%b;
printf("\nMod %d \n",h);



}