INDEX
- A C Program to accept Week-day no. and display the Day-name
- A C Program to accept Month-number and display Month-name.
- A C Program to accept colour-code and display colour-name (0-black,1-red,2-green,3-blue,4-white).
- A C Program to accept month-number and display the number of days in that month.
- A C Program to accept two numbers and an operator(+,-,x,/) then perform appropriate calculation as per the operator entered
- A C Program to Display a menu regarding different kinds of formula, and then based upon user’s choice perform necessary operations.
//A C Program to accept Week-day no. and display the Day-name. Assuming Day1 as Sunday
#include<stdio.h>
int main()
{
int day_num;
printf("\nEnter day number of the week: ");
scanf(“%d”,&day_num);
switch(day_num)
{
case 1:
printf("\nSelected day is SUNDAY.");
break;
case 2:
printf("\nSelected day is MONDAY.");
break;
case 3:
printf("\nSelected day is TUESDAY.");
break;
case 4:
printf("\nSelected day is WEDNESDAY.");
break;
case 5:
printf("\nSelected day is THURSDAY.");
break;
case 6:
printf("\nSelected day is FRIDAY.");
break;
case 7:
printf("\nSelected day is SATURDAY.");
break;
default:
printf("\nError!!! Invalid Day-Number. Enter between 1 to 7.");
};
return 0;
};
C Programming | Computer Programming for Beginners | C Programming | Computer Programming for Beginners | C Programming | Computer Programming for Beginners | C Programming | Computer Programming for Beginners
#include<stdio.h>
int main()
{
int day_num;
printf("\nEnter day number of the week: ");
scanf(“%d”,&day_num);
switch(day_num)
{
case 1:
printf("\nSelected day is SUNDAY.");
break;
case 2:
printf("\nSelected day is MONDAY.");
break;
case 3:
printf("\nSelected day is TUESDAY.");
break;
case 4:
printf("\nSelected day is WEDNESDAY.");
break;
case 5:
printf("\nSelected day is THURSDAY.");
break;
case 6:
printf("\nSelected day is FRIDAY.");
break;
case 7:
printf("\nSelected day is SATURDAY.");
break;
default:
printf("\nError!!! Invalid Day-Number. Enter between 1 to 7.");
};
return 0;
};
/*Write a C Program to accept two numbers and an operand(+,-,x,/) then perform appropriate calculation as per the operator entered and display the corresponding output
Author: Pradeep Das Gupta
Compiler: GNU GCC Compiler*/
#include<stdio.h>
int main()
{
float x,y,z;
char op;
printf("\nEnter two numbers (X): ");
scanf(“%f”,&x);
printf("\n(Y): ");
scanf(“%f”,&y);
printf("\nEnter operator (+,-,x,/): ");
scanf(“%c”,&op);
switch(op)
{
case '+':
z=x+y;
printf(“\n%f + %f = %f”,x,y,z);
break;
case '-':
z=x-y;
printf(“\n%f - %f = %f”,x,y,z);
break;
case 'x':
z=x*y;
printf(“\n%f x %f = %f”,x,y,z);
break;
case '/':
if(y==0)
{
printf("\nError!!! Division by Zero not allowed.");
break;
}
z=x/y;
printf(“\n%f / %f = %f”,x,y,z);
break;
default:
printf("\nError!!! Invalid Operator.");
}
return 0;
}
C Programming | Computer Programming for Beginners | C Programming | Computer Programming for Beginners | C Programming | Computer Programming for Beginners | C Programming | Computer Programming for Beginners /*A menu driven C Program:
Write a C Program to display a menu as follows;
1.Area of Triangle (using base and altitude)
2.Area of triangle (using 3 sides)
3.Area of equilateral triangle
4.Exit
Select your operation (1,2,3 or 4):
The program should take the user's choice and based upon his/her choice, it should perform the appropriate operation.
Author: Pradeep Das Gupta
Compiler: GNU GCC Compiler
*/
#include<math.h>
#include<stdio.h>
#include<stdlib.h>
int main()
{
float x,y,z,ar,temp;
short int ch;
do
{
system("cls");//clears the screen
cout<<"\nMENU\n********************";
printf("\n1.Area of Triangle (using base and altitude)");
printf("\n2.Area of triangle (using 3 sides)");
printf("\n3.Area of equilateral triangle");
printf("\n4.Exit");
printf("\nSelect your operation (1,2,3 or 4): ");
scanf(“%d”,&ch);
switch(ch)
{
case 1: //Area of Triangle (using base and altitude)
printf("\nEnter Base: ");
scanf(“%f”,&x);
printf("\nEnter Corresponding Altitude: ");
scanf(“%f”,&y);
ar=0.5*x*y;
printf(“\nArea = %f sq. units”,ar);
break;
case 2: //Area of triangle (using 3 sides)
printf("\nEnter Side1: ");
scanf(“%f”,&x);
printf("\nEnter Side2: ");
scanf(“%f”,&y);
printf("\nEnter Side3: ");
scanf(“%f”,&z);
temp=0.5*(x+y+z);//semi-perimeter
ar=sqrt(temp*(temp-x)*(temp-y)*(temp-z));
printf(“\nArea = %f sq. units”,ar);
break;
case 3: //Area of equilateral triangle
printf("\nEnter the side: ");
scanf(“%f”,&x);
ar=sqrt(3)*0.25*pow(x,2);
printf(“\nArea = %f sq. units”,ar);
break;
case 4: //Exit
break;
default: //For Invalid Choice
printf("\nERROR!!! Invalid Choice Entered.\ nChoose between 1 to 4.");
}
printf("\nProcess Paused...\nPress [ENTER] to continue.....");
getc(stdin);
}while(ch!=4);
return 0;
}
C Programming | Computer Programming for Beginners | C Programming | Computer Programming for Beginners | C Programming | Computer Programming for Beginners | C Programming | Computer Programming for Beginners
Author: Pradeep Das Gupta
Compiler: GNU GCC Compiler*/
#include<stdio.h>
int main()
{
float x,y,z;
char op;
printf("\nEnter two numbers (X): ");
scanf(“%f”,&x);
printf("\n(Y): ");
scanf(“%f”,&y);
printf("\nEnter operator (+,-,x,/): ");
scanf(“%c”,&op);
switch(op)
{
case '+':
z=x+y;
printf(“\n%f + %f = %f”,x,y,z);
break;
case '-':
z=x-y;
printf(“\n%f - %f = %f”,x,y,z);
break;
case 'x':
z=x*y;
printf(“\n%f x %f = %f”,x,y,z);
break;
case '/':
if(y==0)
{
printf("\nError!!! Division by Zero not allowed.");
break;
}
z=x/y;
printf(“\n%f / %f = %f”,x,y,z);
break;
default:
printf("\nError!!! Invalid Operator.");
}
return 0;
}
C Programming | Computer Programming for Beginners | C Programming | Computer Programming for Beginners | C Programming | Computer Programming for Beginners | C Programming | Computer Programming for Beginners /*A menu driven C Program:
Write a C Program to display a menu as follows;
1.Area of Triangle (using base and altitude)
2.Area of triangle (using 3 sides)
3.Area of equilateral triangle
4.Exit
Select your operation (1,2,3 or 4):
The program should take the user's choice and based upon his/her choice, it should perform the appropriate operation.
Author: Pradeep Das Gupta
Compiler: GNU GCC Compiler
*/
#include<math.h>
#include<stdio.h>
#include<stdlib.h>
int main()
{
float x,y,z,ar,temp;
short int ch;
do
{
system("cls");//clears the screen
cout<<"\nMENU\n********************";
printf("\n1.Area of Triangle (using base and altitude)");
printf("\n2.Area of triangle (using 3 sides)");
printf("\n3.Area of equilateral triangle");
printf("\n4.Exit");
printf("\nSelect your operation (1,2,3 or 4): ");
scanf(“%d”,&ch);
switch(ch)
{
case 1: //Area of Triangle (using base and altitude)
printf("\nEnter Base: ");
scanf(“%f”,&x);
printf("\nEnter Corresponding Altitude: ");
scanf(“%f”,&y);
ar=0.5*x*y;
printf(“\nArea = %f sq. units”,ar);
break;
case 2: //Area of triangle (using 3 sides)
printf("\nEnter Side1: ");
scanf(“%f”,&x);
printf("\nEnter Side2: ");
scanf(“%f”,&y);
printf("\nEnter Side3: ");
scanf(“%f”,&z);
temp=0.5*(x+y+z);//semi-perimeter
ar=sqrt(temp*(temp-x)*(temp-y)*(temp-z));
printf(“\nArea = %f sq. units”,ar);
break;
case 3: //Area of equilateral triangle
printf("\nEnter the side: ");
scanf(“%f”,&x);
ar=sqrt(3)*0.25*pow(x,2);
printf(“\nArea = %f sq. units”,ar);
break;
case 4: //Exit
break;
default: //For Invalid Choice
printf("\nERROR!!! Invalid Choice Entered.\ nChoose between 1 to 4.");
}
printf("\nProcess Paused...\nPress [ENTER] to continue.....");
getc(stdin);
}while(ch!=4);
return 0;
}