Professional Documents
Culture Documents
#include<stdio.h>
long fact(int);
int main(){
int line,i,j;
for(i=0;i<line;i++){
for(j=0;j<line-i-1;j++)
printf(" ");
for(j=0;j<=i;j++)
printf("%ld ",fact(i)/(fact(j)*fact(i-j)));
printf("\n");
}
return 0;
}
output:
return 0;
}
write c program which will accept 2 numbers n and r and calculate value of nCr=n!/(n-r)!. Program
should make use of recursion
#include <stdio.h>
void main()
{
int n, r, ncr;
int fact(int z)
{
int f = 1, i;
if (z == 0)
{
return(f);
}
else
{
for (i = 1; i <= z; i++)
{
f = f * i;
}
}
return(f);
}
C program for palindrome number
#include <stdio.h>
int main()
{
int n, reverse = 0, t;
t = n;
while (t != 0)
{
reverse = reverse * 10;
reverse = reverse + t%10;
t = t/10;
}
if (n == reverse)
printf("%d is a palindrome number.\n", n);
else
printf("%d isn't a palindrome number.\n", n);
return 0;
}
#include<stdio.h>
#include<stdlib.h>
int main(){
long int n,sum=0,r;
system("cls");
printf("enter the number=");
scanf("%ld",&n);
while(n>0)
{
r=n%10;
sum=sum*10+r;
n=n/10;
}
n=sum;
while(n>0)
{
r=n%10;
switch(r)
{
case 1:
printf("one ");
break;
case 2:
printf("two ");
break;
case 3:
printf("three ");
break;
case 4:
printf("four ");
break;
case 5:
printf("five ");
break;
case 6:
printf("six ");
break;
case 7:
printf("seven ");
break;
case 8:
printf("eight ");
break;
case 9:
printf("nine ");
break;
case 0:
printf("zero ");
break;
default:
printf("tttt");
break;
}
n=n/10;
}
return 0;
}
#include <stdio.h>
int main()
{
int a, b;
a = a + b;
b = a - b;
a = a - b;
int main()
{
int x, y, *a, *b, temp;
a = &x;
b = &y;
temp = *b;
*b = *a;
*a = temp;
return 0;
}
int f(int);
int main()
{
int n, i = 0, c;
scanf("%d", &n);
return 0;
}
int f(int n)
{
if (n == 0 || n == 1)
return n;
else
return (f(n-1) + f(n-2));
}
Matrix multiplication in C language
#include <stdio.h>
int main()
{
int m, n, p, q, c, d, k, sum = 0;
int first[10][10], second[10][10], multiply[10][10];
if (n != p)
printf("The matrices can't be multiplied with each other.\n");
else
{
printf("Enter elements of second matrix\n");
multiply[c][d] = sum;
sum = 0;
}
}
printf("\n");
}
}
return 0;
}
C Program To Count Number of Spaces, Newlines, Tabs and Characters in File
#include<stdio.h>
#include<stdlib.h>
void main()
{
FILE *fp;
char ch;
int character = 0, space = 0, tab = 0, line = 0;
fp = fopen("/home/tusharsoni/Desktop/TestFile","r");
if(fp == NULL)
{
printf("File Not Found\n");
exit(1);
}
else
{
while(1)
{
ch = fgetc(fp);
if(ch == EOF)
{
break;
}
character++;
if(ch == ' ')
space++;
else if(ch == '\t')
tab++;
else if(ch == '\n')
line++;
}
}
fclose(fp);
printf("\nNumber of Characters = %d\n", character);
printf("\nNumber of Tabs = %d\n", tab);
printf("\nNumber of New Lines = %d\n", line);
printf("\nNumber of Spaces = %d\n", space);
#include <stdio.h>
int main()
{
int num, result;
/*
* C program to a pass integer array elements to
* a function and return the sum of all elements
*/
#include <stdio.h>
return sum;
}
// main function
int main()
{
int total = 0;
int array[10] = {1,2,3,4,5,6,7,8,9};
return 0;
}
C program to create, write and read text in/from file
#include< stdio.h >
int main()
{
fclose(fp);
return 0;
}
/*
* C program to simulate a simple calculator to perform arithmetic
* operations like addition, subtraction, multiplication and division
*/
#include <stdio.h>
void main()
{
char operator;
float num1, num2, result;