Akhila 1.docx

  • Uploaded by: Apoorv Tyagi
  • 0
  • 0
  • May 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Akhila 1.docx as PDF for free.

More details

  • Words: 1,866
  • Pages: 32
APOORVA TYAGI

INSTITUTE OF INNOVATION IN TECHNOLOGY AND MANAGEMENT

36.Write a program to find square of a number using functions #include<stdio.h> int func(int); int main() { int no,square; printf("\n enter an no:"); scanf("\n %d",&no); square=func(no); clrscr(); printf("\n square of no is =%d",square); printf("\n APOORVA"); } int func(int temp) { return temp*temp; }

APOORVA TYAGI

INSTITUTE OF INNOVATION IN TECHNOLOGY AND MANAGEMENT

37.Write a program to swap two numbers using function (call by value) #include<stdio.h> void swap (int,int); int main() { int a,b; clrscr(); printf("\n enter any 2 numbers:"); scanf("%d %d",&a ,&b); printf("\n before swap value are: %d ,%d ,a,b"); swap(a,b); return 0; } void swap(int x,int y) { int z; z=x; x=y; y=z; printf("\n after swap value are : %d, %d,x,y"); printf("\n APOORVA"); }

APOORVA TYAGI

INSTITUTE OF INNOVATION IN TECHNOLOGY AND MANAGEMENT

38.Write a program to find factorial of a number using functions

#include<stdio.h> long factorial (int); void main() { int n,c; long fact =1; clrscr(); printf("\n enter a number to calculate it's factorial"); scanf("%d",&n); for(c=1;c<=n;c++) fact=fact*c; printf("\n factorial of %d =%d",n,fact); printf("\n APOORVA"); return 0; }

APOORVA TYAGI

INSTITUTE OF INNOVATION IN TECHNOLOGY AND MANAGEMENT

39.Write a program to show a table of a number using functions #include<stdio.h> void main() { void table(); clrscr(); table(); getch(); } void table() { int n,i,r; printf("\n enter a no to know table:"); scanf("%d",&n); for (i=1;i<=10;i++) { r=n*i; printf("\n %d *%d =%d",n,i,r); } printf("\n APOORVA"); }

APOORVA TYAGI

INSTITUTE OF INNOVATION IN TECHNOLOGY AND MANAGEMENT

40.Write a program to swap to numbers using call by reference #include<stdio.h> swap(int*,int*); int main() { int a,b; clrscr(); printf("\n enter value of a &b:"); scanf("%d %d",&a,&b); printf("\n before swapping :"); printf("\n a=%d b=%d",a,b); swap(&a,&b); printf("\n after swapping:"); printf("\n a=%d b=%d ",a,b); printf("\n APOORVA"); getch (); } swap(int*x,int*y) { int temp; temp=*x; *x=*y; *y=temp; }

APOORVA TYAGI

INSTITUTE OF INNOVATION IN TECHNOLOGY AND MANAGEMENT

41.Write a program to find largest of two numbers using functions #include<stdio.h> int findlargest(int a,int b) { if(a>b) { return a; } else { return b; } } int main() { int a,b,large; clrscr(); printf("\n enter two numbers:"); scanf("\n %d %d",&a,&b); large=findlargest(a,b); printf("\n largest is: %d", large); printf("\n APOORVA"); return 0; }

APOORVA TYAGI

INSTITUTE OF INNOVATION IN TECHNOLOGY AND MANAGEMENT

42.Write a program to find factorial of a number using recursion #include<stdio.h> int factorial(int); int main() { int num; int result; printf("enter a number to find it's factorial:"); scanf("%d",&num); if(num<0) { printf("\n factorial of negative number not possible"); } else { result=factorial(num); printf("\n the factorial of %d is %d",num,result); printf("\n APOORVA"); } return 0; } int factorial(int num) { if(num==0||num==1){return 1;} else { return(num*factorial(num-1));}}

APOORVA TYAGI

INSTITUTE OF INNOVATION IN TECHNOLOGY AND MANAGEMENT

