0% found this document useful (0 votes)
9 views7 pages

C Programs

The document contains multiple C programming code snippets demonstrating various functionalities such as calculating storage sizes of data types, computing simple and compound interest, calculating areas of geometric shapes, performing arithmetic operations, finding the largest of three numbers, and determining student grades based on marks. Each code snippet is structured with input prompts and output statements. The use of libraries like <stdio.h> and <conio.h> is consistent throughout the examples.

Uploaded by

Jai
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)
9 views7 pages

C Programs

The document contains multiple C programming code snippets demonstrating various functionalities such as calculating storage sizes of data types, computing simple and compound interest, calculating areas of geometric shapes, performing arithmetic operations, finding the largest of three numbers, and determining student grades based on marks. Each code snippet is structured with input prompts and output statements. The use of libraries like <stdio.h> and <conio.h> is consistent throughout the examples.

Uploaded by

Jai
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

Expt-1

#include<stdio.h>
#include <conio.h>
void main()
{
clrscr();
printf("storage size of int is: %d\n",sizeof(int));

printf("storage size of float is: %d\n",sizeof(float));

printf("storage size of char is: %d\n",sizeof(char));

printf("storage size of double is: %d\n",sizeof(double));

printf("storage size of long int is: %d\n", sizeof(long int));

printf("storage size of short int is: %d\n",sizeof(short int));

printf("storage size of long double is: %d\n", sizeof(long double));

getch();

#include <stdio.h>
#include <conio.h>
void main()
{
//clrscr();
float principle, time, rate, SI;
printf("Enter principle amount):");
scanf("%f", &principle);
printf("Enter time(duration):");
scanf("%f", &time);
printf("Enter rate of interest: ");
scanf("%f", &rate);
SI =((principle*time * rate) /100);
printf("Simple Interest = %f",SI);

getch ();

#include <stdio.h>

#include <conio.h>
#include <math.h>

void main()
{
//clrscr();

float principle, rate, time,CI;

printf("Enter principle amount:\n ");

scanf("%f", &principle);

printf("Enter time:\n ");

scanf("%f", &time);

printf("Enter rate of interest:\n ");

scanf("%f", &rate);
CI=principle*(pow((1+rate/100),time));
printf("compount interest=%f",CI);
getch();

#include<stdio.h>

#include<conio.h>

void main()
{
//clrscr();
float radius,area;
printf("Enter the radius of Circle in cm :\n ");
scanf("%f",&radius);
area= 3.14*radius*radius;
printf("Area of Circle: %f\n", area);
getch();
}

#include<stdio.h>

#include<conio.h>

void main()
{
//clrscr();
int side, area;
printf("Enter the Length of Side :\n ");
scanf("%d", &side);
area = side*side;
printf("Area of Square: %d\n", area);
getch();
}

#include<stdio.h>
#include<conio.h>

void main()
{
//clrscr();

int length, width, area;

printf("Enter the Length of Rectangle:\n");


scanf("%d", &length);
printf("Enter the Width of Rectangle: \n");
scanf("%d", &width);
area=length * width;
printf("Area of Rectangle: %d", area);
getch();
}

#include<stdio.h>

#include<conio.h>

void main()
{
//clrser();

int base, height;


float area;
printf("Enter the base of Right Angle Triangle :\n");
scanf("%d", &base);
printf("Enter the height of Right Angle Triangle :\n");
scanf("%d", &height);
area= 0.5 * base * height;
printf("Area of Right Angle Triangle: %f", area);
getch();

#include <stdio.h>
#include <conio.h>

void main()
{
//clrscr();
int a = 5, b = 7;
printf("Before Swapping: a =%d, b =%d\n", a, b);
a=a+b;
b=a-b;
a=a-b;
printf("After Swapping: a = %d, b = %d\n", a, b);
getch();
}

#include<stdio.h>

#include<conio.h>

void main()
{
//clrser();

int num1,num2;
float result=0;
char ch;

printf("Enter the first number:");


scanf("%d",&num1);

printf("Enter the second number:");


scanf("%d",&num2);
printf("choose operation to perform(+,-,*,/):");
scanf("%c",&ch);

switch(ch)
{
case '+':
result=num1+num2;
break;
case '-':
result=num1-num2;
break;
case '*':
result=num1*num2;
break;
case '/':
result=(float)num1/(float)num2;
break;
default:
printf("invalid operation.\n");
}
printf("Result:%d%c%d=%f\n",num1,ch,num2,result);
getch();
}

#include<stdio.h>

#include<conio.h>

void main()
{
//clrser();

int a,b,c;
printf("Enter three numbers:");
scanf("%d%d%d",&a,&b,&c);
if(a>=b&&a>=c)
printf("%d is the largest number.",a);
else if(b>=a && b>=c)
printf("%d is the largest number.",b);
else
printf("%d is the largest number.",c);
getch();

#include<stdio.h>

#include<conio.h>

void main()
{
//clrser();

int a,b,c,largest;
printf("Enter three numbers:");
scanf("%d%d%d",&a,&b,&c);
largest=a>b?(a>c?a:c): (b>c?b:c);
printf("%d is the largest number.",largest);
getch();

#include<stdio.h>

#include<conio.h>
void main()
{
//clrser();

float s1,s2,s3,s4,s5,s6,per,total;
printf("Enter the marks of all subjects one by one ranging from (1 to 100)\n:");
scanf("%f%f%f%f%f%f",&s1,&s2,&s3,&s4,&s5,&s6);
total=s1+s2+s3+s4+s5+s6;
printf("Total mark=%.1f\n",total);
per=(total/600)*100;
printf("You have secured percentage=%.2f\n",per);
if(s1<35||s2<35||s3<35||s4<35||s5<35||s6<35)
printf("Result:Fail\n");
else
{
if(per>=85)
printf("Result:Distinction");
else if(per>=60)
printf("Result:First class");
else if(per>=50)
printf("Result:Second class");
else
printf("Result:Pass");

}
getch();

#include<stdio.h>

#include<conio.h>

void main()
{
//clrser();

int digit[3],tol,i;
printf("Enter the first digit within[0-9]:\n");
scanf("%d",&digit[0]);
printf("Enter the second digit within[0-9]:\n");
scanf("%d",&digit[1]);
printf("Enter the multiplier within[0-9]:\n");
scanf("%d",&digit[2]);
printf("Enter the tolerance in percentage[5 or 10 or 20]:\n");
scanf("%d",&tol);
printf("The resistance value entered is %d%dx10^%dohm\
n",digit[0],digit[1],digit[2]);
printf("The colour code for givin value is\n");
for(i=0;i<3;i++)
{
switch(digit[i])
{
case 0:printf("black");
break;
case 1:printf("brown");
break;
case 2:printf("red");
break;
case 3:printf("orange");
break;
case 4:printf("yellow");
break;
case 5:printf("green");
break;
case 6:printf("blue");
break;
case 7:printf("violet");
break;
case 8:printf("gray");
break;
case 9:printf("white");
break;
default:printf("Unknown value");
}
}
switch(tol)
{
case 5:printf("gold");
break;
case 10:printf("silver");
break;
case 20:printf("no color");
break;
default:printf("Unknown value");
break;
}

getch();

You might also like