Sunday, April 17, 2011

Lab8


1. WAP to read a string from keyboard until a enter key and count vowels, consonants, semicolons.
Source Code:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char inputstring[200];
int len,i=0,countVowel=0,countCons=0,countComma=0,countSemi=0;
clrscr();
printf("\nEnter some test:\n");
gets(inputstring);
len=strlen(inputstring);
for(i=0;i<len;i++)
{
if(inputstring[i]=='a' || inputstring[i]=='e'|| inputstring[i]=='i'||inputstring[i]=='o'||inputstring[i]=='u')
countVowel++;
else if(inputstring[i]==',')
countComma++;
else if(inputstring[i]==';')
countSemi++;
else
countCons++;
}
printf("\nThe numbers of vowels\t%d",countVowel);
printf("\nThe numbers of Consonants\t%d",countCons);
printf("\nThe numbers of Commas\t%d",countComma);
printf("\nThe numbers of Semicolon\t%d",countSemi);
getch();
}

Output:
Enter some test:
My name Is Sujan Kunwar. I am Computer Engineer, Web Designer, Hardware technician, etc;

The numbers of vowels   25
The numbers of Consonants       59
The numbers of Commas   3
The numbers of Semicolon        1













  1. WAP to define 3 variables of types char, float, int and display memory address reserved by defined variable. Also initialize three pointers with these variables.
Source Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int a=1;
float b=2.5;
char c='n';
int *p;
float *q;
char *r;
p=&a;
q=&b;
r=&c;
printf("\nThe address of a is %u",p);
printf("\nThe address if b is %u",q);
printf("\nThe address if c is %u",r);
getch();
}
Output:
The address of a is 65524
The address if b is 65520
The address if c is 65519


  1. WAP to find sum of all elements of one-dimensional array using pointer.
Source Code:
#include<stdio.h>
#include<conio.h>
#include<malloc.h>
void main()
{
int *a,i,n,result=0;
clrscr();
printf("Enter the no. of elements to be stored in array :");
scanf("%d",&n);
a=(int *)malloc(n*sizeof(int));//allocating space
printf("\nEnter the elements :");
for(i=0;i<n;i++)
scanf("%d",a+i);
for(i=0;i<n;i++)
result+=*(a+i);
printf("\nThe sum of elements in array is :%d",result);
free(a);//deallocating space
getch();
}
Output:
Enter the no. of elements to be stored in array :4
Enter the elements :2 4 6 8
The sum of elements in array is :20
  1. WAP to sort N numbers (use memory allocation)
Source Code:
#include<stdio.h>
#include<conio.h>
void get(float*,int);
void display(float*,int);
void sort(float*,int);
int main(void)
{
int n;
float *num;
clrscr();
printf("\nEnter numbers of elements in an array:\t");
scanf("%d",&n);
num=(float*)malloc(n*sizeof(float));
get(num,n);
sort(num,n);
display(num,n);
getch();
return 0;
}
void get(float*nums,int n)
{
int i;
printf("\nEnter %d numbers:",n);
for(i=0;i<n;i++)
scanf("%f",nums+i);
}
void sort(float*nums,int n)
{
float temp;
int i,j;
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(*(nums+j)>*(nums+j))
{
temp=*(nums+i);
*(nums+i)=*(nums+j);
*(nums+j)=temp;
}
}
}
}
void display(float *nums,int n)
{
int i;
printf("\nThe numbers in ascending order:\n");
for(i=0;i<n;i++)
printf("\t%.2f",*(nums+i));
}
Output:
Enter numbers of elements in an array:  8
Enter 8 numbers:12 56 7 90 30 6 54 65
The numbers in ascending order:
12.00   56.00   7.00    90.00   30.00   6.00    54.00   65.00

  1. WAP to read n numbers in array using pointer concept and display the smallest.
