Program to show swap of two no’s without using third variable.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf(“enter value for a & b: ”);
scanf(“%d%d”,&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf(“after swapping the value of a & b: %d %d”,a,b);
getch();
}
Program to find greatest in 3 numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf(“enter value of a, b & c: ”);
scanf(“%d%d%d”,&a,&b,&c);
if((a>b)&&(a>c))
printf(“a is greatest”);
if((b>c)&&(b>a))
printf(“b is greatest”);
if((c>a)&&(c>b))
printf(“c is greatest”);
getch();
}
write a program to calculate roots of a quadratic equations in C language x=b^2-4ac
if x=0 -> only one root ,
if x>0 -> roots are distinct (–b+x)/2a & (–b-x)/2a
if x roots are imaginary
Write a program to accept roll number ,and marks for three subjects, print total marks and
average, also print grade by considering following conditions
Avg>=60 Grade A
Avg=50 Grade B
Avg=40 Grade C
Grade F.
#include<stdio.h>
#include<conio.h>
main()
{
int RollNumber,m1,m2,m3,total;
float avg;
clrscr();
printf("Enter Roll Number : ");
scanf("%d",&RollNumber);
printf("Enter marks for three subjects : ");
scanf("%d%d%d",&m1,&m2,&m3);
total=m1+m2+m3;
avg=total/3.0;
printf("\nTotal is……. %d",total);
printf("\nAverage is….. %5.2f %",avg);
if(avg>=60)
printf("\nGrade : A");
else if((avg>=50)&&(avg<60))
printf("\nGrade : B");
else if((avg>=40)&&(avg<50))
printf("\nGrade : C");
else
printf("\nGrade : F");
getch();
}
Write a Program to accept a number and print the number in reverse order.
E.g. if 1324 is the number then the output will be 4231
#include<stdio.h>
#include<conio.h>
main()
{
int rem,n;
clrscr();
printf("Enter n : ");
scanf("%d",&n);
while(n>0)
{
rem=n%10;
printf("%d",rem);
n=n/10;
}
getch();
}
Write a Program to accept a number and print sum of it’s digits
#include<stdio.h>
#include<conio.h>
main()
{
int rem,sum=0,n
clrscr();
printf("Enter n : ");
scanf("%d",&n);
while(n>0)
{
rem=n%10;
sum=sum+rem;
n=n/10;
}
printf("Sum of digits….%d",sum);
getch();
}
Write a program to accept a number from user and check it it is Armstrong number or not
i.e. 153 = 1^3 + 5^3 + 3^3 = 153
#include<stdio.h>
#include<conio.h>
main()
{
int i=2,temp,rem,sum=0 ,n;
clrscr();
printf("Enter n : ");
scanf("%d",&n);
temp=n;
while(n>0)
{
rem=n%10;
sum=sum+rem*rem*rem;
n=n/10;
}
if(temp==sum)
printf("Armstrong Number");
else
printf("Not an Armstrong Number");
getch();
}
Write a program to print table of a given number n
#include<stdio.h>
#include<conio.h>
main()
{
int i,n;
clrscr();
printf("Enter number : ");
scanf("%d",&n);
for(i=1;i<=10;i++)
printf("%d X %d = %d\n",n,i,n*i);
getch();
}
Write a program to print sum of given first n numbers
#include<stdio.h>
#include<conio.h>
main()
{
int n,newn,i,sum=0;
clrscr();
printf("enter number : ");
scanf("%d",&n);
printf("Numbers entered….\n");
for(i=1;i<=n;i++)
{
scanf("%d",&newn);
sum=sum+newn;
}
printf("Sum of given n digits is… %d",sum);
}
Write a program to accept a number from user and print it’s factorial
Eg: factorial of 5 is:-5! = 5 * 4 * 3 * 2 * 1=120
#include<stdio.h>
#include<conio.h>
main()
{
int i,fact=1,n;
clrscr();
printf("Enter number…");
scanf("%d",&n);
for(i=1;i<=n;i++)
fact=fact*i;
printf("facttorialof the given number is…%d",fact);
getch();
}
Write a program to accept a number from user and print if it is prime or not
Write a program to accept a number from user and print it’s factorial, check if it prime or not ,
and print it’s fibbonacci series using different functions in C language
#include<stdio.h>
#include<conio.h>
fact(int x)
{
int i,fact=1;
for(i=1;i<=x;i++)
fact=fact*i;
printf("Factorial is : %d",fact);
}
IsPrime(int x)
{
int i;
for(i=2;i<x-1;i++)
{
if(x%i==0)
{
printf("\nNot a Prime Number\n");
return 0;
}
}
printf("\nIt is a Prime number\n");
}
fibbo(int x)
{
int pre=1,cur=1,i,temp;
printf("%d %d",pre,cur);
for(i=3;i<=x;i++)
{
temp=cur;
cur=pre+cur;
pre=temp;
printf(" %d",cur);
}
}
main()
{
int n;
clrscr();
printf("Enter number…");
scanf("%d",&n);
fact(n);
IsPrime(n);
fibbo(n);
getch();
}
Write a program using recursions for fibbonacci series in C language
#include<stdio.h>
#include<conio.h>
#include<process.h>
fibbo(int pre, int cur ,int x)
{
int temp;
if(x==2)
{
getch();
exit(0);
}
temp=cur;
cur=pre+cur;
pre=temp;
printf("%d ",cur);
fibbo(pre,cur,x-1);
}
main()
{
int n,pre=1,cur=1;
clrscr();
printf("Enter number : ");
scanf("%d",&n);
printf("%d %d ",pre,cur);
fibbo(pre,cur,n);
getch();
}
Write a program using reccursions for fibbionacci series factorial in C language
#include<stdio.h>
#include<conio.h>
#include<process.h>
int fact(int n)
{
int f;
if(n==1)
return 1;
else
f=n*fact(n-1);
return f;
}
main()
{
int n;
clrscr();
printf("Enter number : ");
scanf("%d",&n);
printf("\nFactorial is…%d\n",fact(n));
getch();
}
Write a program to accept a number n from user and then accept n array elements from user
and reprint them in C language
Write a program to accept a number n from user and then accept n array elements from user and
print addition of those n array elements in C language
#include<stdio.h>
#include<conio.h>
main()
{
int n,i,a[20],sum=0;
clrscr();
printf("Enter number…");
scanf("%d",&n);
printf("Enter array elements :\n" );
for(i=0;i<n;i++)
{
printf("Enter element %d : ",i+1);
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
sum=sum+a[i];
printf("\nSum of given array elements is : %d",sum);
getch();
}
Write a program to accept a number n from user and print fibbonacci series up to nth level
using arrays in C language
#include<stdio.h>
#include<conio.h>
main()
{
int a[20],n,i;
clrscr();
printf("Enter number : ");
scanf("%d",&n);
a[1]=a[2]=1;
for(i=3;i<=n;i++)
a[i]=a[i-1]+a[i-2];
for(i=1;i<=n;i++)
printf(" %d",a[i]);
getch();
}
Write a program to accept a number n from user and then accept n array elements from user and
print maximum and minimum array element from that set of array in C language
Write a program to accept a number n from user and then accept n array elements from user,
print positive & Negative numbers separately in C language
#include<stdio.h>
#include<conio.h>
main()
{
int n,i,a[20];
clrscr();
printf("Enter number : ");
scanf("%d",&n);
printf("Enter array elements…\n");
for(i=0;i<n;i++)
{
printf("Enter element %d : ",i+1);
scanf("%d",&a[i]);
}
printf("\n\nNegative Elements : \n");
for(i=0;i<n;i++)
if(a[i]<0)
printf("\n%d",a[i]);
printf("\n\nPositive Elements : \n");
for(i=0;i<n;i++)
if(a[i]>0)
printf("\n%d",a[i]);
getch();
}
Write a program to accept a number n from user and then accept n array elements from user,
print these array elements in ascending and descending order in C language
No comments:
Post a Comment
Please write your view and suggestion....