0% found this document useful (0 votes)
13 views10 pages

c practical file

The document contains ten C programming examples, each demonstrating different functionalities. These include printing a message, calculating sums, factorials, Fibonacci sequences, checking even/odd numbers, swapping values, calculating square and cube roots, finding the area of a circle, and computing simple and compound interest. Each example includes the necessary code and user prompts for input.

Uploaded by

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

c practical file

The document contains ten C programming examples, each demonstrating different functionalities. These include printing a message, calculating sums, factorials, Fibonacci sequences, checking even/odd numbers, swapping values, calculating square and cube roots, finding the area of a circle, and computing simple and compound interest. Each example includes the necessary code and user prompts for input.

Uploaded by

hardikthakur724
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

1.//write a c program to print "hello" on the screen.

#include<stdio.h>

#include<conio.h>

int main()

printf("hello");

return(0);

2.//write a c program to find the sum of two numbers.


#include <stdio.h>

#include<conio.h>

int main() {

int a, b, result;

printf("Enter first number : ");

scanf("%d", &a);

printf("Enter second number : ");


scanf("%d", &b);

result = a + b;

printf("Sum : %d\n", result);

return 0;

3.//write a c program to print factorial of a number.


#include <stdio.h>

int main() {

int n, i;

unsigned long long fact = 1;

printf("Enter an integer: ");

scanf("%d", &n);

if (n < 0)

printf("Error! Factorial of a negative number doesn't exist.");

else {

for (i = 1; i <= n; ++i) {

fact *= i;
}

printf("Factorial of %d = %llu", n, fact);

return 0;

4. //write a c program to print fibonacci sequence.


#include <stdio.h>

int main() {

int i, n;

int t1 = 0, t2 = 1;

int nextTerm = t1 + t2;

printf("Enter the number of terms: ");


scanf("%d", &n);

printf("Fibonacci Series: %d, %d, ", t1, t2);

for (i = 3; i <= n; ++i) {

printf("%d, ", nextTerm);

t1 = t2;

t2 = nextTerm;

nextTerm = t1 + t2;

return 0;

5.//write a c program to find whether a number is even or odd.


#include <stdio.h>

int main() {

int num;

printf("Enter an integer: ");

scanf("%d", &num);

if(num % 2 == 0)
printf("%d is even.", num);

else

printf("%d is odd.", num);

return 0;

6.// write a c program to swap two numbers.


#include<stdio.h>
int main() {

double first, second, temp;

printf("Enter first number: ");

scanf("%lf", &first);

printf("Enter second number: ");

scanf("%lf", &second);

temp = first;

first = second;

second = temp;

printf("\nAfter swapping, first number = %.2lf\n", first);

printf("After swapping, second number = %.2lf", second);

return 0; }

7.//write a c program to find the square root of a number.


#include <stdio.h>

#include <math.h>
int main() {

double num, result;

printf("Enter a number: ");

scanf("%lf", &num);

if(num < 0) {

printf("Square root of a negative number is imaginary\n");

return 0;

result = sqrt(num);

printf("Square Root of %.2lf is: %.2lf\n", num, result);

return 0;

8.// C Program to Calculate Cube Root of a Number.


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

int main(){

int number, root;

printf("Enter a number: ");

scanf("%d", &number);

root = cbrt(number);

printf("Cube root of %d is: %d", number, root);

return 0; }

9.//wap to c area of circle.


#include <stdio.h>
#include <math.h>
int main()

float radius, area;


printf("Enter the radius of a circle\n");

scanf("%f", &radius);

area = 3.14159*radius*radius;

printf("Area of the circle = %.2f\n", area);

return 0;

10.//wap to find the simple interest and compund intrest.


#include<stdio.h>

#include<conio.h>

#include<math.h>

int main()

{
float p, t, r, si, ci;

printf("Enter principal amount (p): ");

scanf("%f", &p);

printf("Enter time in year (t): ");

scanf("%f", &t);

printf("Enter rate in percent (r): ");

scanf("%f", &r);

si = (p * t * r)/100.0;

ci = p * (pow(1+r/100, t) - 1);

printf("Simple Interest = %0.3f\n", si);

printf("Compound Interest = %0.3f", ci);

getch();

return(0);

You might also like