0% found this document useful (0 votes)
44 views4 pages

Ref Codes

The document describes a C program that calculates the area of different shapes based on user input. The program uses functions to get numeric input from the user and output results. It prints menus for the user to select calculating the area of a circle, square, or sphere. Based on the selection, it prompts for the appropriate parameter, calls the necessary formula, and prints the output.

Uploaded by

Shraddha sonar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views4 pages

Ref Codes

The document describes a C program that calculates the area of different shapes based on user input. The program uses functions to get numeric input from the user and output results. It prints menus for the user to select calculating the area of a circle, square, or sphere. Based on the selection, it prompts for the appropriate parameter, calls the necessary formula, and prints the output.

Uploaded by

Shraddha sonar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

#include <stdio.

h>
int input();
void output(float);
int main()
{
float result;
int choice, num;
printf("Press 1 to calculate area of circle\n");
printf("Press 2 to calculate area of square\n");
printf("Press 3 to calculate area of sphere\n");
printf("Enter your choice:\n");
choice = input();

switch (choice) {
case 1: {
printf("Enter radius:\n");
num = input();
result = 3.14 * num * num;
printf("Area of sphere=");
output(result);
break;
}
case 2: {
printf("Enter side of square:\n");
num = input();
result = num * num;
printf("Area of square=");
output(result);
break;
}
case 3: {
printf("Enter radius:\n");
num = input();
result = 4 * (3.14 * num * num);
printf("Area of sphere=");
output(result);
break;
}
default:
printf("wrong Input\n");
}
return 0;
}
int input()
{
int number;
scanf("%d", &number);
return (number);
}

void output(float number)


{
printf("%f", number);
}
#include <stdio.h>
int main() {
int sec, h, m, s;
printf("Input seconds: ");
scanf("%d", &sec);

h = (sec/3600);

m = (sec -(3600*h))/60;

s = (sec -(3600*h)-(m*60));

printf("H:M:S - %d:%d:%d\n",h,m,s);

return 0;
}

#include <stdio.h>
int input();
void output(float);
int main()
{
float result;
int choice, num;
printf("Press 1 to calculate area of circle\n");
printf("Press 2 to calculate area of square\n");
printf("Press 3 to calculate area of sphere\n");
printf("Enter your choice:\n");
choice = input();
switch (choice) {
case 1: {
printf("Enter radius:\n");
num = input();
result = 3.14 * num * num;
printf("Area of sphere=");
output(result);
break;
}
case 2: {
printf("Enter side of square:\n");
num = input();
result = num * num;
printf("Area of square=");
output(result);
break;
}
case 3: {
printf("Enter radius:\n");
num = input();
result = 4 * (3.14 * num * num);
printf("Area of sphere=");
output(result);
break;
}
default:
printf("wrong Input\n");
}
return 0;
}
int input()
{
int number;
scanf("%d", &number);
return (number);
}
void output(float number)
{
printf("%f", number);
}

#include<stdio.h>
#include<conio.h>
void main () {
int ch,r,l,w,b,h;
float area;
clrscr();
printf("enter 1 for area of circle\n");
printf("enter 2 for area of rectangal\n");
printf("enter 3 for area of triagle\n");
printf("enter your choise\n");
scanf("%d",&ch);
switch(ch) {
case 1:
printf("enter radious of circle\n");
scanf("%d",&r);
area=3.14*r*r;
break;
case 2:
printf("enter lanth and width\n");
scanf("%d%d",&l,&w);
area=l*w;
break;
case 3:
printf("enter the base and hight\n");
scanf("%d%d",&b,&h);
area=.5*b*h;
break;
}
printf("area is=%f",area);
getch();
}
* * * * *
* * * *
* * *
* *
*
#include <stdio.h>

int main()
{
int i, j;
for(i=1; i<=5; i++)
{
for(j=1; j<i; j++)
{
printf(" ");
}
for(j=i; j<=5; j++)
{
printf("*");
}
printf("\n");
}

return 0;
}

char alpha='A';
char upperAlpha;
printf("Enter letter up to which pyramid to be printed");
scanf("%c",&upperAlpha);
for(int i=1;i<=(upperAlpha-aplha)+1;i++)
{
for(int j=1;j<=i;j++)
{
printf("%c",alpha);
}
alpha++;
}

You might also like