Sie sind auf Seite 1von 28

INTEGER TO FLOAT CONVERSION

PROGRAM
#include<stdio.h>
void main()
{
float b;
int a;
printf("\nEnteranInteger\n");
scanf("%d",&a);
b=(float)a;
printf("\nTheConvertedfloatvalue is%f",b);
}

OUTPUT
Enter an Integer 45
The Converted float value is 45.00000

RESULT
Thus the c program was written,entered, executed successfully and the output
was verified

AREA OF CIRCLE

PROGRAM
#include<stdio.h>
void main()
{
float r,area;
printf(\nEnter the radius of the circle);
scanf(%f,&r);
area=3.14*r*r;
printf(\nArea=%f,area);
}

OUTPUT
Enter the radius of the circle 4
Area = 50.24

RESULT
Thus the c program was written,entered, executed successfully and the output
was verified

TEMPERATURE CONVERSION

PROGRAM
#include<stdio.h>
void main()
{
floatcel, fah ,c ,f;
clrscr();
printf(\nEnter the Fahrenheit value:);
scanf(%f,&f);
cel=(1.8)*(f-32);
printf(Celsius=%f,cel);
printf(\nEnter the Celsius value:);
scanf(%f,&c);
fah=(1.8)*c+32;
printf(Fahrenheit=%f,fah);
getch();
}
OUTPUT
Enter the Fahrenheit value:8
Celsius = -13.33
Enter the Celsius value:10
Fahrenheit = 50

RESULT
Thus the c program was written,entered, executed successfully and the output
was verified

EVALUATE THE GIVEN EXPRESSION

PROGRAM
#include<stdio.h>
void main()
{
int a,b,c;
float x,y,z;
printf ("Enter the values for a,b,c \n");
scanf("%d%d%d", &a,&b,&c);
x = (a * b) c;
y = (b/c) * a;
z = (a - b) / c
printf(The value of x is %f,x);
printf(The value of y is %f,y);
printf(The value of z is %f,z);
}
OUTPUT
Enter the value for a,b,c.
a= 5; b = 6; c= 12;
x = 28.000
y = 2.5000
z = 0.0555

RESULT
Thus the c program was written,entered, executed successfully and the output
was verified

DECISION MAKING & LOOPING, SCIENTIFIC PROBLEMS


Find the Given year is Leap Year or Not (using if else)

PROGRAM
#include<stdio.h>
void main()
{
int year;
printf ("Enter the year \n");
scanf("%d", &year);
if (year%4==0)
printf ("It is a Leap Year \n");
else
printf ("It is Not a Leap Year\n");
}

OUTPUT
Enter the year 2004
It is a Leap Year
Enter the year 1998
It is not a Leap Year

RESULT
Thus the c program was written, entered, executed successfully and the output was
verified

Largest of three numbers (using nested if else)


PROGRAM
#include<stdio.h>
#include<conio.h>
void main()
{
inta,b,c;
clrscr();
printf(Biggest of three Nos);
printf(Enter the values of A,B,C);
scanf(%d%d%d,&a,&b,&c);
if((a>b)&&(b>c))
printf(\n a=%d is greatest,a);
elseif(b>c)
{
printf(\n b=%d is greatest,b);
}
else
{
printf(\n c=%d is greatest,c);
}
getch();
}
OUTPUT
Enter the values of A,B,C:10 20 5
B = 20 is greatest
RESULT
Thus the c program was written,entered, executed successfully and the output was
verified

SUMOFN NATURAL NUMBERS (using while)

PROGRAM
#include<stdio.h>
void main()
{
int i,n,sum=0;
printf("Enter the range\n");
scanf("%d",&n);
i=1;
while(i<=n)
{
sum=sum+i;
i++;
}
printf("\nThesumof first%dnumbersis %d\n",n,sum);
}

OUTPUT
Enterthe range
16
The sumof first16numbersis136

RESULT
Thus the c program was written,entered, executed successfully and the output was
verified

SUM OF DIGITS (using do while)


PROGRAM
#include<stdio.h>
void main()
{
int n,i,sum=0;
printf("Enter a Number\n");
scanf("%d",&n);
do
{
i=n%10;
sum=sum+i;
n=n/10;
}
while(n>0);
printf("The Sumof digitis%d\n",sum);
}

OUTPUT
Enter a Number
5891
The Sum of digitis 23

RESULT
Thus the c program was written,entered, executed successfully and the output was
verified

ARITHMETIC OPERATIONS (Using SwitchCase)


