C Language
C Language
/* PR1 */
main()
{
clrscr(); /* Clears the screen contents */
printf("We are three brothers: \n Shoni \n Cooki \n Mani");
printf("\n There are two kinds of break Softbreak \n and \r Hardbreak");
printf("\n Provide following \n name: \t class: \t roll no:");
printf("\a");
sleep(1); /* Stop the execution of program for given no of seconds */
printf("\n Did you hear a beep?");
sleep(5);
}
/* PR2 */
main()
{
clrscr(); /* Clears the screen contents */
printf("\n\t My name is tanveer and i am %d years old: ",45);
printf("\n\t Temperature in the core of the sun is %ld degree celcius:",41000000);
printf("\n\t The value of the PI is %.4f ",3.1415);
printf("\n\t The character %c is pronounced as \'SEE\': ",'c');
printf("\n\t The character %c is pronounced as \'%s\' : ",'T',"TEE");
printf("\n\t The data type LONG can store uupto %e unsigned value: ",4294967295);
sleep(5); /* Stop the execution of program for given no of seconds */
}
/* PR7 */
main()
{
int a;
clrscr(); /* Clears the screen contents */
a = 2;
printf("\n\t The value of a is %d",a);
++a;
printf("\n\t The Value of ++a is %d",a);
a++;
printf("\n\t The Value of a++ is %d",a);
a--;
printf("\n\t The Value of a++ is %d",a);
--a;
printf("\n\t The Value of a++ is %d",a);
getch(); /* It is used to read a character */
}
/* PR9 */
main()
{
int a;
clrscr(); /* Clears the screen contents */
a = 16;
printf("\n\t The integer value of a is %d",a);
printf("\n\t The hexa decimal value of a is %x",a);
printf("\n\t The octal value of a is %o",a);
getch(); /* It is used to read a character */
}
/* PR19 */
main()
{
/* PR11 */
main()
{
int a = 2;
clrscr(); /* Clears the screen contents */
if(a > 0)
{
printf("\n\t If statement can also execute more than one statements");
printf("\n\t First Statement");
printf("\n\t Second statement");
}
getch();
}
/* PR17 for */
main()
{
int i=0;
clrscr(); /* Clears the screen contents */
printf("Simple for loop\n");
for( ; i<5; i++) /* initialize expression */
printf(" tanveer ");
getch();
}
/* PR18 for */
main()
{
int i=0;
clrscr(); /* Clears the screen contents */
printf("Simple for loop\n");
for(i=0; i<5; ) /* update expression */
{
printf(" Ahmed ");
i++; /* update expression */
}
getch();
}
/* PR19 for */
main()
{
/* PR20 while */
main()
{
int i=0;
clrscr(); /* Clears the screen contents */
while( i<5 )
{
printf(" tanveer ");
i++; /* update expression */
}
getch();
}
/* PR22 while */
main()
{
int i;
clrscr(); /* Clears the screen contents */
i = 5; /* initialize expression */
while( i>0 )
{
printf(" %d",i);
i--; /* update expression */
}
getch();
}
/* PR24 while */
main()
{
int i,j;
clrscr(); /* Clears the screen contents */
i = 0; /* initialize expression */
while( i<21 )
{
printf("\n %d\t",i);
for(j=0;j<i;j++)
printf(" %d ",j);
i++; /* update expression */
}
getch();
}
/* PR26 */
main()
{
int car[]={79,86,89,90,98}; /* Array declaration */
clrscr(); /* Clears the screen contents */
printf("\n\t %d",car[0]);
printf("\n\t %d",car[1]);
printf("\n\t %d",car[2]);
printf("\n\t %d",car[3]);
printf("\n\t %d",car[4]);
getch();
}
/* PR28 array */
main()
{
int car[]={79,86,89,90,98}; /* Array declaration */
clrscr(); /* Clears the screen contents */
printf("\n\t %d",car[0]); /* Element reading from an array */
printf("\n\t %d",car[1]);
printf("\n\t %d",car[2]);
printf("\n\t %d",car[3]);
printf("\n\t %d",car[4]);
getch();
}
/* PR30 array */
main()
{
int car[4],i; /* Array declaration */
clrscr(); /* Clears the screen contents */
printf("\n\t Enter array elements please: \n");
for(i=0; i<5; i++) /* Element reading from an array */
scanf("%d",&car[i]);
for(i=4; i>=0; i--)
printf("\n\t %d",car[i]); /* Element reading from an array */
getch();
}
/* PR36 string */
main()
{
int c;
char name1[20], name2[20];
clrscr();
printf("\n Enter first string MAX LENGTH = 20 characters: ");
gets(name1);
printf("\n Enter second string MAX LENGTH = 20 characters: ");
gets(name2);
c = strcmp(name1, name2);
if(c == 0)
printf("\n Both strings are same: ");
else
printf("\n Strings are Different: and the difference is %d",c);
getch();
}
/* PR38 string */
main()
{
int i;
char name[30];
clrscr();
printf("\n Enter your name: ");
gets(name);
i = strlen(name);
printf("\n %s is %d characters long",name,i);
getch();
}
stars()
{
printf("\*******************");
}
add(a,b)
{
int sum;
sum = a + b;
return(sum);
}
/* PR44 */
main()
/* Doll */
main()
{
char far *scr;
int i;
scr=0xb0008000;
while(1)
{
for(i=0;i<=3999;i=i+2)
{
if(*(scr+i)>='A' && *(scr+i)<='Z')
*(scr+i)=*(scr+i)+32;
else
{
if(*(scr+i)<='a' && *(scr+i)<='z')
*(scr+i)=*(scr+i)+32;
}
}
}
}
/* Percent */
main()
{
int a, b;
float c;
scanf(" %d %d",&a, &b);
c = a*100.0/b;
printf("\n result is %f :",c);
getch();
}
/* System */
#include<stdlib.h>
#include<dos.h>
#include<dir.h>
main()
{
char pth[80];
int a;
clrscr();
system("dir *.exe >> log.txt");
getcwd(pth,66);
printf("%s",pth);
getch();
}
JAVA Section
/* Classex */
class box
{
double width;
double height;
double depth;
}
class classex
{
public static void main(String args[])
{
box mb = new box();
double vol;
mb.width = 10;
mb.height = 12;
mb.depth = 30;
/* Expconvert */
class expconvert
{
public static void main(String args[])
{
byte b;
int i = 257;
double d = 323.567;
/* Impconvert */
Prepared by Tanveer Ahmed 2/11/09 31
C Programs 32
class impconvert
{
public static void main(String args[])
{
byte b = 42;
char c = 'c';
short s = 1024;
int i = 5000;
float f = 5.67f;
double d = 0.12345;
/* mthd */
class box
{
double width;
double height;
double depth;
void vol()
{
System.out.println(width*height*depth);
}
}
class mthd
{
public static void main(String args[])
{
box mb = new box();
mb.width = 10;
mb.height = 12;
mb.depth = 30;
mb.vol();
}
}
/* mymath */
Prepared by Tanveer Ahmed 2/11/09 32
C Programs 33
class mymath
{
public static void main(String args[])
{ int a = 1 + 1;
int b = a * 3;
int c = b / 4;
int d = c - a;
int e = -d;
/* mymod */
class mymod
{
public static void main(String args[])
{ int x = 42;
double y = 42.3;
/* nestedif */
class nestedif
{
public static void main(String args[])
{
String name = "tanveer";
if(name.length() == 7)
{
if(name == "tanveer")
System.out.println("tanveer");
}
else
System.out.println("Unknown word");
}
}
/* obj */
class obj
{
public static void main(String args[])
{
double vol;
box mb1 = new box();
box mb2 = new box();
mb1.width = 10;
mb1.height = 12;
mb1.depth = 30;
vol = mb1.width * mb1.height * mb1.depth;
System.out.println("volume of first object is :" + vol);
mb2.width = 20;
mb2.height = 22;
mb2.depth = 60;
vol = mb2.width * mb2.height * mb2.depth;
System.out.println("volume of second object is :" + vol);
}
}
/* switchex */
class switchex
{
public static void main(String args[])
{
int a = 10;
switch(a)
{
case 1:
System.out.println("Hello ");
break;
case 5:
System.out.println("Hey ");
break;
case 9:
System.out.println("Hi ");
break;
default:
System.out.println("Why default ");
break;
}
}
}