Posts

Implementing linked list in C language

#include <stdio.h> #include <stdlib.h> // Define the structure for a node in the linked list struct node {     int data; // The data stored in the node     struct node *next; // Pointer to the next node in the list }; struct node* head = NULL; // Initialize the head of the list as NULL // Function to insert nodes at the end of the list void insert(struct node **head) {     int num = 0, i, data;     printf("\nEnter the number of elements to be inserted: ");     scanf("%d", &num); // Get the number of nodes to be inserted     // Loop to insert the nodes     for(i = 0; i<num; i++) {         // Allocate memory for a new node and get the data for it         struct node* newNode = malloc(sizeof(struct node));         struct node *last = *head;         printf("\nEnter the element %d: ", i+1);         scanf("...

Implementation of stack using array

#include <stdio.h> int val, top=-1, n, i, j, t, choice=0, stack[100]; void push(); void pop(); void show(); int main() {     printf("\nEnter the capacity of the stack\n");     scanf("%d", &n);     while(choice != 4)     {         printf("\nEnter your choice\n1.Push\n2.Pop\n3.Show\n4.Exit\nYou choose: ");         scanf("%d",&choice);         switch(choice)         {             case 1:             {                 push();                 t += 1;                 break;             }             case 2:             {                 pop();    ...

The number of required [n x 1] multiplexer to implement one [m x 1] multiplexer.

  /****************************************************************************** This is a program to find the number of required (m x 1) multiplexer to implement one (n x 1) multiplexer. And m is always even, otherwise we are wasting the bit(s). If your m is odd then increase it by one. *******************************************************************************/ #include <stdio.h> int main() {     int n, m, x, y = 0;      printf("This is a program to find the number of required (m x 1) multiplexer to implement one (n x 1) multiplexer. And m is always even, otherwise, we are wasting the bit(s). If your m is odd then increase it by one.\n");     printf("Enter the value of n:\t");     scanf("%d", &n);     printf("Enter the value of m:\t");     scanf("%d", &m);     if(n>m){         x = n;         while(x > m){           ...

The number of required [n x 1] multiplexer to implement one [m x 1] multiplexer. Only for even [n/m].

/****************************************************************************** This is a program to find the number of required (n x 1) multiplexer to  implement one (m x 1) multiplexer, only when n/m never gives odd or decimal number . *******************************************************************************/ #include <stdio.h> int main() {     int n, m, x, y = 0;     printf("Enter the value of n:");     scanf("%d", &n);     printf("Enter the value of m:");     scanf("%d", &m);     if(n>m){         x = n;         while(x > m){             x = x/m;             y = y + x;         }         printf("%d", y+1);     }     else         printf("1");     return 0; }  

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];...

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;         ...

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  

Problems in your to-do list | Problem - 48 | Beginner level | C language | CodeChef

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

Course Registration | Problem - 47 | Beginner level | C language | CodeChef

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

Enormous Input Test | Problem - 46 | Beginner level | C language | CodeChef

  Link to the problem statement:  https://www.codechef.com/submit/INTEST 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 n,k,ans=0,i; scanf("%d %d",&n,&k); for(i=0;i<n;i++) { int t; scanf("%d",&t); if(t%k==0) { ans++; } } printf("%d",ans); return 0; } Hope this will help you, if you want anything else leave a comment. Thank you  

Air Hockey | Problem - 45 | Beginner level | C language | CodeChef

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

Fitness | Problem - 44 | Beginner level | C language | CodeChef

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

Biryani classes | Problem - 43 | Beginner level | C language | CodeChef

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

First and Last Digit | Problem - 42 | Beginner level | C language | CodeChef

  Link to the problem statement:  https://www.codechef.com/submit/FLOW004 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 ld,n,t,r;          scanf("%d",&t);     while(t--){         scanf("%d",&n);         ld = n%10;         while(n>0) {r=n%10; n/=10;}         printf("%d\n",r+ld);     }     return 0; } Hope this will help you, if you want anything else leave a comment. Thank you  

Credit score | Problem - 41 | Beginner level | C language | CodeChef

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

Monthly Budget | Problem - 40 | Beginner level | C language | CodeChef

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

Chef and Instant Noodles | Problem - 39 | Beginner level | C language | CodeChef

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

Sum of Digits | Problem - 38 | Beginner level | C language | CodeChef

Link to the problem statement:  https://www.codechef.com/submit/FLOW006 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(void) { int t; scanf("%d",&t); while (t--){     int n,m,sum=0;     scanf ("%d",&n);     while(n>0){                  m=n%10;         n=n/10;              sum=sum+m;     }         printf("%d\n",sum); } return 0; } Hope this will help you, if you want anything else leave a comment. Thank you