0% found this document useful (0 votes)
21 views

Source Code Final

The document contains code snippets in C programming language for various programs like calculating area of triangle, student percentage calculation, checking vowel or consonant, printing numbers and their squares using for loop, finding sum of numbers using do-while and for loop, removing non-alphabet characters from string, finding largest and smallest element in array, sorting array using bubble sort, matrix multiplication, checking palindrome string, using string functions, factorial using function, adding numbers using function with local and global variables. Each code is preceded by description of the program.

Uploaded by

abishek
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Source Code Final

The document contains code snippets in C programming language for various programs like calculating area of triangle, student percentage calculation, checking vowel or consonant, printing numbers and their squares using for loop, finding sum of numbers using do-while and for loop, removing non-alphabet characters from string, finding largest and smallest element in array, sorting array using bubble sort, matrix multiplication, checking palindrome string, using string functions, factorial using function, adding numbers using function with local and global variables. Each code is preceded by description of the program.

Uploaded by

abishek
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

Source Code:

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c;
float s,area;
clrscr();
printf("\t\tAREA OF THE TRIANGLE\n");
printf("\n\nEnter size of each sides of triangle:");
scanf("%f%f%f",&a,&b,&c);
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf("Area of triangle is:%.2f",area);
getch();
}

Sudarshan.S [B.tech IT-C Section]


Source Code:

#include<stdio.h>
#include<conio.h>
void main()
{
int m1,phy,chem,cp,TD,beee,tot;
float avg;
clrscr();
printf("\t\tCALCULATE STUDENT PERCENTAGE PROGRAM\n");
printf("\n\n Enter the maths marks :");
scanf("%d",&m1);
printf("\n Enter the physics marks :");
scanf("%d",&phy);
printf("\n Enter the chemistry marks :");
scanf("%d",&chem);
printf("\n Enter the CP marks :");
scanf("%d",&cp);
printf("\n Enter the TD marks :");
scanf("%d",&TD);
printf("\n Enter the BEEE marks :");
scanf("%d",&beee);
tot=m1+phy+chem+cp+TD+beee;
avg=(tot/6.0);
printf("\nTOTAL MARKS=%d",tot);
printf("\nPERCENTAGE MARKS=%f ",avg);
getch();
}

Sudarshan.S [B.tech IT-C Section]


Source Code:

#include<conio.h>
#include<stdio.h>
void main()
{
char ch;
clrscr();
printf("\t\tGIVEN CHARACTER IS VOWEL OR NOT PROGRAM\n");
printf("\n\nEnter a character in small to check :");
scanf("%c",&ch);
switch(ch)
{
case 'a':
printf("\nThe entered character %c is a vowel",ch);
break;
case 'e':
printf("\nThe entered character %c is a vowel",ch);
break;
case 'i':
printf("\nThe entered character %c is a vowel",ch);
break;
case 'o':
printf("\nThe entered character %c is a vowel",ch);
break;
case 'u':
printf("\nThe entered character %c is a vowel",ch);
break;
default:
printf("\nThe entered character is a consonant");
}
getch();
}

Sudarshan.S [B.tech IT-C Section]


Source Code:

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j=1,n;
clrscr();
printf("\t\tNUMBERS AND THEIR SQUARE\n");
printf("\nEnter the limit value:");
scanf("%d",&n);
for(i=1; i<=n; i++)
{
printf("\n%d\t",i);
j=i*i;
printf("%d\n",j);
}
getch();
}

Sudarshan.S [B.tech IT-C Section]


Source Code:

#include<stdio.h>
#include<conio.h>
void main()
{
int n,sum=0;
clrscr();
printf("\t\tSUM OF 'n' NUMBERS USING DO-WHILE\n");
printf("\n\nEnter a value to find its sum value:");
scanf("%d",&n);
do
{
sum=sum+n;
n=n-1;
}
while(n>0);
printf("sum of the given numbers are: %d",sum);
getch();
}
//Name IT-C

Sudarshan.S [B.tech IT-C Section]


Source Code:

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,sum=0 ;
clrscr();
printf("\t\tSUM OF 'n' NUMBERS USING FOR STATEMENTS\n");
printf("\n\nEnter a value to find its sum value:");
scanf("%d",&n);
for(i=1; i<=n; i++)
{
sum =sum+i;
}
printf ("The sum of number upto %d is %d",n,sum);
getch();
}

Sudarshan.S [B.tech IT-C Section]


Source Code:

