What are Decisions and how computer processes it? Syntax for Decision Control Structures and programs on Decision Control Structures.
- 014. Write a program to accept two number and print largest among them in C language
#include<stdio.h> #include<conio.h> main() { int a,b; clrscr(); printf("Enter numbers : "); scanf("%d%d",&a,&b); if(a>b) printf("Largest value is....%d",a); else printf("Largest value is....%d",b); getch(); }
- 015. Write a program to accept a number and print if the number is Positive/Negative in C language
#include<stdio.h> #include<conio.h> main() { int n; clrscr(); printf("Enter number.."); scanf("%d",&n); if(n>0) printf("Given number is positive"); else if(n<0) printf("Given number is negative"); else printf("Number is Zero"); getch(); }
- 016. Write a program to accept a number and check if it is >10, <10 or =10 in C language
#include<stdio.h> #include<conio.h> main() { int n; clrscr(); printf("enter number..."); scanf("%d",&n); if(n>10) printf("Number is greater than 10"); else if(n<10) printf("Number is lesser than 10"); else printf("Number is 10"); getch(); }
- 017. Write a program to accept a number from user and print if it is even or odd in C language
#include<stdio.h> #include<conio.h> main() { int n; clrscr(); printf("Enter number..."); scanf("%d",&n); if(n%2==0) printf("Number is even..."); else printf("Number is odd...."); getch(); }
- 018. Write a program to accept a number from user and print if it is divisible by 5 in C language
#include<stdio.h> #include<conio.h> main() { int n; clrscr(); printf("Enter number..."); scanf("%d",&n); if(n%5==0) printf("Number is divisible by 5."); else printf("Number is not divisible by 5."); getch(); }
- 019. Write a program to accept a number from user and print if it is multiple of 7 in C language
#include<stdio.h> #include<conio.h> main() { int n; clrscr(); printf("Enter number..."); scanf("%d",&n); if(n%7==0) printf("Number is multiple of 7"); else printf("Number is not multiple of 7"); getch(); }
- 020. Write a program to accept two numbers from user and compare them in C language
#include<stdio.h> #include<conio.h> main() { int a,b; clrscr(); printf("Enter numbers..."); scanf("%d%d",&a,&b); if(a>b) printf("a is greater than b"); else if(b>a) printf("b is greater than a"); else printf("both are equal"); getch(); }
- 021. Write a program to accept three numbers from user and print them in ascending and descending order in C language
#include<stdio.h> void main() { int a,b,c; 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); printf("\n Ascending order : %d %d %d",c,a,b); } else { printf("\n Descending order : %d %d %d",b,c,a); printf("\n Ascending order : %d %d %d",a,c,b); } } else if((c>=a)&&(c>=b)) { if(a>=b) { printf("\n Descending order : %d %d %d",c,a,b); printf("\n Ascending order : %d %d %d",b,a,c); } else { printf("\n Descending order : %d %d %d",c,b,a); printf("\n Ascending order : %d %d %d",a,b,c); } } }
- 022. 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<0 -> roots are imaginary#include<stdio.h> #include<conio.h> main() { float x,r1,r2,a,b,c; clrscr(); printf("Enter a,b,c..."); scanf("%f%f%f",&a,&b,&c); x=b*b-4*a*c; r1=(-b+x)/2*a; r2=(-b-x)/2*a; if(x>0) printf("\nRoots are unequal...\n"); else if(x<0) printf("\nRoots are imaginary...\n"); else printf("\nRoots are same....\n"); printf("R1 = %f",r1); printf("R2 = %f",r2); getch(); }
- 023. 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<60,Avg >=50 Grade B
Avg<50,Avg >=40 Grade CGrade 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(); }
- 024. Write a Program to accept user’s marital status, gender and age to check if he/she is eligible for marriage or not.
#include<stdio.h> #include<conio.h> main() { int age; char MaritalStatus,Gender; clrscr(); printf("Enter MaritalStatus, Gender, Age : (e.g. m,f,25) : "); scanf("%c,%c,%d",&MaritalStatus,&Gender,&age); if(MaritalStatus=='m') { printf("You can not marry!"); } else if(MaritalStatus=='u') { if(Gender=='m') { if(age>=21) printf("You can marry!"); else printf("You can not marry!"); } else if(Gender=='f') { if(age>=18) printf("You can marry!"); else printf("You can not marry!"); } else printf("Invalid input Gender"); } else printf("Invalid input Marital Status "); getch(); }