PROGRAM
#include<stdio.h>
#include<conio.h>
void main()
{
int a, b, c, n;
clrscr();
printf(1. Addition\n);
printf(2. Subtraction\n);
printf(3. Multiplication\n);
printf(4. Division\n);
printf(0. Exit\n);
printf(Enter your choice : );
scanf(%d,&n);
printf(Enter the two numbers :);
scanf(%d,%d,&a,&b);
switch(n)
{
case 1:
c = a + b;
printf(Addition :%d\n,c);
break;
case 2:
c = a b;
printf(Subtraction

:%d\n,c);

break;
case 3:
c = a * b;
printf(Multiplication
break;

:%d\n,c);

case 4:
c = a / b;
printf(Division

:%d\n,c);

break;
case 0:
exit(0);
break;
}
getch();
}
OUTPUT
1. Addition
2. Subtraction
3. Multiplication
4. Division
0. Exit
Enter Your Choice : 1
Enter the two nos a and b: 2

Addition : 10.
Enter Your Choice : 2
Enter the two nos a and b: 5

Subtraction : 3.
Enter Your Choice : 3
Enter the two nos a and b: 2

Multiplication : 16.
Enter Your Choice : 4.
Enter the two nos a and b: 8

Division : 2.
Enter Your Choice : 0.
Exit.
RESULT
Thus the c program was written,entered, executed successfully and the output was
verified

GENERATION OF ARMSTRONG NUMBERS


PROGRAM
#include <stdio.h>
void main()
{
int r;
long number = 0, c, sum = 0, temp;
printf("Enter an integer upto which you want to find armstrong numbers\n");
scanf("%ld",&number);
printf("Following armstrong numbers are found from 1 to %ld\n",number);
for( c = 1 ; c <= number ; c++ )
{
temp = c;
while( temp != 0 )
{
r = temp%10;
sum = sum + r*r*r;
temp = temp/10;
}
if ( c == sum )
printf("%ld\n", c);
sum = 0;
}
getch();
}
OUTPUT
Enter an integer upto which you want to find armstrong numbers:500
Following armstrong numbers are found from 1 to 500: 1,153,370,371,407
RESULT
Thus the c program was written,entered, executed successfully and the output was
verified

ONE DIMENSIONAL ARRAY, TWO DIMENSIONAL ARRAY


ONE DIMENSIONAL ARRAY
PROGRAM
#include<stdio.h>
#include<conio.h>
void main()
{
int a[3],i;
clrscr();
printf("\n\t Enter threenumbers : ");
for(i=0; i<3; i++)
{
scanf("%d",&a[i]);
}
printf("\n\n\tNumbers are: ");
for(i=0; i<3; i++)
{
printf("\t %d", a[i]);
}
getch();
}
OUTPUT
Enter three numbers : 9 4 6
Numbers are: 9

RESULT
Thus the c program was written,entered, executed successfully and the output was
verified

TWODIMENSIONAL ARRAY-MATRIX MULTIPLICATION


PROGRAM
#include<stdio.h>
#include<conio.h>
void main()
{
int a[3][3], b[3][3], c[3][3], i, j, k;
clrscr();
printf("\nENTER 'A' MATRIX\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&a[i][j]);
}
printf("\n");
}
printf("\nENTER 'B' MATRIX\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("\n");
}
printf("__________________________\n\n");
printf("MATRIX MULTIPLICATION\n");
printf("__________________________\n\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)

{
c[i][j]=0;
}
for(k=0;k<3;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d\t \n \n",c[i][j]);}
}
getch();
}
OUTPUT
ENTER 'A'MATRIX
111
222
333
ENTER 'B'MATRIX
123
123
123
________________________
MATRIX MULTIPLICATION
________________________
3
6
9
6
12
18
9
18
2
RESULT
Thus the c program was written,entered, executed successfully and the output was
verified

PROBLEMS UNDER STRING FUNCTIONS


Solving problems using String functions
PROGRAM
#include <stdio.h>
#include <string.h>
int main()
{
char a[100], b[100];
printf("Enter the first string\n");
gets(a);
printf("Enter the second string\n");
gets(b);
if(strcmp(a,b) == 0 )
printf("Entered strings are equal.\n");
else
printf("Entered strings are not equal.\n");
return 0;
}

OUTPUT
Enter the first string
SVS
Enter the second string
SVS College of Engineering
Entered the strings are not equal

RESULT
Thus the c program was written, entered, executed successfully and the output was
verified

