Beruflich Dokumente
Kultur Dokumente
Student name: Tarun kr. Tyagi Roll No.: 03396492710 Semester: 2nd Group: 2C-8
INTRODUCTION TO PROGRAMMING
PRACTICAL RECORD
PAPER CODE
ETCS - 156
Branch
Section/ Group
PRACTICAL DETAILS
a)
Exp. no
Experiment Name
Date of performance
Date of checking
Remarks
Marks (10)
B.Experiments beyond the list of experiments provided by GGSIPU (practical in C language as well as in other programming language).
Exp. no
Experiment Name
Date of performance
Date of checking
Remarks
Marks (10)
OUTPUT
2.Write a programme to input name from user and return it #include<stdio.h> #include<conio.h> main() { char A[20]; printf("enter name",A); scanf("%s",A); printf ("name is %s",A); getch(); } OUTPUT
5. Write a programme print square of a floating no. #include<stdio.h> #include<conio.h> main() { float a,b; printf("enter no."); scanf("%f",&a); b=a*a; printf ("square is %f",b); getch(); } OUTPUT
6 (a) Write a prog. for Arithmetic operations(both integers) #include<stdio.h> #include<conio.h> main() { int a,b,pro,sum; float div; printf("enter nos."); scanf("%d %d",&a,&b); sum=a+b; pro=a*b; div=a/b; printf("results are %d %d %f",sum,pro,div); getch();
} OUTPUT
6 .(b) Write a prog. to show arithmetic operation(int,float) #include<stdio.h> #include<conio.h> main() { int b; float a,div,pro,sum; printf("enter nos."); scanf("%f %d",&a,&b); sum=a+b; pro=a*b; div=a/b; printf("results are %f %f %f",sum,pro,div); getch();
} OUTPUT
8. Write a programme to print ascii value of character #include<stdio.h> #include<conio.h> main() { char a; printf("enter char"); scanf("%c",&a); printf("ascii code is %d",a); getch(); } OUTPUT
10.Write a programme to show the difference between getch and getche(). #include<stdio.h #include<conio.h> void main() { int a=0,b=0; clrscr(); printf("before getch \n"); getch() printf("after getch \n"); printf("before getche \n"); getche() ; printf("\n after getche \n"); getch();} OUTPUT
11. Write a prog. to implement the difference between the functions scanf() and prinf().
#include<stdio.h> #include<conio.h> void main() { int n; clrscr(); printf("\n Enter the value for n "); scanf("\n%d",&n); printf("\n the value is %d",n); getch(); }
OUTPUT
12. Write a prog. to check whether a number is even or odd. #include<stdio.h> #include<conio.h> void main() { int n; clrscr(); printf("Enter the number "); scanf("%d",&n); if(n%2==0) printf("\n%d is even"); else printf("\n%d is odd"); getch();} OUTPUT
13. Write a programme to check whether a given number is prime or not. #include<stdio.h> #include<conio.h> void main() { int a=0,c=0,i=2; clrscr(); printf("enter no.") ; scanf("%d",&a ); for(i=2;i<a/2;i++) { if(a%i==0) c=i; } if(c!=0) printf("no is not prime nd is divisible by %d",i); else printf("no is prime"); getch():}
OUTPUT
14. Write a programme to check whether a given number of 5 digits is palindrom or not? #include<stdio.h> #include<conio.h>
int main() { int a,b=0,c; clrscr(); printf("enter any number"); scanf("%d",&a); c=a ; while(a>0) { b=b*10; b=b+a%10; a=a/10; } if(b==c) printf("the number is palindrome");
OUTPUT
15. Write a programme to reverse a given number. #include<stdio.h> #include<conio.h> void main() { int r=0,d,m,n; clrscr(); printf("Enter a value:"); scanf("%d",&n); m=n; do { d=m%10; m= m/10; r=(r*10)+d; } while(m!=0); printf("%d is the reverse \n",r); getch();}
OUTPUT
16. Write a programme to convert a given digit to word. #include<stdio.h> #include<conio.h> void main() { int n; clrscr(); printf("Enter a digit"); scanf("%d",&n); switch(n) { case 0: printf("ZERO"); break; case 1: printf("ONE"); break; case 2: printf("TWO");
break; case 3: printf("THREE"); break; case 4: printf("FOUR"); break; case 5: printf("FIVE"); break; case 6: printf("SIX"); break; case 7: printf("SEVEN"); break; case 8: printf("EIGHT"); break;
OUTPUT
#include <stdio.h> #include<conio.h> void main() { int i,j,n; clrscr(); printf("Enter the number " ); scanf("%d",%n); j=1; for (i=1; i<=n; i++) j=j*i;
OUTPUT
18.Write a progr1am to swap two no. by using two variables. #include<stdio.h> #include<conio.h> void main() { int a,b; clrscr(); printf("Enter the value for a "); scanf("%d",&a); printf("Enter the value for b "); scanf("%d",&b); printf("before swapping"); printf("\n a=%d, b=%d",a,b); a=a+b; b=a-b; a=a-b; printf("\n after swapping\n a=%d,b=%d",a,b); getch(); }
OUTPUT
19. Write a programme to implement quadratic equation. #include<stdio.h> #include<conio.h> #include<math.h> void main() { int a,b,c,d=0; float x=0,y=0; clrscr(); printf("Enter the value for a"); scanf("%d",&a); printf("Enter the value for b"); scanf("%d",&b); printf("Enter the value for c"); scanf("%d",&c); d=(b*b)-4*a*c; if(d<0) { printf("the roots are imaginary");
} if(d==0) { printf("the roots are real and equal"); printf("\nthe roots are"); x=-b/(2*a); y=-b/(2*a); printf("\n%f ",x); printf("\n%f",y); } if(d>0) { printf("the roots are real and unequal"); printf("\nthe roots are"); x=-b+sqrt(d)/(2*a); y=-b-sqrt(d)/(2*a); printf("\n%f",x); printf("\n%f",y); } getch(); }
OUTPUT
20. Write a programme to print fabonacci series. #include<stdio.h> #include<conio.h> void main() { int n,a=0,b=1,c=0,i ; printf("enter the no of terms upto which u want to see the fibonacci"); scanf("%d",&n); printf("0 "); printf("1 "); for(i=0;i<=n;i++) { printf("%d",a+b); printf(" "); c=b; b=a+b; a=c; } getch(); }
OUTPUT
21.a Write a programme to print the following using for loop 1 22 333 4444 55555 #include<stdio.h> #include<conio.h> void main() { int i,j; for(i=1;i<=5;i++) { for(j=1;j<=i;j++) printf("%d",i); printf("\n"); } getch(); }
OUTPUT
21. b Write a programme to print the following using for loop 1 22 333 4444 55555
printf("%d ",i);
} getch(); } OUTPUT