programming like c, c++, java,python learn in free

Tuesday, May 26, 2020

C programming Question and Answer Day-3

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();
}
Share:

0 comments:

Post a Comment

Unordered List

recentposts1
Powered by Blogger.

Text Widget

Featured Post

C programming Question and Answer Day-15

71. Program to check Niven number (Harshad number). #include<stdio.h> #include<conio.h> void main() {     int n, d, a, su...

Search This Blog

recent comments

recentcomments

Labels

[slideshow][technology]

vertical posts

[verticalposts][technology]

business

[business][grids]

ad space

ads 600

vehicles

[cars][stack]
[verticalposts][food]

our facebook page

about us

logo

Jupiter is a magazine responsive Blogger template. It has everything you need to make your blog stand out. This template is fully customizable and very flexible and we believe you will love it as much as we do.

Slide show

[people][slideshow]

health

[health][btop]

recent posts

recentposts1

Subscribe Us

random posts

randomposts2

Blog Archive

Recent Posts

top ads

Unordered List

recent

Pages

Theme Support

[socialcounter] [facebook][#][215K] [twitter][#][115K] [youtube][#][215,635] [rss][#][23M] [linkedin][#][21.5K] [instagram][#][600,300]