Upcoming SlideShare
×

# SaraPIC

576 views

Published on

0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
576
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
7
0
Likes
0
Embeds 0
No embeds

No notes for slide

### SaraPIC

1. 1. Practical no.1Write a C program to display hexadecimal decimal octal format of theentered numbers.#include<stdio.h>#include<conio.h>void main(){intnum;clrscr();printf("Enter the number : ");scanf("%d",&num);printf("nDecimal format : %d",num);printf("nHexaDecimal format : %x",num);printf("nOctal format : %o",num);getch();}OUTPUT:Enter the number:12Decimal format :12Hexadecimal format:cOctal format:14
2. 2. Practical no.2To demonstrate all possible formatting specifiers.Format Specifiers for C%c The character format specifier.%d The integer format specifier.%i The integer format specifier (same as %d).%f The floating-point format specifier.%e The scientific notation format specifier.%E The scientific notation format specifier.%g Uses %f or %e, whichever result is shorter.%G Uses %f or %E, whichever result is shorter.%o The unsigned octal format specifier.%s The string format specifier.%u The unsigned integer format specifier.%x The unsigned hexadecimal format specifier.%X The unsigned hexadecimal format specifier.%p Displays the corresponding argument that is a pointer.%n Records the number of characters written so far.%% Outputs a percent sign.printf statements is called an escape sequence: n (newline) t (tab) v (vertical tab) f (new page) b (backspace) r (carriage return) n (newline)
3. 3. Practical no.3Write a program to find the largest and the smallest from the giventhree integers.#include<stdio.h>#include<conio.h>void main(){int num1, num2, num3;clrscr();printf("Enter three numbers = ");scanf("%d %d %d", &num1, &num2, &num3);printf("nnThe largest number is ");if( (num1 > num2) && (num1 > num3) )printf("%d", num1);else if(num2 > num3)printf("%d", num2);elseprintf("%d", num3);printf("nnThe Smallest number is ");if( (num1 < num2) && (num1 < num3) )printf("%d", num1);else if(num2 < num3)
4. 4. printf("%d", num2);elseprintf("%d",num3);getch();}OUTPUT:Enter three numbers: 121567The largest no. is :67The smallest no.is :12
5. 5. Practical no.4Write a C program to find even or odd numbers.#include<stdio.h>main(){intnum;printf ("Enter a number to be checked for even/odd: ");scanf ("%d",&num);if (num%2==0){printf ("The entered number is EVEN.n");}else{printf ("The entered number is ODD.n");}}OUTPUT:Enter a number to be checked for even/odd:15The entered number is ODD.
6. 6. Practical no.5Write a C program to display menu 1.Addition 2.Subtraction3.Multiplication 4.Division and execute it using switch case.#include<stdio.h>#include<conio.h>void main(){inta,b,c;int menu;printf("choose the arithmetic optionn");scanf("%d",&menu);switch(menu){case 1:printf("Enter The Two Numbers:n");scanf("%d%d",&a,&b);c=a+b;printf("The addition of two numbers %dn",c);break;case 2:printf("Enter THE TWO NUMBERS:n");scanf("%d%d",&a,&b);c=a-b;printf("The subtraction of two numbers %dn",c);break;case 3:printf("Enter THE TWO NUMBERS:n");scanf("%d%d",&a,&b);c=a*b;printf("The multiplication of two numbers %dn",c);break;case 4:printf("Enter THE TWO NUMBERS:n");scanf("%d%d",&a,&b);c=a/b;printf("The division of two numbers %dn",c);break;}
7. 7. getch();}OUTPUT:choose the arithmetic option2Enter THE TWO NUMBERS:15 6The subtraction of two numbers :9
8. 8. Practical no.6Write a c program to perform addition all numbers from 1 to 100.#include<stdio.h>#include<conio.h>void main(){int i=0,sum=0;clrscr();while(i<100){sum=sum+i;i++;}printf("Addition of all numbers from 1-100=%d",sum);getch();}OUTPUT:Addition of all numbers from 1-100=4950
9. 9. Practical no.7Write a C program to find smallest and largest number from arrayelements.#include<stdio.h>#include<conio.h>Void main(){ int a[20],min,max; intn,i;clrscr(); printf("enter the num of elementst:"); scanf("%d",&n); printf("enter the elementsn"); for( i=0;i<n;i++) { scanf("%d",&a[i]); if(i==0) { min=max=a[i]; } if(a[i]<min) min=a[i]; else if(a[i]>max)
10. 10. max=a[i]; } printf("largest element is %d n Smallest element is %d ",max,min);getch();}OUTPUT:enter the num of elements:5enter the element:1256231078largest element is 78Smallest element is 10
11. 11. Practical no.8Write a C program to enter elements for 3*3matrix and display them.#include<stdio.h>#include<conio.h>void main(){int a[3][3],i,j;clrscr();printf("ENTER ELEMENTSn");for(i=0;i<3;i++){for(j=0;j<3;j++){scanf("%d",&a[i][j]);}}printf("THE ELEMENTS IN 3*3 MATRIX FORM ISn");for(i=0;i<3;i++){for(j=0;j<3;j++){printf("%d",a[i][j]);}printf("n");}getch();}OUTPUT:ENTER ELEMENTS123456789THE ELEMENTS IN 3*3 MATRIX FORM IS1 2 34 5 67 8 9
12. 12. Practical no.9Write a C program to demonstrate output of standard libraryfunctions. Strlent( ),strcpy( ),strcat( ),strcmp( ).#include<stdio.h>#include<conio.h>#include<string.h>void main(){char s1[10],s2[10],s3[30];int a;clrscr();printf("enter the two stringsn");scanf("%s%s",&s1,&s2);printf("1st String=%sn2ndString=%s",s1,s2);if(strcmpi(s1,s2) == 0 )printf("Entered strings are equal.n");elseprintf("Entered strings are not equal.n");a=strlen(s1);printf("nLength=%d",a);strcat(s1,s2);printf("nconcatinated string=%s",s1);strcpy(s1,s2);printf("ncopied string=%s",s1);getch();}
13. 13. OUTPUT:enter the two stringsGoodMorning1st String=Good2ndString=MorningEntered strings are not equal.Length=4concatinated string=GoodMorningcopied string=Morning
14. 14. Practical no.10Write a C program to calculatefactorial of any number usingrecursion.#include<stdio.h>#include<conio.h>int fact(int );int main(){ intnum,res; printf("Enter any number: "); scanf("%d", &num); res = fact(num); printf("Factorial value is: %d",res); getch(); return 0;}int fact(int n){ int f; if(n==1) return(1); else f = n*fact(n-1); return(f);}OUTPUT:Enter any number:5Factorial value is:120
15. 15. Practical no.11Write a C program to demonstrate call by value and call by reference.//CALL BY VALUE#include<stdio.h>#include<conio.h>int swap(int,int);void main(){inta,b;printf("nenter two values:");scanf("%d%d",&a,&b);printf("Before swapping:n");printf("A=%dn B=%d",a,b);swap(a,b);getch();}int swap(intx,int y){int temp;temp=x;x=y;y=temp;
16. 16. printf("After swapping:n A=%dnB=%d",x,y);return(0);}OUPUT:enter two values3020Before swapping:A=30B=20After swapping:A=20B=30
17. 17. //CALL BY REFERENCE#include<stdio.h>#include<conio.h>int swap(int *,int *);void main(){inta,b;printf("nenter two values:");scanf("%d%d",&a,&b);printf("Before swapping:n");printf("A=%dn B=%d",a,b);swap(&a,&b);getch();}int swap(int *x,int *y){int temp;temp=*x;*x=*y;*y=temp;printf("After swapping:n A=%dnB=%d",*x,*y);return(0);}
18. 18. OUPUT:enter two values3020Before swapping:A=30B=20After swapping:A=20B=30