Friday, March 31, 2017

The alert, confirm, and prompt boxes



Lets look at them in detail. The first one is:

window.<a href="#">alert</a>()


This command pops up a message box displaying whatever you put in it. For example:


<body>
<script type="text/javascript"> 
window.a<href="#" >alert</a>("My name is Laxman Poudel")
</script>
</body>


As you can see, whatever you put inside the quotation marks, it will display it.
The second one is:

window.<a href="#">confirm</a>()

Confirm is used to confirm a user about certain action, and decide between two choices depending on what the user chooses.

<script type="text/javascript">
var x=window.<a href="#">confirm</a>("Are you sure you are ok?")
if (x)
window.alert("Good!")
else
window.alert("Too bad")
</script>
There are several concepts that are new here, and I'll go over them. First of all, "var x=" is a variable declaration; it declares a variable ("x" in this case) that will store the result of the confirm box. All variables are created this way. x will get the result, namely, "true" or "false". Then we use a "if else" statement to give the script the ability to choose between two paths, depending on this result. If the result is true (the user clicked "ok"), "good" is alerted. If the result is false (the user clicked "cancel"), "Too bad" is alerted instead. (For all those interested, variable x is called a Boolean variable, since it can only contain either a value of "true" or "false").

The third one is:
window.prompt()

Prompt is used to allow a user to enter something, and do something with that info:

<script type="text/javascript">
var y=window.prompt("please enter your name")
window.alert(y)
</script>





WAP IN C TO FIND WHETHER THE ENTERED NUMBER IS ARMSTRONG NUMBER OR NOT


#include <stdio.h>
int main()
{     /*PROGRAM BY LAXMAN POUDEL*/
    int number, originalNumber, remainder, result = 0;

    printf("Enter a three digit integer: ");
    scanf("%d", &number);

    originalNumber = number;

    while (originalNumber != 0)
    {
        remainder = originalNumber%10;
        result += remainder*remainder*remainder;
        originalNumber /= 10;
    }

    if(result == number)
        printf("%d is an Armstrong number.",number);
    else
        printf("%d is not an Armstrong number.",number);

    return 0;           OUTPUT WINDOW
}                           

WAP IN C TO FIND THE SUM OF TWO MATRICES USING ARRAY 




#include <stdio.h>
 
int main()
{
   int m, n, c, d, first[10][10], second[10][10], sum[10][10];
 
   printf("Enter the number of rows and columns of matrix\n");
   scanf("%d%d", &m, &n);
   printf("Enter the elements of first matrix\n");
 
   for (c = 0; c < m; c++)
      for (d = 0; d < n; d++)
         scanf("%d", &first[c][d]);
 
   printf("Enter the elements of second matrix\n");
 
   for (c = 0; c < m; c++)
      for (d = 0 ; d < n; d++)
            scanf("%d", &second[c][d]);
 
   printf("Sum of entered matrices:-\n");
 
   for (c = 0; c < m; c++) {
      for (d = 0 ; d < n; d++) {
         sum[c][d] = first[c][d] + second[c][d];
         printf("%d\t", sum[c][d]);
      }
      printf("\n");
   }
 
   return 0;
}

OUTPUT WINDOW



WAP IN C TO SWAP TWO NUMBERS USING THIRD VARIABLE

#include<stdio.h>
#include<conio.h>
/* PROGRAM BY LAXMAN POUDEL*/
int main()                                      OUTPUT WINDOW
{ int a,b,temp; printf("enter two values\n"); printf("\na = "); scanf("%d",&a); printf("\nb = "); scanf("%d",&b); temp=a; a=b; b=temp; printf("\na = %d\tb = %d ", a, b); getch(); }