Source Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[20],i,n;
int *ptr,*low;
clrscr();
printf("\nEnter the value of n:\t");
scanf("%d",&n);
printf("\nEnter the %d interger value:\t",n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
ptr=a;
low=&a[0];
for(i=0;i<n;i++)
{
if(*ptr<*low)
{
low=ptr;
}
ptr++;
}
printf("\nElements of an array:\t");
for(i=0;i<n;i++)
{
printf("%d\t",a[i]);
}
printf("\nSmallest value is %d\t",*low);
getch();
}
Output:-
Enter the value of n:   5
Enter the 5 integer value:     6 8 10 9 15
Elements of an array:   6       8       10      9       15
Smallest value is 6







  1. Discuss the following output
#include<stdio.h>
#include<conio.h>
void main()
{
int *x;
int a=20;
*x=10;
*x+=a;
printf("x=%u",x);
printf("\n*x=%d",*x);
printf("\nAddress of x =%u",&x);
getch();
}
Output:
x=36823
*x=30
Address of x =65524


Thursday, February 17, 2011

workshop

Lab1
Objective:-
To make a dust collector from the given GI sheet (26 gauge thick), according to the given structure and dimensions.


Related Theory:-
Dust Collector:-
Designed to handle heavy dust loads, a dust collector system consists of a blower, dust filter, a filter-cleaning system, and a dust receptacle or dust removal system. It is distinguished from air cleaners which use disposable filters to remove dust. A dust collection system is an accessory found in commercial and home woodworking shops used to collect wood dust, chips and shavings at the point of origin. Dust collection systems work on the same principle as central vacuum systems in homes: A fixed motor creates suction, which is distributed through the space via a network of rigid ducting and flexible hoses to the point of use

Layout Diagram of Dust Collector
























Surface development of dust collector:-
i. All dimensions are in mm.
ii. Tolerance -± 1mm
iii. Symbols:-




Requirement Instruments:-
i. Steel scale
ii. Scriber
iii. Tri-Square
iv. Shear
v. Bench vice
vi. Mallet
vii. Metal hammer
viii. Center punch
ix. Arivil
x. Drill Bit
xi. Drilling Machine

Uses of Operations:
i. Measuring and marking
ii. Shearing
iii. Bending
iv. Folding
v. Punching
vi. Drilling
vii. Riveting

Personal Safety:
a) Put on appropriate uniform
b) Do not wear neck tic while working with the machine
c) Do not keep long hair
d) Do not wear rings
e) Put on safety shoes
f) Put on safety glass while grinding & welding
g) Keep work place clean
h) Do not split oil on the floor
i) Do not run in the work place
j) Do not talk & joke while working
k) Do not talk & joke while working
l) Do not play with the tools
m) Do not throw chips, hairs or wire pieces on the floor
n) Detective and damage tools should never be used
o) Always held the tools on materials firmly
p) Do not keep pointed or sharp edged tools in the pocket


Machine, tools, equipment safety:
a) Do not operate the machine unless you are confident about its operations
b) Keep the tools or equipments in its appropriate place
c) Handle the tools and equipment property
d) Use appropriate tools for specific job
e) Never play with tools
f) Always protect the tools from rusting


Product or job safety:
a) Grip the work piece firmly on the machines
b) Use appropriate tools for specific job
c) Do not apply over force on the job


General safety:
a) Do not touch any things about which you are not familiar
b) Do not operate any machines with out instructions
c) Do not start any machines with out instructions
d) Do not smoke or make fire near combinatible things
e) Keep first aid box in the work shop for emergency
f) Never used damaged tools
g) There should be adequate lighting and ventilation in the work place
h) Lift the weight with caution

Conclusion:-
Hence, we have to made dust collector successfully.




Lab2
Objective:-
To make a bottle opener from the given mild steel plate, according to the given structure and dimensions.

Related Theory:-
A bottle opener is a device that enables the removal of metal bottle caps from bottles. More generally, it might be thought to include corkscrews used to remove cork or plastic stoppers from wine bottles.
A metal bottle cap is affixed to the rim of the neck of a bottle by being pleated or ruffled around the rim. A bottle opener is a specialized lever inserted beneath the pleated metalwork, which uses a point on the bottle cap as a fulcrum on which to pivot.

Layout Diagram of Bottle Opener




















Surface development of dust collector:-
i. All dimensions are in mm.
ii. Tolerance -± 1mm
iii. Symbols:-

