PHP Code to find the reverse of a number

Description


This program finds the reverse of a number using do while loop.

code


<html>
<head>
<title>REVERSE OF A NUMBER</title>
</head>
<body>
<font size=7>REVERSE OF A NUMBER</font>
<form action=reverse.php method="post">
ENTER NUMBER:<input type="text" name="t1">
<br><br>
<input type="submit" value="REVERSE">
<?php
if(isset($_POST["t1"]))
{
$n=$_POST["t1"];
$rev=0;
do
{
$t=$n%10;
$rev=($rev*10)+$t;
$n=floor($n/10);
}
while($n>0);
echo 'Reverse is ';
echo $rev;
}
?>
</form>
</body>
</html>

Output



PHP Program to find the reverse of a number

c program to print 1 in diagonal positions of a matrix


Explanation of the program



This program reads a matrix and replaces the value stored in the diagonal positions with 1. The program uses two for loops, with loop variables i and j. The diagonal positions has the same value for i and j. If i and j equals, a 1 is stored at the position a[i][j].

Program



#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a[50][50]={0},i,j,r,c;
printf("Enter the row and column value:\n\n");
scanf("%d%d",&r,&c);
printf("\nEnter the elements:\n\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&a[i][j]);
}}
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
if(i==j)
{
a[i][j]=1;
}}}
printf("\nNew matrix:\n");
for(i=0;i<r;i++)
{
printf("\n");
for(j=0;j<c;j++)
{
printf("%d\t",a[i][j]);
}}
getch();
}


Output



c program to change diagonal elements of a matrix to 1
C program to change diagonal elements of a matrix to 1