Posts

Showing posts from July, 2022

Second largest element in an array

Pre defined array: #include <stdio.h> int main() {     int a[10] = {1, 11, 3, 4, 150, 69, 7, 8, 9, 10};     int i, l, s=0;     l=a[0];     for(i=0; i<10; i++) {         if(l<a[i])             l = a[i];     }     for(i=0; i<10; i++) {         if(a[i]>a[i+1] && a[i]!=l)             s = a[i];     }     printf("Largest - %d \nSecond - %d \n", l, s);     return 0; } Taking array as an input: #include <stdio.h> int main() {     int n, i, l, s=0;     printf("Enter the number of element(s):\n");     scanf("%d", &n);     int a[n];     for(i=0;i<n;i++)     {         printf("\nEnter the element %d:\t", i);         scanf("%d", &a[i]);     }     l=a[0];     for(i=0; i<n; i++)     {         if(l < a[i])         {             s = l;             l = a[i];         }         else if(s < a[i])             s = a[i];     }     printf("\nLargest - %d \nSecond largest- %d \n", l, s);     return 0;

Degree of Polynomial | Problem - 52 | Beginner level | C language | CodeChef

Link to the problem statement:   https://www.codechef.com/submit/DPOLY Solution:   #include <stdio.h> int main(void) { int t; scanf("%d", &t); while(t--) {     int i, n, d;     scanf("%d",  &n);     int a[n];     for(i=0;i<n;i++)     {         scanf("%d", &a[i]);         if(a[i] != 0)         {             d = i;         }              }     printf("%d\n", d); } return 0; } Hope this will help you, if you want anything else leave a comment. Thank you  

Battery Low | Problem - 51 | Beginner level | C language | CodeChef

Link to the problem statement:   codechef.com/submit/BATTERYLOW Solution:   #include <stdio.h> int main(void) { int t, x; scanf("%d", &t); while(t--) {     scanf("%d", &x);     if(x > 15)         printf("NO\n");     else         printf("YES\n"); } return 0; } Hope this will help you, if you want anything else leave a comment. Thank you  

Small factorials | Problem - 50 | Beginner level | C language | CodeChef

    Link to the problem statement:   https://www.codechef.com/submit/FCTRL2 Solution:   The solution is already given, you just have to click on  SUBMIT CODE  button. //We have populated the solutions for the 10 easiest problems for your support. //Click on the SUBMIT button to make a submission to this problem. #include<stdio.h> int main() {     int t,n,a[200],i,j,k,l,m;     scanf("%d",&t);     while(t--)     {     scanf("%d",&n);         m=1;         a[0]=1;         for(j=2;j<=n;j++)         {             l=0;             for(k=0;k<m;k++)             {                 a[k]=a[k]*j+l;                 l=a[k]/10;                 a[k]=a[k]%10;             }             while(l)             {             a[k]=l%10;                 k++;                 m++;                 l=l/10;             }         }         for(i=m-1;i>=0;i--)             printf("%d",a[i]);         printf("\n");     }     return 0; } Hope this will help

Increase IQ | Problem - 49 | Beginner level | C language | CodeChef

  Link to the problem statement:  https://www.codechef.com/submit/INCRIQ Solution:   #include <stdio.h> int main(void) { int x;     scanf("%d",&x);     if(x>=100 && x <= 169)     {         if(x+7 > 170)             printf("YES\n");         else             printf("NO\n");     } return 0; } Hope this will help you, if you want anything else leave a comment. Thank you