C Program to find sum of cubic roots of individual digits of a number

Examples:

123 : 11/3 + 21/3 + 31/3

Program:

#include<stdio.h>
#include<conio.h>
#include<math.h>

void main()
{
long int no;
float sum = 0;
clrscr();
printf(“Enter a Number : “);
scanf(“%ld”, &no);
while (no > 0)
{
sum = sum + pow(no % 10,(1/3));
no = no / 10;
}
printf(“\nSum is %f\n”, sum);
getch();
}

C Program to Check Leap Year

Program Logic:

If the year is divisible by 4, it is a leap year. But, if it is divisible by 100, it is not. If the year is divisible by 400, it is a leap year.

Examples:

1. 1996 is a leap year. (divisible by 4)
3. 2100 is a not leap year. (divisible by 100)
2. 2000 is a leap year. (divisible by 100 but also divisible by 400)

Program:

#include<stdio.h>
#include<conio.h>

void main()
{
int year;
clrscr();
printf(“Enter a Year to check : “);
scanf(“%d”, &year);

if(year % 400 == 0)
printf(“%d is a Leap Year.”, year);
else if(year % 100 == 0)
printf(“%d is not a Leap Year.”, year);
else if(year % 4 == 0)
printf(“%d is a Leap Year.”, year);
else
printf(“%d is not a Leap Year”, year);

printf(“\nPress any key to Quit…”);
getch();
}

C program to convert character to ASCII and to find the sum of digits of ASCII value

Program:

#include<stdio.h>
#include<conio.h>
#include<ctype.h>
void main()
{
 char ch;
 int asc;
 int sum = 0;
 clrscr();
 printf("Enter a character : ");
 scanf("%c", &ch);
 asc = toascii(ch);
 printf("\nThe ASCII value of %c is %d", ch, asc);
 while (asc > 0)
 {
  sum = sum + (asc % 10);
  asc = asc / 10;
 }
 printf("\nThe sum is %d", sum);
 getch();
}

C program to find sum of integers between 101 to 200 whose individual digits are prime in nature

#include<stdio.h>
#include<conio.h>

void main()
{
 int i=102, j, k;
 int sum = 0, digitsum;
 int prime;
 clrscr();
 do
 {
  j = i;
  digitsum = 0;
  while (j > 0)
  {
   digitsum = digitsum + (j % 10);
   j = j / 10;
  }
  prime = 1;
  for (k=2; k<digitsum/2; k++)
  {
   if (digitsum % k == 0)
   {
    prime = 0;
    break;
   }
  }
  if (prime == 1)
  {
   sum = sum + i;
  }
  i++;
 } while (i < 200);
 printf("Sum is %d", sum);
 getch();
}

C program for list implementation using array

#include<stdio.h>
#include<conio.h>

#define MAX 20 //maximum no of elements in the list

//user defined datatypes
struct
{
 int list[MAX];
 int element;  //new element to be inserted
 int pos;  //position of the element to be inserted or deleted
 int length;  //total no of elements
}l;
enum boolean { true, false };
typedef enum boolean boolean;

//function prototypes
int menu(void); //function to display the list of operations
void create(void); //function to create initial set of elements
void insert(int, int); //function to insert the given element at specified position
void delet(int); //function to delete the element at given position
void find(int);  //function to find the position of the given element, if exists
void display(void); //function to display the elements in the list
boolean islistfull(void); //function to check whether the list is full or not
boolean islistempty(void);  //function to check whether the list is empty or not

void main()
{
 int ch;
 int element;
 int pos;

 l.length = 0;

 while(1)
 {
  ch = menu();
  switch (ch)
  {
   case 1:
    l.length = 0;
    create();
    break;
   case 2:
    if (islistfull() != true)
    {
     printf("\tEnter the New element : ");
     scanf("%d", &element);
     printf("\tEnter the Position : ");
     scanf("%d", &pos);
     insert(element, pos);
    }
    else
    {
     printf("\tList if Full. Cannot insert");
     printf("\nPress any key to continue...");
     getch();
    }
    break;
   case 3:
    if (islistempty() != true)
    {
     printf("Enter the position of element to be deleted : ");
     scanf("%d", &pos);
     delet(pos);
    }
    else
    {
     printf("List is Empty.");
     printf("\nPress any key to continue...");
     getch();
    }
    break;
   case 4:
    printf("No of elements in the list is %d", l.length);
    printf("\nPress any key to continue...");
    getch();
    break;
   case 5:
    printf("Enter the element to be searched : ");
    scanf("%d", &element);
    find(element);
    break;
   case 6:
    display();
    break;
   case 7:
    exit(0);
    break;
   default:
    printf("Invalid Choice");
    printf("\nPress any key to continue...");
    getch();
  }
 }
}

