0% found this document useful (0 votes)
14 views3 pages

C Programs for Basic Operations

The document outlines a series of C programming exercises, including printing a name, adding two numbers, and comparing three numbers using both pass by value and pass by reference. It provides function declarations, input examples, and expected output for each exercise. Additionally, it includes tasks for summing natural numbers and summing an array of user-defined size.

Uploaded by

arhank.edu2004
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views3 pages

C Programs for Basic Operations

The document outlines a series of C programming exercises, including printing a name, adding two numbers, and comparing three numbers using both pass by value and pass by reference. It provides function declarations, input examples, and expected output for each exercise. Additionally, it includes tasks for summing natural numbers and summing an array of user-defined size.

Uploaded by

arhank.edu2004
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1. Write a C program to print your name.

2. Write a C program to add two numbers.

3. Write a C program to add two numbers using pass by value

Function declarations

int input();
int add(int a, int b);
void output(int a, int b, int sum);

Input

1
2

Output

The sum of 1 and 2 is 3

4. Write a C program to add two numbers using pass by reference

Function Declarations

int input();
void add(int a, int b, int *sum);
void output(int a, int b, int sum);

Input

1
2

Output

The sum of 1 and 2 is 3


5. Write a C program to compare three numbers using pass by value

Function Declarations

int input();
int compare(int a, int b, int c);
void output(int a, int b, int c, int largest);

Input

1
2
3

Output

The largest of 1,2 and 3 is 3.

6. Write a C program to compare three numbers using pass by reference

Function Declarations

int input();
void compare(int a, int b, int c, int *largest);
void output(int a, int b, int c, int largest);

Input

1
1
0

Output

7. Write a C program to find sum of all natural numbers until n

Function Declarations

int input_n();
int sum_n_nos(int n);
void output(int n, int sum);

Input

1
2
3

Output

The largest of 1,2 and 3 is 3.

8. Write a C program to find the sum of n different numbers entered by the user.

Function Declarations

int input_array_size();
void input_array(int n, int a[n]);
int sum_n_array(int n, int a[n]);
void output(int n, int a[n],int sum);

Input

Input array size: 3


Input the array:
1 7 11

Output

1+7+11 is 19

You might also like