STRINGFUNCTIONS-CONCATENATE TWO STRINGS

PROGRAM
#include<stdio.h>
#include<string.h>
void main()
{
char s1[20], s2[20]; \
printf("\nEnter first string:");
gets(s1);
printf("\nEnter second string: ");
gets(s2);
strcat(s1, s2);
printf("\nThe concatenated string is:%s", s1);
getch();
}

OUTPUT
Enter first string: College of
Enter second string: Engineering
The concatenated string is: College ofEngineering

RESULT
Thus the c program was written, entered, executed successfully and the output was
verified

STRING FUNCTIONS-COPIESTHE STRING

PROGRAM
#include<stdio.h>
#include<string.h>
void main()
{
char s1[20], s2[20];
printf("\nEnter string into s1: ");
gets(s1);
strcpy(s2, s1);
printf("\ns2: %s", s2);
getch();
}

OUTPUT
Enter string into s1: Engineering
s2: Engineering

RESULT
Thus the c program was written, entered, executed successfully and the output was
verified

STRING CONVERTION TO LOWERCASE, UPPERCASE, STRINGLENGTH

PROGRAM
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
charstr[50];
clrscr();
printf("\n\t Enteryour name : ");
gets(str);
printf("\nLower caseof string: %s",strlwr(str));
printf("\nUpper caseof string: %s",strupr(str));
printf("\nReverseof string: %s",strrev(str));
printf("\nLength of String: %d",strlen(str));
getch();
}

OUTPUT
Enteryour name :College
Lower caseof string: college
Upper caseof string: COLLEGE
Reverseof string: EGELLOC
Length of String: 8

RESULT
Thus the c program was written, entered, executed successfully and the output was
verified

PROGRAMS USING USER DEFINED FUNCTIONS


WITHOUT ARGUMENTS AND RETURN TYPE
PROGRAM
#include<stdio.h>
voidisleap();
voidisleap()
{
int yr;
printf("Enter a Year\n");
scanf("%d",&yr);
if(yr%4==0)
printf("GivenYear is Leap year");
else
printf("GivenYear is Not a Leap year");
}
void main()
{
isleap();
getch();
}

OUTPUT
Enter a Year
1965
GivenYear is Not a Leap year

RESULT
Thus the c program was written,entered, executed successfully and the output was
verified

FUNCTIONS WITHOUT ARGUMENTS &WITH RETURNTYPE


PROGRAM
#include<stdio.h>
#include<math.h>
float area();
float area()
{
int a,b,c;
float s,ar;
printf("Enter 3 Sides\n");
scanf("%d%d%d",&a,&b,&c);
s=(a+b+c)/2;
ar=sqrt(s*(s-a)*(s-b)*(s-c));
return ar;
}
void main()
{
float a;
a=area();
printf("The Area of Triangle is%f\n",a);
}
OUTPUT
Enter3Sides
12

The Area of Triangle is19.748418

RESULT
Thus the c program was written, entered, executed successfully and the output was
verified

FUNCTIONS WITH ARGUMENTS & WITHOUT RETURNTYPE


