/* reverse an integer number without using strrev() and strlen(). subtract 9 from the reversed number and print the result. [2010] */
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n,r,s=0;
printf("Enter any no:");
scanf("%d",&n);
while(n!=0)
{
r=n%10;
s=s*10+r;
n=n/10;
}
printf("result= %d",s-9);
getch();
}
/* print the series as given along with the sum. 1-2+3-4+5-....n.[2010] */
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n,i,s=0,flag=0;
printf("Enter the limit:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(flag==0)
{
s+=i;
flag=!flag;
}
else if(flag==1)
{
s-=i;
flag=!flag;
}
}
printf(" sum= %d",s);
getch();
}
/* reverse a string without using strrev() funtion.[2010] */
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
char str[5],str2[5];
int l=0,i=0,k=0;
printf("Enter any string=");
gets(str);
while(str[i]!='\0')
{
l++;
i++;
}
l=l-1;
while(l>=0)
{
str2[k]=str[l];
k++;
l--;
}
puts(str2);
getch();
}
/* swap the values between two variable using pointer. [2010] */
void swap(int *,int *);
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
printf("Enter the value of a and b:");
scanf("%d%d",&a,&b);
swap(&a,&b);
printf("\nAfter swaping the value of a= %d and b= %d",a,b);
getch();
}
void swap(int *x,int *y)
{
int t;
t=*x;
*x=*y;
*y=t;
}
/* convert decimal to binary number [2010]*/
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int arr[10],n,i=0,r=0;
printf("Enter the decimal no:");
scanf("%d",&n);
while(n>0)
{
arr[i]=n%2;
n=n/2;
i++;
r++;
}
for(i=r-1;i>=0;i--)
{
printf("%d",arr[i]);
}
getch();
}
/* s=1+(1+2)+(1+2+3)... [2011] */
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,s=0,n;
printf("Enter the limit:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
s+=j;
}
}
printf("sum= %d",s);
getch();
}
/* find the max or min no from n no of set [2011] */
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int num[100],n,i,t,j;
printf("How many no you enter");
scanf("%d",&n);
printf("Enter the no");
for(i=0;i<n;i++)
{
scanf("%d",&num[i]);
}
for(i=0;i<n;i++)
{
for( j=0;j<n-i;j++)
{
if(num[j]>num[j+1])
{
t=num[j];
num[j]=num[j+1];
num[j+1]=t;
}
}
}
printf("the max no= %d ",num[n-1]);
printf("\nThe min no=%d",num[0]);
getch();
/* factorial of a no. [2012] */
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n,fact=1,i;
printf("Enter the value of n:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
fact*=i;
}
printf("fact of n=%d",fact);
getch();
}
/* matrix multiplication of 2_d array. [2012] */
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a[5][5],b[5][5],sum[5][5],i,j,r1,c1,r2,c2,k;
printf("Enter the limit of row 1st matrix:");
scanf("%d",&r1);
printf("\nEnter the limit of column 1st matrix:");
scanf("%d",&c1);
printf("Enter the limit of row 1st matrix:");
scanf("%d",&r2);
printf("\nEnter the limit of column 1st matrix:");
scanf("%d",&c2);
if(c1!=r2)
{
printf("\nerror! column of 1st matrix not equal to row of 2nd matrix");
printf("\nEnter the limit of row 1st matrix:");
scanf("%d",&r1);
printf("\nEnter the limit of column 1st matrix:");
scanf("%d",&c1);
printf("\nEnter the limit of row 2nd matrix:");
scanf("%d",&r2);
printf("\nEnter the limit of column 2nd matrix:");
scanf("%d",&c2);
}
printf("Enter the element:");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Enter the element:");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
scanf("%d",&b[i][j]);
}
}
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
sum[i][j]=0;
for(k=0;k<c2;k++)
{
sum[i][j]+=a[i][k]*b[k][j];
}
}
}
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
printf(" %d",sum[i][j]);
}
printf("\n");
}
getch();
}
/* GCD of 2no using recursion [2012] */
int gcd(int,int);
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,res;
printf("Enter 2no:");
scanf("%d%d",&a,&b);
res=gcd(a,b);
printf("The GCD of a=%d and b=%d is=%d",a,b,res);
getch();
}
int gcd(int x,int y)
{
int r;
r=x%y;
if(r==0)
return(1);
else
return(gcd(y,r));
}
/* implement structure program [2012] */
struct person
{
char name[10] ;
char doj[12];
float salary;
} ;
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
person obj;
printf("Enter employee name:");
gets(obj.name);
printf("\n Enter Date of joining:");
gets(obj.doj);
printf("\n Enter salary:");
scanf("%f",&obj.salary);
printf("\n\nThe employee details are:\n");
printf("Name: %s",obj.name);
printf("\nDate of joining: %s",obj.doj);
printf("\nSalary: %f",obj.salary);
getch();
}
/* s=1^2+2^2+3^2+4^2+...+n^2. [2013] */
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
int s=0,n,i;
printf("Enter the limit:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
s+=pow(i,2);
}
printf("Sum=%d",s);
getch();
}
/* print sum of 1 to n even number using function. [2013] */
#include<stdio.h>
#include<conio.h>
#include<math.h>
int sum(int);
void main()
{
clrscr();
int n,i,r;
printf("Enter the limit:");
scanf("%d",&n);
r=sum(n);
printf("The result is= %d",r);
getch();
}
int sum(int x)
{
int i,s=0;
for(i=1;i<=x;i++)
{
if(i%2==0)
s=s+i;
}
return(s);
}
/* print the natural number 1 to n. [2013] */
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i;
printf("Enter the limit:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("The natural no are:%d",i);
}
getch();
}
/* print integer 1 to n omitting those integers which are divisible by 10 [2013] */
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n,i;
printf("Enter the limit:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(i%10!=0)
printf(" %d",i);
}
getch();
}
/* print biggest among three number using one extra variable [2013] */
#include<stdio.h>
#include<conio.h>
void main()
{
void biggest(int ,int,int,int *);
clrscr();
int a,b,c,r;
printf("Enter 3 no:") ;
scanf("%d%d%d",&a,&b,&c);
biggest(a,b,c,&r);
printf("The biggest no is=%d",r);
getch();
}
void biggest(int x,int y,int z,int *t)
{
if(x>=y&&x>=z)
*t=x;
else if(y>=x&&y>=z)
*t=y;
else
*t=z;
}
/* check a no is prime or not [2013]*/
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n,i,c=0;
printf("Enter any no:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(n%i==0)
c++;
}
if(c<=2)
printf("This no is prime:");
else
printf("This no is not prime:");
getch();
}
/* print the fiboniccy seris of n number using recursion. [2013] */
#include<stdio.h>
#include<conio.h>
void main()
{
int fibo(int);
clrscr();
int n,i;
printf("Enter the limit:");
scanf("%d",&n);
printf(" 0 1 ");
for(i=2;i<=n;i++)
{
printf(" %d",fibo(i));
}
getch();
}
int fibo(int x)
{
if(x==0)
return(0);
else if(x==1)
return (1);
else
return(fibo(x-1)+fibo(x-2));
}
/* find the LCM of two no. [2013] */
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n1,n2,m;
printf("Enter two positive integer:");
scanf("%d%d",&n1,&n2);
m=(n1>n2)?n1:n2;
while(1)
{
if(m%n1==0 && m%n2==0)
{
printf("The LCM of %d and %d is %d",n1,n2,m);
break;
}
++m;
}
getch();
}
QUESTION-2016
3. Write a c program to find the LCM of two integer number.
#include<stdio.h>
int main()
{
int a,b,c;
printf("\n Enter two positive integer :");
scanf("%d %d",&a,&b);
c=(a>b)?a:b;
while(1)
{
if(c%a==0 && c%b==0)
{
printf("\n LCM of %d and %d is %d",a,b,c);
break;
}
c++;
}
return 0;
}
5. Print the following pattern:
*
* * *
* * * * *
#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,k,n;
printf("\n Enter the number of rows :");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(k=1;k<=n-i;k++)
{
printf(" ");
}
for(j=1;j<=(2*i)-1;j++)
{
printf("*");
}
printf("\n");
}
getch();
}
6. Write a c program to reverse a string using pointer concept.
#include <stdio.h>
#include <conio.h>
#include<string.h>
void main()
{
char *s;
int len,i;
clrscr();
printf("\nENTER A STRING: ");
gets(s);
len=strlen(s);
printf("\nTHE REVERSE OF THE STRING IS:");
for(i=len;i>=0;i--)
printf("%c",*(s+i));
getch();
}
7. Write a c program to print sum of three digits prime number.
#include <stdio.h>
int main()
{
int i,j,s,e;
int p,sum=0;
printf("\n Enter lower limit :");
scanf("%d",&s);
printf("\n Enter upper limit :");
scanf("%d",&e);
for(i=s;i<=e;i++)
{
p=1;
for(j=2;j<=i/2;j++)
{
if(i%j==0)
{
p=0;
break;
}
}
if(p==1)
{
sum+=i;
}
}
printf("\n Sum of all prime numbers between %d to %d = %d",s,e,sum);
return 0;
}
9.b. Write a program to interchange the largest and smallest number in the array.
QUESTION-2015
4. Print the pattern:
1 3 5 7 9
3 5 7 9 1
5 7 9 1 3
7 9 1 3 5
9 1 3 5 7
#include<stdio.h>
int main()
{
int i,j,n,d;
for(i=1;i<=10;i=i+2)
{
n=i;
for(j=1;j<=5;j++)
{
d=n%10;
printf("\t %d",d);
n=n+2;
}
printf("\n");
}
return 0;
}
5. Write a c program which will reverse the values in a 1D array of size N.
#include <stdio.h>
#include<conio.h>
int main()
{
int n, c, d, a[100], b[100];
printf("Enter the number of elements in array\n");
scanf("%d", &n);
printf("Enter the array elements\n");
for (c = 0; c < n ; c++)
scanf("%d", &a[c]);
for (c = n - 1, d = 0; c >= 0; c--, d++)
b[d] = a[c];
for (c = 0; c < n; c++)
a[c] = b[c];
printf("Reverse array is\n");
for (c = 0; c < n; c++)
printf("%d\n", a[c]);
getch();
return 0;
}
7.c. Write a program to print the 1st 100 Fibonacci number using recursive function.
#include<stdio.h>
int Fibonacci(int);
int main()
{
int n, i = 0, c;
printf("Enter the limit :");
scanf("%d",&n);
printf("\n Fibonacci series\n");
for ( c = 1 ; c <= n ; c++ )
{
printf("%d\n", Fibonacci(i));
i++;
}
return 0;
}
int Fibonacci(int n)
{
if ( n == 0 )
return 0;
else if ( n == 1 )
return 1;
else
return ( Fibonacci(n-1) + Fibonacci(n-2) );
}
8.c. Print this pattern:
1
0
1 0 1
1 0 1 0
#include<stdio.h>
int main()
{
int i,j,k;
for(i=1;i<=4;i++)
{
for(j=3;j>=i;j--)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
if(j%2==0)
printf("%d ",0);
else
printf("%d ",1);
}
printf("\n");
}
return 0;
}
9.Write a c program to calculate sin(x) from
Sin(x)=x - x3/3! + x5/5! - x7/7!.... with an accuracy of 10^-5.
10. Write a c program to find the prime factors of a number .
#include <stdio.h>
int main()
{
int i, j, num, Prime;
printf("Enter any number to print Prime factors: ");
scanf("%d", &num);
printf("All Prime Factors of %d are: \n", num);
for(i=2; i<=num; i++)
{
if(num%i==0)
{
Prime = 1;
for(j=2; j<=i/2; j++)
{
if(i%j==0)
{
Prime = 0;
break;
}
}
if(Prime==1)
{
printf("%d, ", i);
}
}
}
return 0;
}
QUESTION-2014
5. Write a c program to print the sum of the following series of n term :
S = 1+(1+2) + (1+2+3)+……
#include<stdio.h>
int main()
{
int i,j,k;
for(i=1;i<=4;i++)
{
for(j=3;j>=i;j--)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
if(j%2==0)
printf("%d ",0);
else
printf("%d ",1);
}
printf("\n");
}
return 0;
}
6. Write a c programming in c to add two complex numbers.
#include <stdio.h>
struct complex
{
int real, img;
};
int main()
{
struct complex a, b, c;
printf("Enter a and b where a + ib is the first complex number.\n");
scanf("%d%d", &a.real, &a.img);
printf("Enter c and d where c + id is the second complex number.\n");
scanf("%d%d", &b.real, &b.img);
c.real = a.real + b.real;
c.img = a.img + b.img;
printf("Sum of the complex numbers: (%d) + (%di)\n", c.real, c.img);
return 0;
}
7. Write a recursive function for n p r calculation.
#include<stdio.h>
int fact(int n)
{
if (n <= 1)
return 1;
return n*fact(n-1);
}
int nPr(int n, int r)
{
return fact(n)/fact(n-r);
}
int main()
{
int n, r;
printf("Enter n: ");
scanf("%d", &n);
printf("Enter r: ");
scanf("%d", &r);
printf("%dP%d is %d", n, r, nPr(n, r));
return 0;
}
8. Write a program to check the number is prime or not.
#include<stdio.h>
#include<conio.h>
int main()
{
int i,n,count=0;
printf("\n Enter the number :");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(n%i == 0)
{
count++;
}
}
if(count==2)
printf("\n Prime number");
else
printf("\n Not Prime number");
getch();
}
9. Write a c program that implements the matrix transpose using 2-D array.
#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,mat[2][2],transpose_mat[2][2];
printf("\n Enter the elements of the matrix :");
printf("\n ***************************************");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
scanf("%d",&mat[i][j]);
}
}
printf("\n The elements of the matrix are :");
printf("\n ***************************************");
for(i=0;i<2;i++)
{
printf("\n");
for(j=0;j<2;j++)
printf(" %d",mat[i][j]);
}
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
transpose_mat[i][j]=mat[j][i];
}
printf("\n The elements of the matrix are :");
printf("\n ***************************************");
for(i=0;i<2;i++)
{
printf("\n");
for(j=0;j<2;j++)
printf(" %d",transpose_mat[i][j]);
}
getch();
}
10. Write a c program to print the Fibonacci sequence of n number.
#include <stdio.h>
int main()
{
int i, n, t1 = 0, t2 = 1, T;
printf("Enter the number of terms: ");
scanf("%d", &n);
printf("Fibonacci Series: ");
for (i = 1; i <= n; ++i)
{
printf("%d, ", t1);
T = t1 + t2;
t1 = t2;
t2 = T;
}
return 0;
}
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n,r,s=0;
printf("Enter any no:");
scanf("%d",&n);
while(n!=0)
{
r=n%10;
s=s*10+r;
n=n/10;
}
printf("result= %d",s-9);
getch();
}
/* print the series as given along with the sum. 1-2+3-4+5-....n.[2010] */
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n,i,s=0,flag=0;
printf("Enter the limit:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(flag==0)
{
s+=i;
flag=!flag;
}
else if(flag==1)
{
s-=i;
flag=!flag;
}
}
printf(" sum= %d",s);
getch();
}
/* reverse a string without using strrev() funtion.[2010] */
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
char str[5],str2[5];
int l=0,i=0,k=0;
printf("Enter any string=");
gets(str);
while(str[i]!='\0')
{
l++;
i++;
}
l=l-1;
while(l>=0)
{
str2[k]=str[l];
k++;
l--;
}
puts(str2);
getch();
}
/* swap the values between two variable using pointer. [2010] */
void swap(int *,int *);
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
printf("Enter the value of a and b:");
scanf("%d%d",&a,&b);
swap(&a,&b);
printf("\nAfter swaping the value of a= %d and b= %d",a,b);
getch();
}
void swap(int *x,int *y)
{
int t;
t=*x;
*x=*y;
*y=t;
}
/* convert decimal to binary number [2010]*/
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int arr[10],n,i=0,r=0;
printf("Enter the decimal no:");
scanf("%d",&n);
while(n>0)
{
arr[i]=n%2;
n=n/2;
i++;
r++;
}
for(i=r-1;i>=0;i--)
{
printf("%d",arr[i]);
}
getch();
}
/* s=1+(1+2)+(1+2+3)... [2011] */
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,s=0,n;
printf("Enter the limit:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
s+=j;
}
}
printf("sum= %d",s);
getch();
}
/* find the max or min no from n no of set [2011] */
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int num[100],n,i,t,j;
printf("How many no you enter");
scanf("%d",&n);
printf("Enter the no");
for(i=0;i<n;i++)
{
scanf("%d",&num[i]);
}
for(i=0;i<n;i++)
{
for( j=0;j<n-i;j++)
{
if(num[j]>num[j+1])
{
t=num[j];
num[j]=num[j+1];
num[j+1]=t;
}
}
}
printf("the max no= %d ",num[n-1]);
printf("\nThe min no=%d",num[0]);
getch();
/* factorial of a no. [2012] */
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n,fact=1,i;
printf("Enter the value of n:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
fact*=i;
}
printf("fact of n=%d",fact);
getch();
}
/* matrix multiplication of 2_d array. [2012] */
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a[5][5],b[5][5],sum[5][5],i,j,r1,c1,r2,c2,k;
printf("Enter the limit of row 1st matrix:");
scanf("%d",&r1);
printf("\nEnter the limit of column 1st matrix:");
scanf("%d",&c1);
printf("Enter the limit of row 1st matrix:");
scanf("%d",&r2);
printf("\nEnter the limit of column 1st matrix:");
scanf("%d",&c2);
if(c1!=r2)
{
printf("\nerror! column of 1st matrix not equal to row of 2nd matrix");
printf("\nEnter the limit of row 1st matrix:");
scanf("%d",&r1);
printf("\nEnter the limit of column 1st matrix:");
scanf("%d",&c1);
printf("\nEnter the limit of row 2nd matrix:");
scanf("%d",&r2);
printf("\nEnter the limit of column 2nd matrix:");
scanf("%d",&c2);
}
printf("Enter the element:");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Enter the element:");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
scanf("%d",&b[i][j]);
}
}
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
sum[i][j]=0;
for(k=0;k<c2;k++)
{
sum[i][j]+=a[i][k]*b[k][j];
}
}
}
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
printf(" %d",sum[i][j]);
}
printf("\n");
}
getch();
}
/* GCD of 2no using recursion [2012] */
int gcd(int,int);
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,res;
printf("Enter 2no:");
scanf("%d%d",&a,&b);
res=gcd(a,b);
printf("The GCD of a=%d and b=%d is=%d",a,b,res);
getch();
}
int gcd(int x,int y)
{
int r;
r=x%y;
if(r==0)
return(1);
else
return(gcd(y,r));
}
/* implement structure program [2012] */
struct person
{
char name[10] ;
char doj[12];
float salary;
} ;
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
person obj;
printf("Enter employee name:");
gets(obj.name);
printf("\n Enter Date of joining:");
gets(obj.doj);
printf("\n Enter salary:");
scanf("%f",&obj.salary);
printf("\n\nThe employee details are:\n");
printf("Name: %s",obj.name);
printf("\nDate of joining: %s",obj.doj);
printf("\nSalary: %f",obj.salary);
getch();
}
/* s=1^2+2^2+3^2+4^2+...+n^2. [2013] */
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
int s=0,n,i;
printf("Enter the limit:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
s+=pow(i,2);
}
printf("Sum=%d",s);
getch();
}
/* print sum of 1 to n even number using function. [2013] */
#include<stdio.h>
#include<conio.h>
#include<math.h>
int sum(int);
void main()
{
clrscr();
int n,i,r;
printf("Enter the limit:");
scanf("%d",&n);
r=sum(n);
printf("The result is= %d",r);
getch();
}
int sum(int x)
{
int i,s=0;
for(i=1;i<=x;i++)
{
if(i%2==0)
s=s+i;
}
return(s);
}
/* print the natural number 1 to n. [2013] */
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i;
printf("Enter the limit:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("The natural no are:%d",i);
}
getch();
}
/* print integer 1 to n omitting those integers which are divisible by 10 [2013] */
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n,i;
printf("Enter the limit:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(i%10!=0)
printf(" %d",i);
}
getch();
}
/* print biggest among three number using one extra variable [2013] */
#include<stdio.h>
#include<conio.h>
void main()
{
void biggest(int ,int,int,int *);
clrscr();
int a,b,c,r;
printf("Enter 3 no:") ;
scanf("%d%d%d",&a,&b,&c);
biggest(a,b,c,&r);
printf("The biggest no is=%d",r);
getch();
}
void biggest(int x,int y,int z,int *t)
{
if(x>=y&&x>=z)
*t=x;
else if(y>=x&&y>=z)
*t=y;
else
*t=z;
}
/* check a no is prime or not [2013]*/
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n,i,c=0;
printf("Enter any no:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(n%i==0)
c++;
}
if(c<=2)
printf("This no is prime:");
else
printf("This no is not prime:");
getch();
}
/* print the fiboniccy seris of n number using recursion. [2013] */
#include<stdio.h>
#include<conio.h>
void main()
{
int fibo(int);
clrscr();
int n,i;
printf("Enter the limit:");
scanf("%d",&n);
printf(" 0 1 ");
for(i=2;i<=n;i++)
{
printf(" %d",fibo(i));
}
getch();
}
int fibo(int x)
{
if(x==0)
return(0);
else if(x==1)
return (1);
else
return(fibo(x-1)+fibo(x-2));
}
/* find the LCM of two no. [2013] */
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n1,n2,m;
printf("Enter two positive integer:");
scanf("%d%d",&n1,&n2);
m=(n1>n2)?n1:n2;
while(1)
{
if(m%n1==0 && m%n2==0)
{
printf("The LCM of %d and %d is %d",n1,n2,m);
break;
}
++m;
}
getch();
}
QUESTION-2016
3. Write a c program to find the LCM of two integer number.
#include<stdio.h>
int main()
{
int a,b,c;
printf("\n Enter two positive integer :");
scanf("%d %d",&a,&b);
c=(a>b)?a:b;
while(1)
{
if(c%a==0 && c%b==0)
{
printf("\n LCM of %d and %d is %d",a,b,c);
break;
}
c++;
}
return 0;
}
5. Print the following pattern:
*
* * *
* * * * *
#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,k,n;
printf("\n Enter the number of rows :");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(k=1;k<=n-i;k++)
{
printf(" ");
}
for(j=1;j<=(2*i)-1;j++)
{
printf("*");
}
printf("\n");
}
getch();
}
6. Write a c program to reverse a string using pointer concept.
#include <stdio.h>
#include <conio.h>
#include<string.h>
void main()
{
char *s;
int len,i;
clrscr();
printf("\nENTER A STRING: ");
gets(s);
len=strlen(s);
printf("\nTHE REVERSE OF THE STRING IS:");
for(i=len;i>=0;i--)
printf("%c",*(s+i));
getch();
}
7. Write a c program to print sum of three digits prime number.
#include <stdio.h>
int main()
{
int i,j,s,e;
int p,sum=0;
printf("\n Enter lower limit :");
scanf("%d",&s);
printf("\n Enter upper limit :");
scanf("%d",&e);
for(i=s;i<=e;i++)
{
p=1;
for(j=2;j<=i/2;j++)
{
if(i%j==0)
{
p=0;
break;
}
}
if(p==1)
{
sum+=i;
}
}
printf("\n Sum of all prime numbers between %d to %d = %d",s,e,sum);
return 0;
}
9.b. Write a program to interchange the largest and smallest number in the array.
QUESTION-2015
4. Print the pattern:
1 3 5 7 9
3 5 7 9 1
5 7 9 1 3
7 9 1 3 5
9 1 3 5 7
#include<stdio.h>
int main()
{
int i,j,n,d;
for(i=1;i<=10;i=i+2)
{
n=i;
for(j=1;j<=5;j++)
{
d=n%10;
printf("\t %d",d);
n=n+2;
}
printf("\n");
}
return 0;
}
5. Write a c program which will reverse the values in a 1D array of size N.
#include <stdio.h>
#include<conio.h>
int main()
{
int n, c, d, a[100], b[100];
printf("Enter the number of elements in array\n");
scanf("%d", &n);
printf("Enter the array elements\n");
for (c = 0; c < n ; c++)
scanf("%d", &a[c]);
for (c = n - 1, d = 0; c >= 0; c--, d++)
b[d] = a[c];
for (c = 0; c < n; c++)
a[c] = b[c];
printf("Reverse array is\n");
for (c = 0; c < n; c++)
printf("%d\n", a[c]);
getch();
return 0;
}
7.c. Write a program to print the 1st 100 Fibonacci number using recursive function.
#include<stdio.h>
int Fibonacci(int);
int main()
{
int n, i = 0, c;
printf("Enter the limit :");
scanf("%d",&n);
printf("\n Fibonacci series\n");
for ( c = 1 ; c <= n ; c++ )
{
printf("%d\n", Fibonacci(i));
i++;
}
return 0;
}
int Fibonacci(int n)
{
if ( n == 0 )
return 0;
else if ( n == 1 )
return 1;
else
return ( Fibonacci(n-1) + Fibonacci(n-2) );
}
8.c. Print this pattern:
1
0
1 0 1
1 0 1 0
#include<stdio.h>
int main()
{
int i,j,k;
for(i=1;i<=4;i++)
{
for(j=3;j>=i;j--)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
if(j%2==0)
printf("%d ",0);
else
printf("%d ",1);
}
printf("\n");
}
return 0;
}
9.Write a c program to calculate sin(x) from
Sin(x)=x - x3/3! + x5/5! - x7/7!.... with an accuracy of 10^-5.
10. Write a c program to find the prime factors of a number .
#include <stdio.h>
int main()
{
int i, j, num, Prime;
printf("Enter any number to print Prime factors: ");
scanf("%d", &num);
printf("All Prime Factors of %d are: \n", num);
for(i=2; i<=num; i++)
{
if(num%i==0)
{
Prime = 1;
for(j=2; j<=i/2; j++)
{
if(i%j==0)
{
Prime = 0;
break;
}
}
if(Prime==1)
{
printf("%d, ", i);
}
}
}
return 0;
}
QUESTION-2014
5. Write a c program to print the sum of the following series of n term :
S = 1+(1+2) + (1+2+3)+……
#include<stdio.h>
int main()
{
int i,j,k;
for(i=1;i<=4;i++)
{
for(j=3;j>=i;j--)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
if(j%2==0)
printf("%d ",0);
else
printf("%d ",1);
}
printf("\n");
}
return 0;
}
6. Write a c programming in c to add two complex numbers.
#include <stdio.h>
struct complex
{
int real, img;
};
int main()
{
struct complex a, b, c;
printf("Enter a and b where a + ib is the first complex number.\n");
scanf("%d%d", &a.real, &a.img);
printf("Enter c and d where c + id is the second complex number.\n");
scanf("%d%d", &b.real, &b.img);
c.real = a.real + b.real;
c.img = a.img + b.img;
printf("Sum of the complex numbers: (%d) + (%di)\n", c.real, c.img);
return 0;
}
7. Write a recursive function for n p r calculation.
#include<stdio.h>
int fact(int n)
{
if (n <= 1)
return 1;
return n*fact(n-1);
}
int nPr(int n, int r)
{
return fact(n)/fact(n-r);
}
int main()
{
int n, r;
printf("Enter n: ");
scanf("%d", &n);
printf("Enter r: ");
scanf("%d", &r);
printf("%dP%d is %d", n, r, nPr(n, r));
return 0;
}
8. Write a program to check the number is prime or not.
#include<stdio.h>
#include<conio.h>
int main()
{
int i,n,count=0;
printf("\n Enter the number :");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(n%i == 0)
{
count++;
}
}
if(count==2)
printf("\n Prime number");
else
printf("\n Not Prime number");
getch();
}
9. Write a c program that implements the matrix transpose using 2-D array.
#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,mat[2][2],transpose_mat[2][2];
printf("\n Enter the elements of the matrix :");
printf("\n ***************************************");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
scanf("%d",&mat[i][j]);
}
}
printf("\n The elements of the matrix are :");
printf("\n ***************************************");
for(i=0;i<2;i++)
{
printf("\n");
for(j=0;j<2;j++)
printf(" %d",mat[i][j]);
}
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
transpose_mat[i][j]=mat[j][i];
}
printf("\n The elements of the matrix are :");
printf("\n ***************************************");
for(i=0;i<2;i++)
{
printf("\n");
for(j=0;j<2;j++)
printf(" %d",transpose_mat[i][j]);
}
getch();
}
10. Write a c program to print the Fibonacci sequence of n number.
#include <stdio.h>
int main()
{
int i, n, t1 = 0, t2 = 1, T;
printf("Enter the number of terms: ");
scanf("%d", &n);
printf("Fibonacci Series: ");
for (i = 1; i <= n; ++i)
{
printf("%d, ", t1);
T = t1 + t2;
t1 = t2;
t2 = T;
}
return 0;
}
No comments:
Post a Comment