Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Compile and Execute C Online

c

/*
 * math.h
 *
 *  Created on: Aug 22, 2017
 * 	Last Edited: Sept 5, 2017
 *      Author: Russell Trafford
 */

/* Your assignment is to take the math function and implement at least the following functions:
 * + Add (num1 + num2)
 * - Subtract (num1 - num2)
 * * Multiply (num1 * num2)
 * / Divide (num1 / num2)
 * % Modulus (num1 % num2)
*/

#include <stdio.h>
#ifndef MATH_H_
#define MATH_H_

int math(int num1, int num2, char Operator);

int main(){
	
	int num1 = 4;
	int num2 = 2;
	char Operator = '%';
	int ret;
	
	ret = math(num1, num2,Operator);
	
	printf("Answer is : %d\n", ret);

return 0;
}

//Part of your documentation should be listing the valid inputs and outputs for the functions you create.
int math(int num1, int num2, char Operator){
	int result;
	
	if (Operator == '+'){
		result = num1 + num2;
	}
	else if (Operator == '-'){
		result = num1 - num2;
	}
	else if (Operator == '*'){
		result = num1 * num2;
	}
	else if (Operator == '/'){
		result = num1 / num2;
	}
	else if (Operator == '%'){
		result = num1 % num2;
	}
	
	return result;
}

#endif /* MATH_H_ */

fork() - Example

c

#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>

int main() {
    int a = 1000;
    printf("\nAgain ...%d", (int)getpid());
    if (fork()) {
        printf("\nIn child ...");
        a /= 2;
        printf("\nValue of a = %d. PID: %d", a, (int) getpid());
    } else {
        printf("\nIn parent ...");
        if (fork()) {
            printf("\nSecond fork() ... PID: %d", (int) getpid());
            a*=2;
            printf("\nValue of a = %d. PID: %d", a, (int) getpid());
            if (execlp("ls","ls", 0) == -1) {
                a = a + 2;
                printf("\nValue of a = %d. PID: %d", a, (int) getpid());
            }
        } else {
            printf("\nIncrement ...");
            a+=2;
            printf("\nValue of a = %d. PID: %d", a, (int) getpid());
        }
    }
    a++;
    printf("\nValue of a = %d. PID: %d", a, (int) getpid());
    printf("\nExiting %d\n", getpid());
    return 0;
}

Compile and Execute C Online

c

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

int factorial (int n){
    
}

Sunil_C_Program_Examples_

c

#include <stdio.h>

int main()
{
   for(;0;)
   {
       printf("Hello it will execute");
   }
   return 0;
}

MC102

c

#include <stdio.h>

int main()
{
    int sp,pf,sf,vo;
    int rp,rf;
    scanf("%d",&sp);
    scanf("%d",&pf);
    scanf("%d",&sf);
    scanf("%d",&vo);
    rp=sp-1;
    rf=sf-pf;
    for(i=3999999999,i%rp!=0,i=i-1){
        
    }
    
    
    
    
    
    
    return 0;
}

This is really a great domain name

c

#include <stdio.h>

int main()
{
    printf("Hello, World!\n");

    return 0;
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.