PROGRAM
#include<stdio.h>
void sorting(int a[],int n)
{
int i,j,t;
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
printf("Array Elemets after sorting\n");
for(i=0;i<n;i++)
printf("%d\t",a[i]);
}
void main()
{
int i,a[10], n;
printf("Enter totalno.of elements\n");
scanf("%d",&n);
printf("Enter Array Elements onebyone\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);

printf("Array Elemets before sorting\n");


for(i=0;i<n;i++)
printf("%d\t",a[i]);
printf("\n");
sorting(a, n);
}

OUTPUT
Enter totalno.of elements
6
Enter Array Elements onebyone
21
2
9
45
30
11
Array Elemets before sorting
21

45

30

11

Array Elemets after sorting


2

11

21

30

45

RESULT
Thus the c program was written, entered, executed successfully and the output was
verified

USER DEFINED FUNCTIONS - SWAPPING OF TWO NUMBERS


CALL BY VALUE AND REFERENCE
PROGRAM
#include<stdio.h>
#include<conio.h>
void swap(int *,int *);
void swap1(int,int);
void main()
{
int a,b,c,d;
clrscr();
printf("Enter the values of a and b:= ");
scanf("%d %d",&a,&b);
printf("Enter the values of c and d:= ");
scanf("%d %d",&c,&d);
printf("\n BEFORE SWAPPING : ");
printf("\n The value of a and b is : %d\t %d ",a,b);
printf("\n The value of c and d is : %d\t %d ",c,d);
printf("\n AFTER SWAPPING : ");
swap(a,b);
swap1(&c,&d);
printf("\n Method is:-Call by Value");
printf("\n **************************");
printf("\n The value of a and b is : %d\t %d",a,b);
printf("\n Method is:-Call by Address or Reference");
printf("\n ***************************");
printf("\n The value of c and d is : %d\t %d",c,d);
}

void swap(int *c,int *d)


{
int t;
t=*c;
*c=*d;
*d=t;
}
void swap1(int a,int b)
{
int t;
t=a;
a=b;
b=a;
}
OUTPUT:
Enter the values of a and b: 2

Enter the values of c and d: 6

BEFORE SWAPPING:
The value of a and b is: 2

The value of c and d is: 6

AFTER SWAPPING:
Method is:-Call by Value
The value of a and b is: 2 4
Method is:-Call by Address or Reference
The value of c and d is: 5
RESULT
Thus the c program was written, entered, executed successfully and the output was
verified

RECURSIVE FUNCTIONS FACTORIAL OF A NUMBER


PROGRAM
#include<stdio.h>
#include<conio.h>
int fact(int);
void main()
{
int n,f,choice;
clrscr();
printf(Enter the number to find the factorial\n);
scanf(%d,&n);
f=fact(n);
printf(The factorial of a number %d using recursion is %d,n,f);
getch();
}
int fact(int n)
{
int f;
if(n==0)
return(1);
else
f=n*fact(n-1);
return(f);
}
OUTPUT
Enter the number to find the factorial 5
The factorial of a number 5 using recursion is 120

RESULT
Thus the c program was written, entered, executed successfully and the output was
verified

PROGRAM FOR STRUCTURE


PROGRAM
#include<stdio.h>
#include<conio.h>
struct student
{
char name[20];
int rno;
}s;
struct cse
{
int m1, m2, m3, m4, tot;
float avg;
struct student s;
}c[10];
void main()
{
int i,n;
clrscr();
printf("ENTER THE VEALUE OF n\n\n");
scanf("%d",&n);
printf("\nENTER NAME,RNO AND MARKS \n\n");
for(i=0;i<n;i++)
{
scanf("%s%d",c[i].s.name, &c[i].s.rno);
scanf("%d",&c[i].m1);
scanf("%d",&c[i].m2);
scanf("%d",&c[i].m3);

scanf("%d",&c[i].m4);
}
printf("\n\n\n");
printf("\t\t******************STUDENT DETAILS***************\n");
printf("\t------------------------------------------------------------------\n");
printf("\tNAME \tRNO \tM1 \tM2 \tM3 \tM4 \tTOTAL \tAVERAGE\n");
printf("\t------------------------------------------------------------------\n");
for(i=0;i<n;i++)
{
c[i].tot=c[i].m1+c[i].m2+c[i].m3+c[i].m4;
c[i].avg=(c[i].tot)/4;
printf("\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%.2f\n\n",c[i].s.name,c[i].s.rno,c[i].m1,
c[i].m2,c[i].m3,c[i].m4,c[i].tot,c[i].avg);
}
printf("\t------------------------------------------------------------------\n");
getch();
}
OUTPUT:
ENTER THE VEALUE OF n 2
ENTER NAME,RNO AND MARKS
Sugir 23 95 85 85 95
Jai 12 98 98 78 98
***********************STUDENT DETAILS******************
--------------------------------------------------------------------------------------NAME
RNO M1
M2 M3 M4 TOTAL AVERAGE
---------------------------------------------------------------------------------------Sugi 23
95
85
85
95
360 90.00
Jai
12
98
98
78
98
372 93.00
---------------------------------------------------------------------------------------RESULT
Thus the c program was written, entered, executed successfully and the output was
verified

PROGRAM FOR UNION


PROGRAM
#include<stdio.h>
#include<conio.h>
union student
{
int a;
char b[2];
}c;
void main()
{
c.a=256;
printf(\n Values Of c.a is = %d ,c.a);
print(\n Values Of c.b[0]=%d,c.b[0]);
printf(\n Values Of c.b[1]=%d,c.b[1]);
getch();
}

OUTPUT:
Value Of c.a is = 256
Value Of c.b[0] = 0
Value Of c.b[1] = 1

RESULT
Thus the c program was written, entered, executed successfully and the output was
verified

Das könnte Ihnen auch gefallen