Skip to content

Commit 7ef5b29

Browse files
authored
Merge pull request #15 from yashpatel08/main
Basics of C
2 parents 4e9e733 + ca5ea46 commit 7ef5b29

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1066
-0
lines changed

Addition.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include<stdio.h>
2+
3+
int main()
4+
5+
{
6+
int num1,num2,addition;
7+
printf("enter the num1");
8+
scanf("%d",&num1);
9+
printf("enter the num2");
10+
scanf("%d",&num2);
11+
addition= num1+num2;
12+
printf ("%d",addition);
13+
return 0 ;
14+
15+
}

Area of circle.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include<stdio.h>
2+
3+
int main()
4+
{
5+
float r,pie=3.14,area;
6+
printf("enter the radius ");
7+
scanf("%f",&r);
8+
area=pie*r*r;
9+
printf("area of the circle is %f",area);
10+
11+
return 0;
12+
}

Calculator.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <stdio.h>
2+
#include <math.h>
3+
#include <conio.h>
4+
5+
int main()
6+
{
7+
int a, b;
8+
int sum, sub, mult, mod;
9+
float div;
10+
printf("enter the value of a ");
11+
scanf("%d", &a);
12+
printf("enter the value of b");
13+
scanf("%d", &b);
14+
sum = a + b;
15+
printf("\n add=%d", sum);
16+
sub = a - b;
17+
printf("\n sub=%d", sub);
18+
mult = a * b;
19+
printf("\n mul=%d", mult);
20+
div = (a)/(b);
21+
printf("\n div=%f", div);
22+
mod = a % b;
23+
printf("\n mod=%d", mod);
24+
25+
return 0;
26+
}

Check_Prime_number.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
4+
int main()
5+
{
6+
int n, i;
7+
printf("enter a number ");
8+
scanf("%d",& n);
9+
for (i = 2; i <= n; i++)
10+
{
11+
n % i != 0 ? printf("it is a prime number") : printf("it is a prime number");
12+
}
13+
return 0;
14+
}

Convert celsius to fahrenheit.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include<stdio.h>
2+
3+
int main()
4+
{
5+
float fare,cels;
6+
printf("Enter the temperature in fahrenheit");
7+
scanf("fahrenheit=%f",&fare);
8+
cels=(fare - 32)*0.5;
9+
printf("the temperature in celsius is %f",cels);
10+
11+
return 0;
12+
}

Example of pointer.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include<stdio.h>
2+
3+
int main()
4+
{
5+
int age=18;
6+
int*ptr=&age;
7+
int _age=*ptr;
8+
printf(" age %d",age);
9+
printf("\n *ptr %d",*ptr);
10+
printf("\n _age %d",_age);
11+
12+
return 0;
13+
14+
15+
}

Find factorial.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include<stdio.h>
2+
3+
int factorial(int n);
4+
5+
int main()
6+
{
7+
8+
int n,fact,i;
9+
printf("enter the number ");
10+
scanf("%d",&n);
11+
printf("factorial is %d",factorial(n));
12+
return 0;
13+
14+
}
15+
16+
int factorial(int n)
17+
{
18+
if(n==0)
19+
{
20+
return 1;
21+
}
22+
23+
int factnm1=factorial(n-1);
24+
int factn=factnm1 * n ;
25+
return factn;
26+
27+
}
28+
29+
30+
31+
32+
/* int i,n,fact;
33+
for(i=0;i<=n;i++)
34+
{
35+
fact=n*i;
36+
printf("%d",fact);
37+
38+
return fact;
39+
}*/
40+
41+

Find no is pos or neg.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include<stdio.h>
2+
3+
int main()
4+
{
5+
int num;
6+
printf("enter the num");
7+
scanf("%d",&num);
8+
if(num>0)
9+
{
10+
printf("the given number is positive");
11+
}
12+
else
13+
{
14+
printf("the given number is negative");
15+
}
16+
return 0 ;
17+
}

Find out max no.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include<stdio.h>
2+
3+
int main()
4+
{
5+
int a,b;
6+
printf("enter the value of a ");
7+
scanf("%d",&a);
8+
printf("entefr the value of b");
9+
scanf("%d",&b);
10+
if(a>b)
11+
{
12+
printf("a is greater than b");
13+
else
14+
{
15+
printf("b is greater than a");
16+
}
17+
}
18+
return 0;
19+
}

Given_number_is_prime_or_not.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <stdio.h>
2+
3+
int main() {
4+
5+
int n, i, flag = 0;
6+
printf("Enter a positive integer: ");
7+
scanf("%d", &n);
8+
9+
// 0 and 1 are not prime numbers
10+
// change flag to 1 for non-prime number
11+
if (n == 0 || n == 1)
12+
flag = 1;
13+
14+
for (i = 2; i <= n / 2; ++i) {
15+
16+
17+
if (n % i == 0) {
18+
flag = 1;
19+
break;
20+
}
21+
}
22+
23+
24+
if (flag == 0)
25+
printf("%d is a prime number.", n);
26+
else
27+
printf("%d is not a prime number.", n);
28+
29+
return 0;
30+
}

0 commit comments

Comments
 (0)