43.Write a program to display fibonacci series using recursion #include<stdio.h> int fibo(int); int main() { int num; int result; clrscr(); printf("enter the nth number in fibonacci series:"); scanf("%d",&num); if(num<0){ printf("\n fibonacci of negative number is not possible:");} else { result =fibo(num); printf("\n the %d number in fibonacci series is %d ",num,result); printf("\n APOORVA");}return 0;} int fibo(int num){if(num==0){ return 0;} else if(num==1) { return 1; } else { return(fibo(num-1)+fibo(num-2)); } }

APOORVA TYAGI

INSTITUTE OF INNOVATION IN TECHNOLOGY AND MANAGEMENT

44.Write a program to show sum of 10 elements of array & show the average #include<stdio.h> void main() { int a[10],i,sum=0; float av; clrscr(); printf("\n enter elements of an array"); for(i=0;i<10;i++) scanf("%d",&a[i]); for(i=0;i<10;i++) sum=sum+a[i]; printf("sum=%d",sum); av=sum/10; printf("average =%2f",av); printf("\n APOORVA"); getch(); }

APOORVA TYAGI

INSTITUTE OF INNOVATION IN TECHNOLOGY AND MANAGEMENT

45. Write a program to find the maximum no in an array #include<stdio.h> int main() { int array[50],size,i,largest; printf("\n enter the size of the array:"); scanf("%d",&size); printf("\n enter the %d elements of the array:",size); for(i=0;i<size;i++) scanf("%d",&array[i]); largest=array[0]; for(i=1;i<size;i++) { if(largest<array[i]); largest=array[i]; } printf("\n largest element present in the given array is :%d",largest); printf("\n APOORVA"); return 0; }

APOORVA TYAGI

INSTITUTE OF INNOVATION IN TECHNOLOGY AND MANAGEMENT

46. Write a program to perform linear search #include<stdio.h> int main() { int array[100],search,c,n; clrscr(); printf("\n enter number of elements in array"); scanf("%d",&n); printf("\n enter %d integer (s)",n); for(c=0;c
APOORVA TYAGI

INSTITUTE OF INNOVATION IN TECHNOLOGY AND MANAGEMENT

47.Writa a program to perform binary search #include<stdio.h> int main() { int c,first,last,middle,n,search,array[100]; clrscr(); printf("\n enter number of elements"); scanf("%d",&n); printf("\n enter %d integers ",n); for(c=0;clast) printf("\n not found! %d isn't present in the list ",search); printf("\n APOORVA"); return 0;}

APOORVA TYAGI

INSTITUTE OF INNOVATION IN TECHNOLOGY AND MANAGEMENT

48. Write a program to perform bubble sort #include<stdio.h> int main() { int array[100],n,c,d,swap; clrscr(); printf("\n enter number of elements"); scanf("%d",&n); printf("\n enter %d integers",n); for(c=0;carray[d+1]) { swap=array[d]; array[d]=array[d+1]; array[d+1]=swap; } } } printf("\n sorted list in ascending order:"); for(c=0;c
APOORVA TYAGI

INSTITUTE OF INNOVATION IN TECHNOLOGY AND MANAGEMENT

49. Write a program to display a matrix #include<stdio.h> int main() { int i,j,m,n; int matrix[10][20]; clrscr(); printf("\n enter number of rows :"); scanf("%d",&m); printf("enter number of columns:"); scanf("%d",&n); for(i=0;i<m;i++) { for(j=0;j
APOORVA TYAGI

INSTITUTE OF INNOVATION IN TECHNOLOGY AND MANAGEMENT

50. Write a program to find the sum of two matrices #include<stdio.h> void main() { int a[3][2]={ {1,0}, {0,1}, {1,0} }; int b[3][2]={ {0,1}, {1,0}, {0,1} }; int c[3][2]; int i,j; for(i=0;i<=2;i++) { printf("\n"); for(j=0;j<=1;j++) { c[i][j]=a[i][j]+b[i][j]; printf("%d \t",c[i][j]); } } printf("\n APOORVA"); getch(); }

