C++ program to swap two numbers using pointers
#include<iostream.h> #include<conio.h> void main() { clrscr(); int *a,*b,*temp; cout<<“Enter value of a and b:”; cin>>*a>>*b; temp=a; a=b; b=temp; cout<<“nAfter swapingna=”<<*a<<“nb=”<<*b; getch(); }
#include<iostream.h> #include<conio.h> void main() { clrscr(); int *a,*b,*temp; cout<<“Enter value of a and b:”; cin>>*a>>*b; temp=a; a=b; b=temp; cout<<“nAfter swapingna=”<<*a<<“nb=”<<*b; getch(); }
#include<iostream.h> #include<conio.h> #include<math.h> void main() { clrscr(); double sum=0,a; int n,i; cout<<“1+1/2^2+1/3^3+…..+1/n^n”; cout<<“nEnter value of n:”; cin>>n; for(i=1;i<=n;++i) { a=1/pow(i,i); sum+=a; } cout<<“Sum=”<<sum; getch(); }
#include<stdio.h> #include<conio.h> void main() { int i,j,k,n,a,b; clrscr(); printf(“How many lines?”); scanf(“%d”,&n); n=n*2; for(i=1;i<n;i+=2) { for(j=n-1;j>i;j-=2) printf(” “); for(k=1;k<=(i/2)+1;++k) printf(“%d”,k); for(k=i/2;k>=1;–k) printf(“%d”,k); printf(“n”); } getch(); }
#include<stdio.h> #include<conio.h> #include<string.h> void main() { int i,j,flag=1,len; char str[50]; clrscr(); printf(“Enter any string:”); gets(str); len=strlen(str); for(i=0,j=len-1;i<len/2;++i,–j) if(str[i]!=str[j]) { flag=0; break; } if(flag) printf(“String is palindrome“); else printf(“String is not palindrome”); getch(); }
#include<stdio.h> #include<conio.h> #include<string.h> void main() { int i,n; char a[30]; clrscr(); printf(“Enter any string:”); gets(a); n=strlen(a); printf(“Reverse of string:”); for(i=(n-1);i>=0;–i) printf(“%c”,a[i]); getch(); }
#include<stdio.h> #include<conio.h> void main() { int i; char str[50]; clrscr(); printf(“Enter a string:”); gets(str); for(i=0;str[i]!=’’;++i); printf(“Lenth of string is %d”,i); getch(); }
#include<stdio.h> #include<conio.h> #include<string.h> void main() { int i,j,n,ch1,ch2; char a[50],temp; clrscr(); printf(“Enter any string:”); scanf(“%s”,a); n=strlen(a); for(i=1;i<n;++i) for(j=0;j<(n-i);++j) { ch1=a[j]; ch2=a[j+1]; if(ch1>ch2) { temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; } } printf(“String after arranging %s”,a); getch(); }
#include<stdio.h> #include<conio.h> #include<stdlib.h> struct student { int rollno; char *name; int m1,m2,m3; }s1; void main() { FILE *fp; clrscr(); fp=fopen(“Record.dat”,”wb”); //opening binary file in writing mode if(fp==NULL) { printf(“File could not open”); exit(0); } printf(“Enter student detailsn”); printf(“Roll No:”); scanf(“%d”,&s1.rollno); printf(“Name:”); scanf(“%s”,s1.name); printf(“Marks in three subjects:”); scanf(“%d%d%d”,&s1.m1,&s1.m2,&s1.m3); fwrite(&s1,sizeof(s1),1,fp); //writing to binary file printf(“nRecord has …
C program to write student record to a binary file Read More »