Requirement Instruments:-
i. Steel scale
ii. Scriber
iii. Tri-Square
iv. Shear
v. Bench vice
vi. Mallet
vii. Metal hammer
viii. Center punch
ix. Arivil
x. Drill Bit
xi. Drilling Machine
Operations:-
i. Measuring and Marking
ii. Sawing
iii. Filling
iv. Punching
v. Drilling
vi. Finishing


Procedure:-
Measuring
The first step of making bottle opener is measuring.

Marking:-
The second step for making bottle opener is marking. Marking is done when completing measuring.

Sawing:-
Sawing is the third step for making bottle opener. Sawing operation (Hack saw) is used for sawing all metal except hardened steel.

Filling:-
Filling is done when completing the sawing. To remove metal piece from the metal surface into small piece filling operations is used. It cuts all metal except hardened steel.

Punching:-
Punching is performing by the help of center punch.


Drilling:-
After punching the bottle opener drilling operation is perform by the help of drilling machine.


Finishing:-
When completing drilling the bottle opener we perform finishing operation.













Safety Measure
Personal Safety:
a) Put on appropriate uniform
b) Do not wear neck tic while working with the machine
c) Do not keep long hair
d) Do not wear rings
e) Put on safety shoes
f) Put on safety glass while grinding & welding
g) Keep work place clean
h) Do not split oil on the floor
i) Do not run in the work place
j) Do not talk & joke while working
k) Do not talk & joke while working
l) Do not play with the tools
m) Do not throw chips, hairs or wire pieces on the floor
n) Detective and damage tools should never be used
o) Always held the tools on materials firmly
p) Do not keep pointed or sharp edged tools in the pocket


Machine, tools, equipment safety:
a) Do not operate the machine unless you are confident about its operations
b) Keep the tools or equipments in its appropriate place
c) Handle the tools and equipment property
d) Use appropriate tools for specific job
e) Never play with tools
f) Always protect the tools from rusting


Product or job safety:
a) Grip the work piece firmly on the machines
b) Use appropriate tools for specific job
c) Do not apply over force on the job


General safety:
a) Do not touch any things about which you are not familiar
b) Do not operate any machines with out instructions
c) Do not start any machines with out instructions
d) Do not smoke or make fire near combinatible things
e) Keep first aid box in the work shop for emergency
f) Never used damaged tools
g) There should be adequate lighting and ventilation in the work place
h) Lift the weight with caution

Conclusion:-
Hence, we have to made bottle opener successfully.




Lab3
To make nut and bolt from the given metal.

Related Theory:-
A nut is a type of hardware fastener with a threaded hole. Nuts are almost always used opposite a mating bolt to fasten a stack of parts together. The two partners are kept together by a combination of their threads' friction, a slight stretch of the bolt, and compression of the parts. In applications where vibration or rotation may work a nut loose, various locking mechanisms may be employed: Adhesives, safety pins or lockwire, nylon inserts, or slightly oval-shaped threads. A screw, or bolt, is a type of fastener characterized by a helical ridge, known as an external thread or just thread, wrapped around a cylinder. Some screw threads are designed to mate with a complementary thread, known as an internal thread, often in the form of a nut or an object that has the internal thread formed into it.

Layout Diagram of nut and bolt




















Surface development of nut and bolt:-
i. All dimensions are in mm.
ii. Tolerance -± 1mm
iii. Symbols:-
Requirement Instruments:-
i. Lathe Machine
ii. File
iii. Tap and Tap handle
iv. Die and die handle
v. Drill bit and drilling Machine.


Procedure:-
Measuring
The first step of making nut-bolt is measuring.

Marking:-
The second step for making nut-bolt is marking. Marking is done when completing measuring.

Cutting:-
After complete measuring and marking cutting operation is perform for cut the metal work piece.

Turning:-
It is the process that is used to reduce the size in to from different shapes on the circular surface with the application of “Lathe Machine”.


Filing:-
It is the process of remaining metal from the metallic surface.

Drilling:-
It is the process used for making required holes on metallic surface.

Tuning:-
It is the process that is used to reduce the size on to from different shapes on the circular surface with the application of “Lathe Machine”

