11. Program to accept three numbers from user and print them in ascending and decending order.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("Enter numbers:");
scanf("%d%d%d",&a,&b,&c);
if((a>=b)&&(a>=c))
{
if(b>=c)
{
printf("\n Descending order:
%d %d %d",a,b,c);
printf("\n Ascending order :
%d %d %d",c,b,a);
}
else
{
printf("\n Descending order :
%d %d %d",a,c,b);
printf("\n Ascending order :
%d %d %d",b,c,a);
}
}
else if((b>=a)&&(b>=c))
{
if(a>=c)
{
printf("\n Descending order :
%d %d %d",b,a,c);
}
}
getch();
}
12. Program to find the roots of a quadratic equation.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a, b, c, determinant, real;
double r1, r2, imag;
printf("Enter coefficients a, b and c: ");
scanf("%f%f%f", &a, &b, &c);
determinant = b * b - 4 * a * c;
if (determinant > 0)
{
r1 = (-b + sqrt(determinant)) / (2 * a);
r2 = (-b - sqrt(determinant)) / (2 * a);
printf("Roots are: %.2f and %.2f", r1, r2);
}
else if (determinant == 0)
{
r1 = r2 = -b / (2 * a);
printf("Roots are: %.2f and %.2f", r1, r2)
}
else
{
real = -b / (2 * a);
imag = sqrt(-determinant) / (2 * a);
printf("Roots are: %.2f+%.2fi and %.2f-%.2fi", real, imag, real, imag);
}
getch();
}
13. Program to accept rollnumber and marks of three subjects from user and print total marks, average and grade.
#include<stdio.h>
#include<conio.h>
void main()
{
int RollNum, m1, m2, m3, total;
float avg;
clrscr();
printf("Enter Roll Number : ");
scanf("%d",&RollNum);
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>80)
printf("\nGrade : A");
else if((avg>60)&&(avg<=80))
printf("\nGrade : B");
else if((avg>40)&&(avg<=60))
printf("\nGrade : C");
else if((avg>=33)&&(avg<=40)
printf("\nGrade : D");
else
printf("\nGrade : Fail");
getch();
}
14. Program to print numbers from 1 to n using while loop.
#include<stdio.h>
#include<conio.h>
void main()
{
int i=1, n;
clrscr();
printf("Enter n : ");
scanf("%d", &n);
while(i<=n)
{
printf("%d\t",i);
i++;
}
getch();
}
15. Program to print numbers from n to 1 using Do While loop.
#include<stdio.h>
#include<conio.h>
void main()
{
int i=1, n;
clrscr();
printf("Enter n : ");
scanf("%d", &n);
i=n;
do
{
printf("%d\t",i);
i--;
}while(i>=1);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("Enter numbers:");
scanf("%d%d%d",&a,&b,&c);
if((a>=b)&&(a>=c))
{
if(b>=c)
{
printf("\n Descending order:
%d %d %d",a,b,c);
printf("\n Ascending order :
%d %d %d",c,b,a);
}
else
{
printf("\n Descending order :
%d %d %d",a,c,b);
printf("\n Ascending order :
%d %d %d",b,c,a);
}
}
else if((b>=a)&&(b>=c))
{
if(a>=c)
{
printf("\n Descending order :
%d %d %d",b,a,c);
}
}
getch();
}
12. Program to find the roots of a quadratic equation.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a, b, c, determinant, real;
double r1, r2, imag;
printf("Enter coefficients a, b and c: ");
scanf("%f%f%f", &a, &b, &c);
determinant = b * b - 4 * a * c;
if (determinant > 0)
{
r1 = (-b + sqrt(determinant)) / (2 * a);
r2 = (-b - sqrt(determinant)) / (2 * a);
printf("Roots are: %.2f and %.2f", r1, r2);
}
else if (determinant == 0)
{
r1 = r2 = -b / (2 * a);
printf("Roots are: %.2f and %.2f", r1, r2)
}
else
{
real = -b / (2 * a);
imag = sqrt(-determinant) / (2 * a);
printf("Roots are: %.2f+%.2fi and %.2f-%.2fi", real, imag, real, imag);
}
getch();
}
13. Program to accept rollnumber and marks of three subjects from user and print total marks, average and grade.
#include<stdio.h>
#include<conio.h>
void main()
{
int RollNum, m1, m2, m3, total;
float avg;
clrscr();
printf("Enter Roll Number : ");
scanf("%d",&RollNum);
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>80)
printf("\nGrade : A");
else if((avg>60)&&(avg<=80))
printf("\nGrade : B");
else if((avg>40)&&(avg<=60))
printf("\nGrade : C");
else if((avg>=33)&&(avg<=40)
printf("\nGrade : D");
else
printf("\nGrade : Fail");
getch();
}
14. Program to print numbers from 1 to n using while loop.
#include<stdio.h>
#include<conio.h>
void main()
{
int i=1, n;
clrscr();
printf("Enter n : ");
scanf("%d", &n);
while(i<=n)
{
printf("%d\t",i);
i++;
}
getch();
}
15. Program to print numbers from n to 1 using Do While loop.
#include<stdio.h>
#include<conio.h>
void main()
{
int i=1, n;
clrscr();
printf("Enter n : ");
scanf("%d", &n);
i=n;
do
{
printf("%d\t",i);
i--;
}while(i>=1);
getch();
}
0 comments:
Post a Comment