Assignment 3 FY-A 19

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

{\rtf1\ansi\ansicpg1252\cocoartf2580

\cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
{\*\expandedcolortbl;;}
\margl1440\margr1440\vieww11520\viewh8400\viewkind0
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\
tx8640\pardirnatural\partightenfactor0

\f0\fs24 \cf0 1\
Name: Aditya Hambir\
Roll no:19 Div : A\
Program Number : 3A\
Program Title : Implement Linear search method using array\
\
#include <stdio.h>\
int main()\
\{\
int array[100], search, c, n;\
\
printf("Enter number of elements in array\\n");\
scanf("%d", &n);\
\
printf("Enter %d integer(s)\\n", n);\
\
for (c = 0; c < n; c++)\
scanf("%d", &array[c]);\
\
printf("Enter a number to search\\n");\
scanf("%d", &search);\
\
for (c = 0; c < n; c++)\
\{\
if (array[c] == search) /* If required element is found */\
\{\
printf("%d is present at location %d.\\n", search, c+1);\
break;\
\}\
\}\
if (c == n)\
printf("%d isn't present in the array.\\n", search);\
\
return 0;\
\}\
\
Enter number of elements in array\
5\
Enter 5 integer(s)\
2 5 6 8 1\
Enter a number to search\
8\
8 is present at location 4.\
\
\
...Program finished with exit code 0\
Press ENTER to exit console.\
/=================================================================================\
2\
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\
tx8640\pardirnatural\partightenfactor0
\cf0 Name: Aditya Hambir\
Roll no:19 Div : A\
Program Number : 3B\
Program Title : Program to separate odd and even integers in separate arrays\
\
#include <stdio.h>\
\
void main()\
\{\
int arr1[10], arr2[10], arr3[10];\
int i,j=0,k=0,n;\
\
\
printf("\\n\\nSeparate odd and even integers in separate arrays:\\n");\
printf("------------------------------------------------------\\n"); \
\
printf("Input the number of elements to be stored in the array :");\
scanf("%d",&n);\
\
printf("Input %d elements in the array :\\n",n);\
for(i=0;i<n;i++)\
\{\
printf("element - %d : ",i);\
scanf("%d",&arr1[i]);\
\}\
\
for(i=0;i<n;i++)\
\{\
if (arr1[i]%2 == 0)\
\{\
arr2[j] = arr1[i];\
j++;\
\}\
else\
\{\
arr3[k] = arr1[i];\
k++;\
\}\
\}\
\
printf("\\nThe Even elements are : \\n");\
for(i=0;i<j;i++)\
\{\
printf("%d ",arr2[i]);\
\}\
\
printf("\\nThe Odd elements are :\\n");\
for(i=0;i<k;i++)\
\{\
printf("%d ", arr3[i]);\
\}\
printf("\\n\\n"); \
\}\
\
Separate odd and even integers in separate arrays:\
Input the number of elements to be stored in the array :6\
Input 6 elements in the array :\
element - 0 : 10 9 67 88 34 10\
element - 1 : element - 2 : element - 3 : element - 4 : element - 5 : \
The Even elements are : \
10 88 34 10 \
The Odd elements are :\
9 67 \
\
\
\
...Program finished with exit code 0\
Press ENTER to exit console.\
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\
tx8640\pardirnatural\partightenfactor0
\cf0 \
}

You might also like