#include<stdio.h>
#include<conio.h>
void main()
{
char line[100],newline[100];
int i=0,j=0;
clrscr();
printf("\t\tREMOVE CHARACTERS EXCEPT ALPHABETS\n");
printf("\n\nEnter a String:");
gets(line);
for(i=0;line[i]!='\0';i++)
{
if((line[i]>='a'&&line[i]<='z')||(line[i]>='A'&&line[i]<='Z'))
{
newline[j]=line[i];
j++;
}
}
newline[j]='\0';
printf("Output String: ");
puts(newline);
getch();
}
Sudarshan.S [B.tech IT-C Section]
Source Code:

#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,a[20];
clrscr();
printf("\t\t DISPLAY NUMBER OF DIGITS INTO WORDS\n");
printf("\n\nEnter the three digits number:\n");
scanf("%d",&n);
for(i=0;n>0;i++)
{
a[i]=n%10;
n=n/10;
}
for(i=2;i>=0;i--)
{
switch(i)
{
case 0:
printf("\t%d units",a[i]);
break;
case 1:
printf("\t%d tens",a[i]);
break;
case 2:
printf("\t%d hundreds",a[i]);
break;
}
}
getch();
}

Sudarshan.S [B.tech IT-C Section]


Source Code:

#include<stdio.h>
#include<conio.h>
void main()
{
int a[50],size,i,big,small;
clrscr();
printf("\t\tLARGEST AND SMALLEST ELEMENT IN AN ARRAY\n");
printf("\n\nEnter the size of the array: ");
scanf("%d",&size);
printf("\n\nEnter %d elements(numbers) in to the array: ",size);
for(i=0;i<size;i++)
{
scanf("%d",&a[i]);
big=a[0];
}
for(i=1;i<size;i++)
{
if(big<a[i])
big=a[i];
}
printf("\n Largest elementis: %d",big);
small=a[0];
for(i=1;i<size;i++)
{
if(small>a[i])
small=a[i];
}
printf("\n Smallest elementis: %d",small);
getch();
}

Sudarshan.S [B.tech IT-C Section]


Source Code:

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n,a[10], temp;
clrscr();
printf("\t\tSORTING THE ELEMENTS IN AN ARRAY USING BUBBLE
SORT\n");
printf("\n\nEnter the number of elements(numbers)");
scanf("%d",&n);
printf("Enter the %d values:\n", n );
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
for(i=1;i<n;i++)
{
for(j=1;j<=n-i;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
printf("Sorted values in ascending order\n");
for(i=1;i<=n;i++)
{
printf("%d\n",a[i]);
}
printf("Sorted values in descending order\n");
for(i=n;i>0;i--)
{
printf("%d\n",a[i]);
}
getch();
}

Sudarshan.S [B.tech IT-C Section]


Source Code:

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,j,a[3][3],b[3][3],c[3][3],m,k;
clrscr();
printf("\t\tMATRIX OPERATIONS-MULTIPLICATION PROGRAM\n");
printf("\n\nEnter the order of two Matrices:");
scanf("%d %d",&m,&n);
printf("\n Enter the Matrix A");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
printf("\n");
}
printf("\n Enter the Matrix B");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&b[i][j]);
}
printf("\n");
}
printf("Matrix Multiplication\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
c[i][j]=0;
for(k=0;k<n;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
printf("\t%d",c[i][j]);
}
printf("\n");
}
getch();
}

Sudarshan.S [B.tech IT-C Section]


Source Code:

#include <stdio.h>
#include<conio.h>
#include <string.h>
int main()
{
char a[100], b[100];
clrscr();
printf("\tSTRING FUNCTIONS(Palindrome)PROGRAM\n");
printf("\n\nEnter the string to check if it is a Palindrome\n");
gets(a);
strcpy(b,a);
strrev(b);
if (strcmp(a,b) == 0)
printf("Entered string is a palindrome.\n");
else
printf("Entered string is not a palindrome.\n");
getch();
return 0;
}

Sudarshan.S [B.tech IT-C Section]


Source Code:

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char s1[20],s2[20];
clrscr();
printf("\t\tSTRING FUNCTION PROGRAM\n");
printf("\nEnter two strings:");
scanf("%s%s",s1,s2);
printf("\n Length of String s1: %d",strlen(s1));
printf ("\n Length of String s2: %d",strlen(s2));
strupr(s1) ;
printf("\n\n Uppercase of the string s1:%s",s1);
strlwr(s2) ;
printf("\n\n Lowercase of the string s2:%s",s2);
strcat(s1,s2);
printf("\n\n String s1 after concatenating s2 to it:%s",s1);
getch();
}