//function to display the list of elements
int menu()
{
 int ch;
 clrscr();
 printf("\n\t\t********************************************\n");
 printf("\t\t******LIST Implementation Using Arrays******\n");
 printf("\t\t********************************************\n\n");
 printf("\t1. Create\n\t2. Insert\n\t3. Delete\n\t4. Count\n\t5. Find\n\t6. Display\n\t7. Exit\n\n\tEnter your choice : ");
 scanf("%d", &ch);
 printf("\n\n");
 return ch;
}

//function to create initial set of elements
void create(void)
{
 int element;
 int flag=1;
 while(flag==1)
 {
  printf("Enter an element : ");
  scanf("%d", &element);
  l.list[l.length] = element;
  l.length++;
  printf("To insert another element press '1' : ");
  scanf("%d", &flag);
 }
}

//function to display the elements in the list
void display(void)
{
 int i;
 for (i=0; i<l.length; i++)
  printf("Element %d : %d \n", i+1, l.list[i]);
 printf("Press any key to continue...");
 getch();
}

//function to insert the given element at specified position
void insert(int element, int pos)
{
 int i;
 if (pos == 0)
 {
  printf("\n\nCannot insert at zeroth position");
  getch();
  return;
 }
 if (pos-1 > l.length)
 {
  printf("\n\nOnly %d elements exit. Cannot insert at %d postion", l.length, pos);
  printf("\nPress any key to continue...");
  getch();
 }
 else
 {
  for (i=l.length; i>=pos-1; i--)
  {
   l.list[i+1] = l.list[i];
  }
  l.list[pos-1] = element;
  l.length++;
 }
}

//function to delete the element at given position
void delet(int pos)
{
 int i;
 if(pos == 0)
 {
  printf("\n\nCannot delete at zeroth position");
  getch();
  return;
 }
 if (pos > l.length)
 {
  printf("\n\nOnly %d elements exit. Cannot delete", l.length, pos);
  printf("\nPress any key to continue...");
  getch();
  return;
 }
 for (i=pos-1; i<l.length; i++)
 {
  l.list[i] = l.list[i+1];
 }
 l.length--;
}

//function to find the position of the given element, if exists
void find(int element)
{
 int i;
 int flag = 1;
 for (i=0; i<l.length; i++)
 {
  if(l.list[i] == element)
  {
   printf ("%d exists at %d position",element, i+1);
   flag = 0;
   printf("\nPress any key to continue...");
   getch();
   break;
  }
 }
 if(flag == 1)
 {
  printf("Element not found.\nPress any key to continue...");
  getch();
 }
}

//function to check whether the list is full or not
boolean islistfull(void)
{
 if (l.length == MAX)
  return true;
 else
  return false;
}

//function to check whether the list is empty or not
boolean islistempty(void)
{
 if (l.length == 0)
  return true;
 else
  return false;
}

Sample Output:

1. Create
2. Insert
3. Delete
4. Count
5. Find
6. Display
7. Exit

Enter your Choice: 1
Enter an element: 25
To insert another element press 1: 1

Enter an element: 50
To insert another element press 1: 0

Enter your Choice: 6
Element in the List are
1. 25
2. 50

Enter your Choice: 2
Enter an element: 5
Enter the position: 1
Element in the List are
1. 25
2. 50

Enter your Choice: 3
Enter the position: 3

Enter your Choice: 6
Element in the List are
1. 5
2. 25

Enter your Choice: 4
Number of Elements: 2

Enter your Choice: 7