Showing posts with label Generic. Show all posts
Showing posts with label Generic. Show all posts

FIND OUT GENERIC ROOT OF A NUMBER - C PROGRAM.

How to FIND OUT GENERIC ROOT OF A NUMBER BY C PROGRAM.


#include<stdio.h>
int main(){
long int num,sum,r;
printf("\nEnter a number:-");
scanf("%ld",&num);
while(num>10){
sum=0;
while(num){
r=num%10;
num=num/10;
sum+=r;
}
if(sum>10)
num=sum;
else
break;
}
printf("\nSum of the digits in single digit is: %ld",sum);
return 0;
}

C program to defines a generic type for queues

How to write a C program to defines a generic type for queues in C Programming Language ?

This C program defines a generic type for queues.

Solution:

  1. /* This C program defines a generic type for queues. */
  2. #ifndef QUEUE_H
  3. #define QUEUE_H
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <stdbool.h>
  8.  
  9. typedef struct Queue Queue;
  10. typedef int Queueelem;
  11.  
  12. Queue *queue_new(unsigned long queue_size);
  13. bool queue_is_empty(const Queue *q);
  14. void queue_add(Queue *q, Queueelem elem);
  15. Queueelem queue_get(Queue *q);
  16. void queue_show(const Queue *q);
  17. void queue_delete(Queue *q);
  18.  
  19. #endif