APOORVA TYAGI

INSTITUTE OF INNOVATION IN TECHNOLOGY AND MANAGEMENT

51.write a program to find the subtraction of matrix #include<stdio.h> void main() { int a[3][2]={ {1,0}, {0,1}, {1,0} }; int b[3][2]={ {0,1}, {1,0}, {0,1} }; int c[3][2]; int i,j; for(i=0;i<=2;i++) { printf("\n"); for(j=0;j<=1;j++) { c[i][j]=a[i][j]-b[i][j]; printf("%d \t",c[i][j]); } } printf("\n APOORVA"); getch(); }

APOORVA TYAGI

INSTITUTE OF INNOVATION IN TECHNOLOGY AND MANAGEMENT

52. Write a program to find the multiplication of a matrix #include<stdio.h> int main() { int m,n,p,q,c,d,k,sum=0; int first[10][10],second[10][10],multiply[10][10]; printf("\n enter the number of rows and column of first matrix "); scanf("%d %d ",&m,&n); printf("\n enter elememts of first matrix"); for(c=0;c<m;c++) for(d=0;d
APOORVA TYAGI

INSTITUTE OF INNOVATION IN TECHNOLOGY AND MANAGEMENT

53. Write a program to find the transpose a matrix #include<stdio.h> int main() { int a[10][10],transpose[10][10],r,c,i,j; clrscr(); printf("enter rows and columns of matrix :"); scanf("%d %d ",&r,&c); printf("\n enter elements of matrix :"); for(i=0;i
APOORVA TYAGI

INSTITUTE OF INNOVATION IN TECHNOLOGY AND MANAGEMENT

54. Write a program to add to number using pointer #include<stdio.h> int main() { int first ,second ,*p,*q,sum; clrscr(); printf("\n enter two integers to add"); scanf("%d %d ",&first,&second); p=&first; q=&second; sum=*p+ *q; printf("\n sum of the numbers =%d",sum); printf("\n APOORVA"); return 0; }

APOORVA TYAGI

INSTITUTE OF INNOVATION IN TECHNOLOGY AND MANAGEMENT

55. Write a program to find maximum number in array using pointer #include<stdio.h> int main() { int array[100],maximum,size,c,location=1; clrscr(); printf("\n enter the number of elememts in array"); scanf("%d ",&size); printf("\n enter %d integers",size); for(c=0;c<size;c++) scanf("%d",&array[c]); maximum=array[0]; for(c=1;c<size;c++) { if(array[c]>maximum) { maximum=array[c]; location=c+1; } } printf("\n maximum elements is present at location %d and it's value is %d",location,maximum); printf("\n APOORVA"); return 0; }

APOORVA TYAGI

INSTITUTE OF INNOVATION IN TECHNOLOGY AND MANAGEMENT

56. Write a program to reverse a number using pointer #include<stdio.h> void main() { int n,reverse=0; clrscr(); printf( "\n enter a number to reverse "); scanf("%d ",&n); while(n!=0) { reverse=reverse*10; reverse=reverse+n%10; n=n/10; } printf("\n reverse of entered number is=%d",reverse); printf("\n APOORVA"); return 0; }

APOORVA TYAGI

INSTITUTE OF INNOVATION IN TECHNOLOGY AND MANAGEMENT

57. Write a program to show input and output operations using string library functions #include<stdio.h> int main() { char name [30]; clrscr(); printf("\n enter name :"); gets(name); printf("\n name:"); puts(name); printf("\n APOORVA"); return 0; }

APOORVA TYAGI

INSTITUTE OF INNOVATION IN TECHNOLOGY AND MANAGEMENT

58. Write a program to find whether a string is palindrome or not #include<stdio.h> #include<string.h> int main() { char a[100],b[100]; clrscr(); printf("\n enter a string to check if it is a palindrome"); gets(a); strcpy(b,a); strrev(b); if(strcmp(a,b)==0) printf("\n the string is a palindrome"); else printf("\n the string isn't a palindrome "); printf("\n APOORVA"); return 0; }

APOORVA TYAGI

