C Program Report
C Program Report
1. Program Sample
2. Program to find cube of a number
3. Program to add two numbers
4. Program to Print an Integer
5. Program to find product of floating point numbers
6. Program to Print ASCII Value
7. Program to Compute Quotient and Remainder
8. Program to Find the Size of Variables
9. Swap Numbers Using Temporary Variable
10.Program to find area of rectangle and square
11.Increment Decrement Operator
12.Program on Relational operator
13.Program to find whether a person can vote
14. Program to check greater of two number.
15. Program to check condition with &. And |.
16. Program on Static Example
17.Program on extern Storage Class
18.Program on Register variable
19.Program to check Even Odd
20.Program to check largest among three integers
21. Program using switch to display week days .
22.Calculator using switch
23.Program to print table of a number
24.Program to print sum of 10 numbers.
25.Program to print factorial of a numbers..
26.While loop
27.Program to check for prime
28.Program using do_while to display sum of n natural number
29.Program to find LCM
30.Convert binary to decimal
31.Goto jump statement
32.Program to check continue statement.
33.Program to store value in array and traversing
34.Program to input two-dimensional array
35.Bubble sort.
36.Program to input String .
37.Program to illustrate String functions
38.Program to find reverse of string.
39.Function example with argument /without argument
40.Call by Value
41.Call by Reference
42.Recursion for calculating factorial.
43.Pointer Example /double pointer
44.Program to display Array using Pointers
45.Program to allocate memory dynamically malloc function
46.Program using calloc function
47.Program on structure
48.Program to illustrate pionter object to structure
49.What is a nested structure ?
50.Passing structure to function
Program solutions
1. Program Sample
#include <stdio.h>
#include<conio.h>
void main()
{ printf(“C Programming”);
getch();
}
return 0;
}
return 0;
}
16,17,18 Program will be given later on
40.Call by Value
#include<stdio.h>
void change(int num) {
printf("Before adding value inside function num=%d \n",num);
num=num+100;
printf("After adding value inside function num=%d \n", num);
}
int main() {
int x=100;
printf("Before function call x=%d \n", x);
change(x);//passing value in function
printf("After function call x=%d \n", x);
return 0;
}
41. Call by reference
#include<stdio.h>
void change(int *num) {
printf("Before adding value inside function num=%d \n",*num);
(*num) += 100;
printf("After adding value inside function num=%d \n", *num);
}
int main() {
int x=100;
printf("Before function call x=%d \n", x);
change(&x);//passing reference in function
printf("After function call x=%d \n", x);
return 0;
}
42. Recursion
#include <stdio.h>
int fact (int);
int main()
{
int n,f;
printf("Enter the number ");
scanf("%d",&n);
f = fact(n);
printf("factorial = %d",f);
}
int fact(int n)
{
if (n==0)
{ return 0; }
else if ( n == 1)
{ return 1; }
else
{ return n*fact(n-1); }
}
43.Pointer example
#include<stdio.h>
int main(){
int number=50;
int *p;
p=&number;
printf("Address of p variable is %x \n",p);
printf("Value of p variable is %d \n",*p);
return 0;
}
47.Program on structure
struct Point
{ int x, y;
};
int main()
{ struct Point p1 = {0, 1};
p1.x = 20;
printf ("x = %d, y = %d", p1.x, p1.y) ;
return 0;
}
48. Program to illustrate pionter object to structure
struct Point
{ int x, y;
};
int main()
{ struct Point p1 = {0, 1};
p1.x = 20;
printf ("x = %d, y = %d", p1.x, p1.y) ;
// p2 is a pointer to structure p1
struct Point *p2 = &p1;
// Accessing structure members using structure pointer
printf("%d %d", p2->x, p2->y);
return 0;
}
#include<stdio.h>
struct address
{ char city[20], phone[14];
int pin;
};
struct employee
{ char name[20];
struct address add;
};
void display(struct employee);
void main ()
{ struct employee emp;
printf("Enter employee information?\n");
scanf("%s %s %d %s",emp.name,emp.add.city, &emp.add.pin, emp.add.phone);
display(emp); }
void display(struct employee emp)
{ printf("Printing the details....\n");
printf("%s %s %d%s",emp.name,emp.add.city,emp.add.pin,emp.add.phone);}