Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
674 views

Programming Assignment No.4

This document contains the answers to multiple programming assignments. 1. The answers provide code snippets and output for programs that process arrays, including: swapping odd and even elements, copying an array in reverse order, and calculating the binary equivalent of a number. 2. When too many values are put into an array, it can cause system errors. When an array is passed as an argument to a function, the address of the array is passed rather than the values.
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
674 views

Programming Assignment No.4

This document contains the answers to multiple programming assignments. 1. The answers provide code snippets and output for programs that process arrays, including: swapping odd and even elements, copying an array in reverse order, and calculating the binary equivalent of a number. 2. When too many values are put into an array, it can cause system errors. When an array is passed as an argument to a function, the address of the array is passed rather than the values.
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

Assignment No.

4
Ans 1: Output is
200 100
Ans 2: Output is
Declarations should be at the top and it does not have the
particular dimension of the array.
Ans 3: No error
Ans 4: int num !" is the si#e of the array
$nt !" %11 is a element of the particular array
Ans !: &' pro(ram to find out ho) many numbers are positive*
ne(ative* odd and even in array'&
+include ,stdio.h-
+include ,conio.h-
void main . /
0
int num 2!"* 1* ne(%0* pos%0* odd%0* eve%01
clrscr . /1
printf .2enter the values3/1
for .i%01 i,%241 i44/
0
scanf .25d3* 6numi"/1
7
for .i%01 i,%241i44/
0
if .numi" ,0/8
printf .29n ne(ative numbers%5d3* ne(/:
printf .29n positive numbers%5d3* pos/1
7
for .i%01 i,%24: i44/
0
if .numi" 52%%0/8
printf .29n even numbers%5d3* eve/:
printf .29n odd numbers%5d3* odd/1
(etch . /1
7
7
Ans :: &' pro(ram to interchan(e the odd and even elements of the
array'&
+include ,stdio.h-
+include ,conio.h-
void main . /
0
int num"%01*2*3*4*!*:*;*<*=*10*11*12*13*1471
int i* m1
clrscr . /1
for .i%01 i,%131 i42/
0
m%numi"1
num i" %num i41"1
num i41" %m1
7
for .i%01 i,%131 i44/
printf .25d3* num i"/1
(etch . /1
7
Ans ;: output is
0
20
0
40
!
Ans <: Output is
;
=
11
13
1!
Ans =: Output is
2! 4

Ans 10: &' pro(ram to copy one array to another array in reverse
order '&
+include ,stdio.h-
+include ,conio.h-
void main . /
0
int arr1 :"* arr2 :"* $* >1
clrscr . /1
printf .29n enter the elements of array3/1
for .i%01 i,%!: i44/
0
scanf .25d3* 6arr1 i"/1
7
for .i%01 i,%!1 i44* >??/
arr2 >" % arr1 i"1
printf .29n reverse order 2/1
for .i%01 i,%!1 i44/
0
printf .29n 5d 2* arr2 i" /1
(etch . /1
7
7
Ans 11: output is
2! 4
Ans 12: Output is
1: 2
Ans 13: Output is
100: 100: 100:
13.!00000 13.!00000 13.!00000 13.!00000 13.!00000
Ans 14: &'pro(ram to calculate binary e@uivalent of a number '&
+include ,stdio.h-
+include ,conio.h-
+include ,math.h-
void main . /
0
int num* s* i%0* t1
bin % 01
clrscr . /1
printf .2enter the number3/1
scanf .25d3* 6num/1
s%num1
)hile .sA %0/
0
t%s521
s%s&21
bin% .po) .:* i/'t/ 4bin1
i441
7
printf .2binary e@uivalent is 5d3* num* bin/1
(etch . /1
7
Ans 1!: Bhen )e try to put so many values into an array* it can
lead to system malfunction and )hen )e pass an array as an
ar(ument to a function* address of the array (ets passed.

You might also like