×

# Q.1

     Take as input a natural number, say n. Output all subsets of {1,2,...,n}.
You cannot use functions or recursion.


# Q.2

     Write a program to read a sequence of non-zero integers till the number zero is entered and at the end display the following:
a)      the number of even and odd numbers,
b)      sum of all the numbers entered,
c)      the length and starting index (or position) of a largest subsequence of consecutive non-decreasing integers entered. Assume that the index of the numbers start from 1.

For example, if the user input is  1 -2 3 17 9 5 -10 -12 0, then the output will be:
No. of even numbers: 3
No. of odd numbers: 5
Sum of the numbers: 11
Length of largest non-decreasing subsequence: 3
Starting index: 2
Note: Do not use arrays.


Note by Rishabh Deep Singh
9 months, 1 week ago

Sort by:

i got it @Agnishom Chattopadhyay · 9 months, 1 week ago

Nice! · 9 months, 1 week ago

Thanks · 9 months, 1 week ago

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 #include #include int main() { int n,i,r=1,z,b=0,rem,k=0,j=1; printf("Enter the number\n"); scanf("%d",&n); for(i=0;i
· 9 months, 1 week ago

Thanks @Agnishom Chattopadhyay Can u post a solution to Question no 1. · 9 months, 1 week ago

Try answering the hint · 9 months, 1 week ago

i need to submit my assignment now please post the answer Bro. · 9 months, 1 week ago

I have increased the scope of your problems from C to all other languages by editing "C" out of the discussion.

Hint about 2: How do functions work? What is the underlying data structure that keeps track of where the execution should return to? · 9 months, 1 week ago

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 #include int main() { int n=1, e=0, o=0, sum=0, p=0, i=0, index=1, c=0, gre=0, first=1; printf("Enter a sequnce of numbers terminal no. of sequence being 0"); while(n!=0) { i++; scanf("%d" ,&n); if(n==0) break; sum+=n; if(n%2==0) e++; else o++; if(n>=p) { c++; } else { if(c>gre) { gre=c; first=index; index=1; } c=1; }p=n; } if(c>gre) { gre=c; first=index; } printf("No. of even no. is %d \n" ,e); printf("No. of odd numbers is %d \n" ,o); printf("Sum of the entered numbers is %d \n" ,sum); printf("Length of largest non decreasing subsequence within is %d \n" ,gre); printf("starting index is %d \n" ,first); return 0; }