INSTITUTE OF INNOVATION IN TECHNOLOGY AND MANAGEMENT

59. Write a program to concatenate two strings #include<stdio.h> #include<string.h> void main() { char str1[]="APOORVA"; char str2[]="TYAGI"; strcat(str1,str2); clrscr(); printf(str1,str2); printf("\n APOORVA"); getch(); }

APOORVA TYAGI

INSTITUTE OF INNOVATION IN TECHNOLOGY AND MANAGEMENT

60. Write a program to find length of the string #include<stdio.h> #include<string.h> void main() { char str[]="HELLO"; int i; i=strlen(str); printf("%d",i); printf("\n APOORVA"); }

APOORVA TYAGI

INSTITUTE OF INNOVATION IN TECHNOLOGY AND MANAGEMENT

61. Write a program to enter book record #include<stdio.h> struct book { char name[10]; int price; float page; } b [10]; int main() { printf("\n enter record "); scanf("%c %d %f" ,&b[10].name ,&b[10].price,&b[10].page); printf("%c %d %f ",&b[10].name,&b[10].price,&b[10].page); printf("\n APOORVA"); }

APOORVA TYAGI

INSTITUTE OF INNOVATION IN TECHNOLOGY AND MANAGEMENT

62. Write a program to enter student record (name, roll no, course) #include<stdio.h> struct student { char name[50]; int roll; char course; } s; int main() { printf("\n enter information "); printf("\n enter name:"); scanf("%s",s.name); printf("\n enter roll no:"); scanf("%d",&s.roll); printf("\n enter course:"); scanf("%s",s.course); printf("\n displaying information:"); printf("\n name,course"); puts(s.name); puts(s.course); printf("\n roll no: %d",s.roll); printf("\n APOORVA"); return 0; }

APOORVA TYAGI

INSTITUTE OF INNOVATION IN TECHNOLOGY AND MANAGEMENT

63. Write a program to show the use of enum data type #include<stdio.h> enum week{sunday,monday,tuesday,wednesday,thrusday,friday,saturday}; int main() { enum week today; today=wednesday; printf(" day %d",today+1); printf("\n APOORVA"); return 0; }

APOORVA TYAGI

INSTITUTE OF INNOVATION IN TECHNOLOGY AND MANAGEMENT

64.program to create a file and write content in file #include<stdio.h> #include<string.h> int main(){ FILE *fp; clrscr(); fp=fopen("iitm.txt","w"); putc('a',fp); putc('b',fp); putc('c',fp); printf("%c",getc(fp)); printf("%c",getc(fp)); printf("%c",getc(fp)); fclose(fp); printf("\n APOORVA"); return 0;}

APOORVA TYAGI

INSTITUTE OF INNOVATION IN TECHNOLOGY AND MANAGEMENT

65 .program to display content of file on screen #include<stdio.h> #include<string.h> int main() {

FILE *fp; clrscr(); fp=fopen("iitm.txt","r"); if(fp==NULL){

printf("\n no such files"); exit(0); }

else{ printf("%c",getc(fp)); printf("%c",getc(fp)); printf("%c",getc(fp));} fclose(fp); return 0;}

APOORVA TYAGI

INSTITUTE OF INNOVATION IN TECHNOLOGY AND MANAGEMENT

66.program to copy the content of one file into another file using command line arguments #include<stdio.h> #include int main(int argc,char*argv[]) { FILE*fp1,*fp2; char ch; clrscr(); if(argc!=3) { printf(" insufficient argument"); exit(0); } fp1=fopen(argv[1],"r"); fp2=fopen(argv[2],"w"); if(fp1==NULL||fp2==NULL) { printf("unable to open file"); exit(0); } while(!feof(fp1)) { ch=fgetc(fp1); fputc(ch,fp2); }

APOORVA TYAGI printf("file successfully copied"); fclose(fp1); fclose(fp2); return 0; }

INSTITUTE OF INNOVATION IN TECHNOLOGY AND MANAGEMENT

Related Documents


More Documents from "Kevin Bran"