Tapping:-
It is the process of creating internal threads in drilled hole for example:- Tapping is done in Nut.

Dieing:-
It is the process of forming external thread on the surface of object like bolts and studs.









Safety Measure
Personal Safety:
a) Put on appropriate uniform
b) Do not wear neck tic while working with the machine
c) Do not keep long hair
d) Do not wear rings
e) Put on safety shoes
f) Put on safety glass while grinding & welding
g) Keep work place clean
h) Do not split oil on the floor
i) Do not run in the work place
j) Do not talk & joke while working
k) Do not talk & joke while working
l) Do not play with the tools
m) Do not throw chips, hairs or wire pieces on the floor
n) Detective and damage tools should never be used
o) Always held the tools on materials firmly
p) Do not keep pointed or sharp edged tools in the pocket


Machine, tools, equipment safety:
a) Do not operate the machine unless you are confident about its operations
b) Keep the tools or equipments in its appropriate place
c) Handle the tools and equipment property
d) Use appropriate tools for specific job
e) Never play with tools
f) Always protect the tools from rusting


Product or job safety:
a) Grip the work piece firmly on the machines
b) Use appropriate tools for specific job
c) Do not apply over force on the job


General safety:
a) Do not touch any things about which you are not familiar
b) Do not operate any machines with out instructions
c) Do not start any machines with out instructions
d) Do not smoke or make fire near combinatible things
e) Keep first aid box in the work shop for emergency
f) Never used damaged tools
g) There should be adequate lighting and ventilation in the work place
h) Lift the weight with caution


Conclusion:-
Hence, we have to nut -bolt successfully.

Wednesday, February 16, 2011

c_lab6

1. Create a function add () with return type as integer. Pass the argument from the main() and return the result in main and display in the main()

Source Code
#include
#include
int add(int a, int b)
{
int sum;
sum=a+b;
return sum;
}
void main()
{
int a, b, sum;
clrscr();
printf("\nEnter two numbers:\t");
scanf("%d%d",&a,&b);
sum=add(a,b);
printf("\nThe sum is \t%d",sum);
getch();
}

Programs Output:-
Enter two numbers: 25 26

The sum is 51


2. Create a function subtract () with return type void. Pass the argument from the main () and display the result in subtract().
Source Code
#include
#include
void subtract(int a, int b)
{
int sub;
sub=a-b;
printf("\nThe subtraction is \t%d",sub);
}
void main()
{
int a, b, sub;
clrscr();
printf("\nEnter two numbers:\t");
scanf("%d%d",&a,&b);
subtract(a,b);
getch();
}

Programs Output:-
Enter two numbers: 15 10

The subtraction is 5



3. Create a function multi() with return type as integer. Declare required variable and take user input. Perform multiplication & return in main()
Source Code
#include
#include
int multi(int a, int b)
{
int prod;
prod=a*b;
return prod;
}
void main()
{
int a, b, prod;
clrscr();
printf("\nEnter two numbers:\t");
scanf("%d%d",&a,&b);
prod=multi(a,b);
printf("\nThe Multiplication is \t%d",prod);
getch();
}

Program Output:-
Enter two numbers: 5 5

The Multiplication is 25


4. Create a function division() wit return type as void. Declared required variables and take user input perform division & display result in division() itself.
Program Code
#include
#include
void division(int a, int b)
{
int div;
div=a/b;
printf("\nThe Division is \t%d",div);

}
void main()
{
int a, b;
clrscr();
printf("\nEnter two numbers:\t");
scanf("%d%d",&a,&b);
division(a,b);
getch();
}


Program Output
Enter two numbers: 25 5

The Division is 5


5. Combine above question and use switch case statement in main() to call function.
Ans:



6. Write programs for factorial using recursive function.
Source Code
#include
#include
long int factorial(int n)
{
if(n==1)
return(1);
else
return(n*factorial(n-1));
}
void main()
{
int num;
clrscr();
printf("\nEnter a number:\t");
scanf("%d",&num);
printf("\nThe factorial is \t%ld",factorial(num));
getch();
}

Program Output:
Enter a number: 5

The factorial is 120


Discussion/Conclusion