Skip to content

Commit 2f4e934

Browse files
Add files via upload
0 parents  commit 2f4e934

18 files changed

+401
-0
lines changed

armstrong_number.c

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
// C PROGRAM TO CHECK IF A NUMBER IS ARMSTRONG NUMBER
3+
4+
#include<stdio.h>
5+
#include<math.h>
6+
int main()
7+
{
8+
int a,i,b=0,c,d,e=0,sum=0;
9+
printf("Enter a number: ");
10+
scanf("%d",&a);
11+
c=d=a;
12+
while(c>0)
13+
{
14+
c/=10;
15+
b++;
16+
}
17+
while(d!=0)
18+
{
19+
e=d%10;
20+
sum+=pow(e,b);
21+
d=d/10;
22+
}
23+
if (a==sum)
24+
printf("It is a armstrong number");
25+
else
26+
printf("It is not a armstrong number");
27+
return 0;
28+
}

combinations_of_a_string.c

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
// C PROGRAM TO FIND NUMBER OF COMBINATIONS ALLOWED FOR A STRING
3+
4+
#include<stdio.h>
5+
#include<string.h>
6+
int fact(int a)
7+
{
8+
if (a==0 || a==1)
9+
return 1;
10+
else
11+
return a*fact(a-1);
12+
}
13+
int main()
14+
{
15+
char arr[100];
16+
int count,final;
17+
printf("Enter string: ");
18+
scanf("%s",arr);
19+
int n=strlen(arr),ans=(fact(n));
20+
char ch[26]={'a','s','d','f','g','h','j','k','l','z','x','c','v','b','n',
21+
'm','q','w','e','r','t','y','u','i','o','p'};
22+
for (int i=0;i<26;i++)
23+
{ count=0;
24+
for(int j=0;j<n;j++)
25+
{
26+
if (ch[i]==arr[j])
27+
count++;
28+
}
29+
ans=ans/fact(count);
30+
}
31+
printf("No of combinations: %d",ans);
32+
return 0;
33+
}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
// C PROGRAM TO FIND INTEGER AND DECIMAL PART OF A NUMBER
3+
4+
#include<stdio.h>
5+
#include<math.h>
6+
int main()
7+
{
8+
double a,b,c;
9+
printf("Enter number: ");
10+
scanf("%lf",&a);
11+
b=modf(a,&c);
12+
printf("Decimal part: %f\nInteger part: %f",b,c);
13+
return 0;
14+
}

decimal_to_binary.c

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
// C PROGRAM TO CONVERT DECIMAL TO BINARY NUMBER
3+
4+
#include<stdio.h>
5+
int main()
6+
{
7+
int a,b,c=0,d=1;
8+
printf("Enter decimal number: ");
9+
scanf("%d",&a);
10+
while(a!=0)
11+
{
12+
b=a%2;
13+
c+=b*d;
14+
d*=10;
15+
a=a/2;
16+
}
17+
printf("Binary number: %d",c);
18+
return 0;
19+
}

factorial_of_a_number.c

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
// C PROGRAM TO FIND FACTORIAL OF A NUMBER
3+
4+
#include <stdio.h>
5+
int main()
6+
{
7+
int a,i,b=1;
8+
printf("Enter number: ");
9+
scanf("%d",&a);
10+
for (i=1;i<=a;i++)
11+
{
12+
b=b*i;
13+
}
14+
printf("Factorial: %d",b);
15+
return 0;
16+
}

factors_of_a_number.c

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
// C PROGRAM TO FIND FACTORS OF A NUMBER
3+
4+
#include<stdio.h>
5+
int main()
6+
{
7+
int a;
8+
printf("Enter number: ");
9+
scanf("%d",&a);
10+
printf("Factors: ");
11+
for(int i=1;i<=a;i++)
12+
{
13+
if(a%i==0)
14+
printf("%d ",i);
15+
}
16+
return 0;
17+
}

