Beruflich Dokumente
Kultur Dokumente
#include<stdio.h>
main()
{
int n1,n2,temp;
n1=10;
n2=15;
printf("Before swap value of n1 and n2=%d,%d",n1,n2);
//swap two value
temp=n1;
n1=n2;
n2=temp;
printf("\n After swap value of n1 and n2=%d,%d",n1,n2);
}
void main()
{
int array[20];
int i, low, mid, high, key, size;
printf("Enter the size of an array\n");
scanf("%d", &size);
printf("Enter the array elements\n");
for (i = 0; i < size; i++)
{
scanf("%d", &array[i]);
}
}
}
//Decimal to binary conversion using function
#include<math.h>
#include<conio.h>
long tobinary(int n)
{
int i=0,r;
long b=0;
while(n)
{
r=n%2;
n=n/2;
b=(long)((pow(10,i)*r))+b;
i++;
}
return b;
}
int main()
{
int n;
printf("Enter a number : ");
scanf("%d",&n);
printf("Binary of %d is %ld",n,tobinary(n));
getch();
}
String operation
#include<stdio.h>
#include<string.h>
int main()
{
char str[100],temp[100];
printf("Enter a string : ");
gets(str);
printf("Length of %s is %d\n",str,strlen(str));
strcpy(temp,str);
printf("Reverse of %s is %s\n",str,strrev(temp));
strcpy(temp,str);
printf("Upper case of %s is %s\n",str,strupr(temp));
printf("Lower case of %s is %s\n",str,strlwr(temp));
getch();
}
Prime number
#include<stdio.h>
int main()
{
int n,d,flag;
printf("Enter a number : ");
scanf("%d",&n);
d=2;flag=0;
while(d<n)
{
if(n%d==0)
{
flag=1;
break;
}
d++;
}
if(flag)
printf("%d is not a prime number",n);
else
printf("%d is a prime number",n);
getch();
}
/*
WAP to get a number and
check the number to be palindrome.
*/
#include<stdio.h>
int main()
{
int n,m,rev=0,d;
printf("Enter a number : ");
scanf("%d",&n);
m=n;
while(n)
{
d=n%10;
rev=rev*10+d;
n=n/10;
}
if(m==rev)
printf("%d is a palindrome",m);
else
printf("%d is not a palindrome",m);
getch();
}
/*
Write a program to check as number to be
Armstrong number
*/
int main()
{
int n,m,d,sum=0;
printf("Enter a number : ");
scanf("%d",&n);
m=n;
while(n)
{
d=n%10;
sum=sum+d*d*d;
n=n/10;
}
if(m==sum)
printf("%d is an Armstrong Number",m);
else
printf("%d is not an Armstrong Number",m);
getch();
}
/*
Write a program to get a number and
print sum of its digits using while loop
*/
#include<stdio.h>
#include<conio.h>
int main()
{
int num,d,sum=0;
printf("Enter a number : ");
scanf("%d",&num);
while(num)
{
d=num%10;
sum=sum+d;
num=num/10;
}
printf("Sum of digits is : %d",sum);
getch();
}
int factorial(int n)
{
if(n==2)
return 2;
else
return n*factorial(n-1);
}
int main()
{
int n;
printf("Enter a number : ");
scanf("%d",&n);
printf("Factorial of %d is %d",n,factorial(n));
getch();
}
int fib(int n)
{
if(n==1)
return 0;
else if(n==2)
return 1;
else
return fib(n-1)+fib(n-2);
}
int main()
{
int num,i;
printf("Numbers in series : ");
scanf("%d",&num);
for(i=1;i<=num;i++)
printf("%d ",fib(i));
getch();
}
#define N 10
int main()
{
int ar[N],i,j,temp;
printf("Enter %d numbers : ",N);
for(i=0;i<N;i++)
scanf("%d",&ar[i]);
for(i=0;i<N;i++)
for(j=i+1;j<N;j++)
{
if(ar[i]>ar[j])
{
temp=ar[i];
ar[i]=ar[j];
ar[j]=temp;
}
}
printf("Sorted numbers are : ");
for(i=0;i<N;i++)
printf("%d ",ar[i]);
getch();
}
Hint: First look the NULL character \0 then start printing from the
backside to print reverse of a string. Use putchar() function to write
a character o screen rather than printf("%c")
int main()
{
char str[100]; int i=0;
printf("Enter a string : "); gets(str);
while(str[i]!='\0')
{
i++;
}
printf("Reverse of %s is : ",str);
for(i=i-1;i>=0;i--)
putchar(str[i]);
getch();
}
Java script program-Calculator
<html>
<head>
<title>Web App for Simple Interest Calculation</title>
<script>
function calculate()
{
p = document.getElementById("p").value;
n = document.getElementById("n").value;
r = document.getElementById("r").value;
result = document.getElementById("result");
result.innerHTML = "The interest is " + (p*n*r/100);
}
</script>
</head>
<body>
<h1>Simple Interest Calculation</h1>
Amount: <input id="p"><br/>
Rate: <input id="r"><br/>
No. of Years: <input id="n"><br/>
<button onclick="calculate()">Calculate</button>
<p id="result"></p>
</body>
</html>
Load image
<!DOCTYPE html>
<html>
<body>
<img src="w3html.gif" onload="loadImage()" width="100"
height="132">
<script>
function loadImage() {
alert("Image is loaded");
}
</script>
</body>
</html>
Viva Voice
1. local variable
2. global variable
3. subscript variable/array variable
4. reference type variable
5. keyword
6. constants
7. infinite loops
8. Array advantage
9. Pointer
10. Function
11. Html basic tags
12. Java script features
13. Tcp/ip model
14. Router and bridge
15. Network cable
16. Lan and wan