Sudarshan.S [B.tech IT-C Section]


Source Code:

#include<stdio.h>
#include<conio.h>
int factorial(int);
void main()
{
int i,num;
long int fact;
clrscr();
printf("\t FACTORIAL USING FUNCTIONS\n");
printf("\nEnter a number: ");
scanf("%d",&num);
fact = factorial(num);
printf("\nFactorial of %d is: %ld",num,fact);
getch();
}
int factorial(int n)
{
int i,f=1;
for(i=1;i<=n;i++)
f=f*i;
return f;
}
Sudarshan.S [B.tech IT-C Section]
Source Code:

#include<stdio.h>
#include<conio.h>
int add_numbers(void);
int value1,value2,value3;
int add_numbers(void)
{
auto int result;
result=value1+value2+value3;
return result;
}
void main()
{
int result;
clrscr();
printf("\t\tLOCAL AND GLOBAL VARIABLES\n");
value1 = 10;
value2 = 20;
value3 = 30;
result = add_numbers();
printf("\nThe sum of %d+%d+%d is %d \n",value1,value2,value3,result);
getch();
}

Sudarshan.S [B.tech IT-C Section]


Source Code:

#include<stdio.h>
#include<conio.h>
void swap(int,int);
void main()
{
int i, j;
clrscr();
printf("\t\STWAPPING OF TWO NUMBERS USING CALL BY VALUE\n");
printf("\n\nEnter the First Number in A : ");
scanf("%d",&i);
printf("\nEnter the Second Number in B : ");
scanf("%d",&j);
swap(i,j);
getch();
}

void swap(int x, int y)


{
int t;
t=x;
x=y;
y=t;
printf("\n A = %d",x);
printf("\n B = %d",y);
}

Sudarshan.S [B.tech IT-C Section]


Source Code:

#include<stdio.h>
#include<conio.h>
void swap(int*a,int*b);
void main()
{
int i,j;
clrscr();
printf("\t\tSWAPPING OF TWO NUMBERS USING CALL BY
REFERENCE\n");
printf("\nEnter the First Number in A : ");
scanf("%d",&i);
printf("\nEnter the Second Number in B : ");
scanf("%d",&j);
swap(&i,&j);
printf("\n A = %d",i);
printf("\n B = %d",j);
getch();
}

void swap(int*x,int*y)
{
int t;
t=*x;
*x=*y;
*y=t;
}

Sudarshan.S [B.tech IT-C Section]


Source Code:

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i,sum=0;
int *ptr;
clrscr();
printf("\t\tSUM OF AN INTEGER ARRAY USING POINTERS\n");
printf("\n\nEnter 10 elements:");
for(i=0;i<10;i++)
{
scanf("%d",&a[i]);
ptr = a;
}
for(i=0;i<10;i++)
{
sum = sum + *ptr;
ptr++;
}
printf("The sum of array elements is %d",sum);
getch();
}

Sudarshan.S [B.tech IT-C Section]


Source Code:

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],n,i,max;
int *p;
clrscr();
printf("\t\tMAXIMUM ELEMENTS IN AN INTEGER ARRAY USING
POINTERS PROGRAM\n");
printf("\n\nEnter the size of array:");
scanf("%d",&n);
printf("Enter %d elements in the array:\n",n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
p=&a[0];
max=a[0];
}
for(i=0;i<n;i++)
{
if(max<=*p)
{
max=*p;
}
p++;
}
printf("\nMaximum element in the array is: %d",max);
getch();
}

Sudarshan.S [B.tech IT-C Section]


Source Code:

#include <stdio.h>
#include <conio.h>
void main()
{
struct stud
{
int rollno;
char name[25];
int total;
}stud[100];
int n,i;
clrscr();
printf("\t\tSTUDENT DETAILS USING STRUCTURES PROGRAM\n");
printf("\n\nEnter total number of students\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter details of No.%d student\n",i+1);
printf("Name:");
scanf("%s",&stud[i].name);
printf("Roll number:");
scanf("%d",&stud[i].rollno);
printf("Total mark:");
scanf("%d",&stud[i].total);
}
printf("\nSTUDENTS DETAILS:\n");
for(i=0;i<n;i++)
{
printf("\n*********************");
printf("\nRoll number:%d",stud[i].rollno);
printf("\nName:%s",stud[i].name);
printf("\nTotal mark:%d",stud[i].total);
printf("\n*********************\n");
}
getch();
}

Sudarshan.S [B.tech IT-C Section]

You might also like