finding_berth_in_a_train.c

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
// C PROGRAM TO FIND BERTH IN A TRAIN
3+
4+
#include<stdio.h>
5+
#include<string.h>
6+
int main()
7+
{
8+
int a;
9+
printf("Enter seat number: ")
10+
scanf("%d",&a);
11+
if((a-4)%8==0 || (a-1)%8==0)
12+
printf("Lower Berth");
13+
else if ((a-2)%8==0 || (a-1)%4==0)
14+
printf("Middle Berth");
15+
else if ((a-3)%8==0 || (a-2)%4==0)
16+
printf("Upper Berth");
17+
else if (a%8==0)
18+
printf("Side Upper Berth");
19+
else
20+
printf("Side Lower Berth");
21+
return 0;
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
// C program to input and print array elements using pointers
3+
4+
#include <stdio.h>
5+
#define MAX_SIZE 100 // Maximum array size
6+
int main()
7+
{
8+
int arr[MAX_SIZE];
9+
int N, i;
10+
int * ptr = arr; // Pointer to arr[0]
11+
12+
printf("Enter size of array: ");
13+
scanf("%d", &N);
14+
15+
printf("Enter elements in array:\n");
16+
for (i = 0; i < N; i++)
17+
{
18+
scanf("%d", ptr);
19+
20+
// Move pointer to next array element
21+
ptr++;
22+
}
23+
24+
// Make sure that pointer again points back to first array element
25+
ptr = arr;
26+
27+
printf("Array elements: ");
28+
for (i = 0; i < N; i++)
29+
{
30+
// Print value pointed by the pointer
31+
printf("%d, ", *ptr);
32+
33+
// Move pointer to next array element
34+
ptr++;
35+
}
36+
return 0;
37+
}

nested_printf.c

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
// C PROGRAM FOR NESTED PRINTF FUNCTION
3+
4+
#include<stdio.h>
5+
int main ()
6+
{
7+
int i=10,j=2;
8+
printf("%d",printf("%d",printf("%d",printf("%d%d",i,j))));
9+
// INNER MOST PRINTF PRINTS THE OUTPUT AND NEXT PRINTF PRINTS
10+
// THE SIZE OF THE OUTPUT AND NEXT PRINTF PRINTS THE SIZE OF
11+
// SECOND OUTPUT AND IT GOES ON...
12+
return 0;
13+
}

palindrome_number_or_not.c

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
// C PROGRAM TO FIND A NUMBER IS PALINDROME OR NOT
3+
4+
#include <stdio.h>
5+
int main()
6+
{
7+
int a,b,rev=0,rem;
8+
printf("Enter the number: ");
9+
scanf("%d",&a);
10+
b=a;
11+
while(a>0)
12+
{
13+
rem=a%10;
14+
rev=(rev*10)+rem;
15+
a=a/10;
16+
}
17+
printf("Reverse number of %d is %d",b, rev);
18+
if(b==rev)
19+
printf("\n%d is palindrome\n",b);
20+
else
21+
printf("\n%d is not a palindrome\n",b);
22+
return 0;
23+
}

prime_number_or_composite_number.c

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
// C PROGRAM TO FIND IF A NUMBER IS PRIME OR COMPOSITE
3+
4+
#include<stdio.h>
5+
int main()
6+
{
7+
int a,i;
8+
printf("Enter number: ");
9+
scanf("%d",&a);
10+
for (i=2;i<a;i++)
11+
{
12+
if(a%i==0){
13+
printf("composite");
14+
break;}
15+
}
16+
if(i==a)
17+
printf("prime");
18+
return 0;
19+
}

print_diamond_star_pattern.c

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
// C PROGRAM TO FIND DIAMOND STAR PATTERN
3+
4+
#include <stdio.h>
5+
6+
int main()
7+
{
8+
int i, j, rows;
9+
int stars, spaces;
10+
11+
printf("Enter rows to print : ");
12+
scanf("%d", &rows);
13+
14+
15+
stars = 1;
16+
spaces = rows - 1;
17+
18+
/* Iterate through rows */
19+
for(i=1; i<rows*2; i++)
20+
{
21+
/* Print spaces */
22+
for(j=1; j<=spaces; j++)
23+
printf(" ");
24+
25+
/* Print stars */
26+
for(j=1; j<stars*2; j++)
27+
printf("*");
28+
29+
/* Move to next line */
30+
printf("\n");
31+
32+
if(i<rows)
33+
{
34+
spaces--;
35+
stars++;
36+
}
37+
else
38+
{
39+
spaces++;
40+
stars--;
41+
}
42+
}
43+
44+
return 0;
45+
}

print_upper_half_diamond_pattern.c

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
// C PROGARM TO PRINT UPPER HALF DIAMOND PATTERN
3+
4+
#include <stdio.h>
5+
int main() {
6+
int i, space, rows, k = 0;
7+
printf("Enter the number of rows: ");
8+
scanf("%d", &rows);
9+
for (i = 1; i <= rows; ++i, k = 0) {
10+
for (space = 1; space <= rows - i; ++space) {
11+
printf(" ");
12+
}
13+
while (k != 2 * i - 1) {
14+
printf("* ");
15+
++k;
16+
}
17+
printf("\n");
18+
}
19+
return 0;
20+
}

scanf_inside_printf.c

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
// C PROGRAM TO IMPLEMENT SCANF INSIDE PRINTF
3+
4+
#include <stdio.h>
5+
int main()
6+
{
7+
char a[100], b[100], c[100];
8+
// scanf() with one input
9+
printf("First scanf() returns : %d\n",scanf("%s", a));
10+
// scanf() with two inputs
11+
printf("Second scanf() returns : %d\n",scanf("%s%s", a, b));
12+
// scanf() with three inputs
13+
printf("Third scanf() returns : %d",scanf("%s%s%s", a, b, c));
14+
return 0;
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
// C PROGRAM TO IMPLEMENT NESTED STRUCTURE
3+
4+
#include<stdio.h>
5+
struct student
6+
{
7+
int rollno;
8+
};
9+
struct class
10+
{
11+
struct student a;
12+
char name[20];
13+
}var;
14+
int main()
15+
{
16+
printf("Enter name and roll no: ");
17+
scanf("%s%d",var.name,&var.a.rollno);
18+
printf("Entered name: %s\nEntered rollno: %d",var.name,var.a.rollno);
19+
return 0;
20+
}

sum_of_'n'_numbers.c

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
// C PROGRAM TO FIND SUM OF 'N' NUMBERS
3+
4+
#include<stdio.h>
5+
int main()
6+
{
7+
int a;
8+
printf("Enter number: ");
9+
scanf("%d",&a);
10+
printf("Sum: %d",a*(a+1)/2);
11+
}

0 commit comments

Comments
 (0)