int main()
{
char str[90];
printf("Enter name :");
flushall();/* removes input stream blockage*/
gets(str);
printf("\n Hello %s ",str);
}
#include <stdio.h>
#include <conio.h>
long int findFactorial(int mnum);
int main()
{
int num;
long int ans;
clrscr();
printf("Enter number ");
scanf("%d",&num);
ans = findFactorial(num);
printF("\n Factorial of %d is %ld",num, ans);
getch();
return 0;
}
long int findFactorial(int mnum)
{long int a=1;
int cnt =1;
while(cnt <=mnum)
{
a = a *cnt;
cnt = cnt +1;
}
return a;
}
String : group of characters terminated by null character
%s is used as format specifier
input and output the name
int main()
{
char str[90];
printf("Enter name :");
scanf("%s",str);
printf("\n Hello %s ",str);
}
/*convert given string into capital case */
#include <stdio.h>
#include <conio.h>
void toCapital(char *ptr);
void toSmall(char *ptr);
int main()
{
char str[90];
clrscr();
printf("Enter string :");
flushall();
gets(str);
toCapital(str);
puts(str);
toSmall(str);
puts(str);
getch();
return 0;
}
void toCapital(char *ptr)
{
while(*ptr!='\0')
{
if (*ptr >='a' && *ptr <='z')
{
*ptr = *ptr -32;
}
ptr = ptr +1;
}
}
/* input word and output the same using function */
#include <stdio.h>
#include <conio.h>
void admission(char *ss);
void cancel(char *ss);
int main()
{
char bookname[90];
clrscr();
printf("Enter bookname ");
admission(&bookname[0]);
cancel(&bookname[0]);
getch();
return 0;
}
void admission(char *ss)
{
flushall();
gets(ss);
}
void cancel(char *ss)
{
puts(ss);
}
int findLength(char *str);
int main()
{
char str[90];
int len;
printf("Enter word ");
flushall();
gets(str);
len = findLength(&str[0]);
printf("\n Length of %s is %d",str,len);
getch();
return 0;
}
int findLength(char *str)
{
int i=0;
while(*str !='\0')
{
i =i+1;
str = str +1;
}
return i;
}
/**************************
Write a C program to find ASCII values of a character
***************************/
#include <stdio.h>
#include <conio.h>
int main()
{
char ch;
clrscr();
printf("Enter character");
scanf("%c",&ch);
printf("\n %c %d ",ch,ch);
getch();
return 0;
}
/**********
Write a program to concatenate 2 strings .
using function
*********/
#include <stdio.h>
#include <conio.h>
#include <string.h>
void pstrcat(char mfirst[80], char msname[80]);
int main()
{
char first[80],sname[80];
clrscr();
printf("Enter first name :");
flushall();
gets(first);
printf("Enter sname :");
flushall();
gets(sname);
pstrcat(first,sname);
puts(first);
getch();
return 1;
}
void pstrcat(char mfirst[80],char msname[80])
{
int i=0,j;
while (mfirst[i]!='\0')
{
i=i+1;
}
j=0;
while(msname[j]!='\0')
{
mfirst[i] = msname[j];
i=i+1;
j=j+1;
}
mfirst[i]='\0';
}
/**********
Write a program to concatenate 3 strings .
using function
using pointer
*********/
#include <stdio.h>
#include <conio.h>
#include <string.h>
void pstrcat(char *f, char *s);
int main()
{
char first[80],middle[80],sname[80];
clrscr();
printf("Enter first name :");
flushall();
gets(first);
printf("Enter middle name ");
flushall();
gets(middle);
printf("Enter sname :");
flushall();
gets(sname);
pstrcat(first,middle);
pstrcat(first,sname);
puts(first);
getch();
return 1;
}
void pstrcat(char *d, char *s)
{
while (*d!='\0')
{
d=d+1;
}
while(*s!='\0')
{
*d = *s;
s=s+1;
d=d+1;
}
*d='\0';
}
/**********
Write a C program to count digit, spaces, special character, alphabets in string.
*********/
#include <stdio.h>
#include <conio.h>
#include <string.h>
int main()
{
char mobilesms[80]={"123how are you? Wish you \'best of luck\'"};
int i, digitcnt=0, spacecnt =0, spcnt=0,alphacnt=0;
clrscr();
/*
printf("Enter message :");
flushall();
gets(first);
*/
i=0;
while(mobilesms[i]!='\0')
{
if(mobilesms[i]>=48 && mobilesms[i]<=57)
{
digitcnt++;
}
if(mobilesms[i] ==' ')
{
spacecnt++;
}
if((mobilesms[i] >='a'&& mobilesms[i]<='z')||(mobilesms[i] >='A'&& mobilesms[i]<='Z'))
{
alphacnt++;
}
if(!((mobilesms[i] >='a'&& mobilesms[i]<='z')||(mobilesms[i] >='A'&& mobilesms[i]<='Z')||(mobilesms[i] >='0'&& mobilesms[i]<='9')))
{
spcnt++;
}
i=i+1;
}
printf("\n digits %d",digitcnt);
printf("\n spaces %d",spacecnt);
printf("\n alphabets %d",alphacnt);
printf("\n special character %d",spcnt);
getch();
return 0;
}
/**********
Write a C program to count digit, spaces, special character, alphabets in string.
using library functions from ctype.h
*********/
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <ctype.h>
int main()
{
char mobilesms[80]={"123how are you? Wish you \'best of luck\'"};
int i, digitcnt=0, spacecnt =0, spcnt=0,alphacnt=0;
clrscr();
printf("Enter message :");
flushall();
//gets(mobilesms);
scanf("%s",mobilesms);
i=0;
while(mobilesms[i]!='\0')
{
if(isdigit(mobilesms[i]))
{
digitcnt++;
}
else
{if(isspace(mobilesms[i]))
{
spacecnt++;
}
else
if(isalpha(mobilesms[i]))
{
alphacnt++;
}
else
{
spcnt++;
}
}
i=i+1;
}
printf("\n digits %d",digitcnt);
printf("\n spaces %d",spacecnt);
printf("\n alphabets %d",alphacnt);
printf("\n special character %d",spcnt);
getch();
return 0;
}
/**********
Write a C program to count digit, spaces, special character, alphabets in string.
using user defined functions
*********/
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <ctype.h>
int isDigit(char mx);
int isSpace(char mx);
int isSpecial(char mx);
int isAlphabet(char mx);
int main()
{
char mobilesms[80]={"123how are you? Wish you \'best of luck\'"};
int i, digitcnt=0, spacecnt =0, spcnt=0,alphacnt=0;
clrscr();
printf("Enter message :");
flushall();
//gets(mobilesms);
scanf("%s",mobilesms);
i=0;
while(mobilesms[i]!='\0')
{
if(isDigit(mobilesms[i]))
{
digitcnt++;
}
else
{if(isSpace(mobilesms[i]))
{
spacecnt++;
}
else
if(isAlphabet(mobilesms[i]))
{
alphacnt++;
}
else
{
spcnt++;
}
}
i=i+1;
}
printf("\n digits %d",digitcnt);
printf("\n spaces %d",spacecnt);
printf("\n alphabets %d",alphacnt);
printf("\n special character %d",spcnt);
getch();
return 0;
}
int isDigit(char mx)
{
if(mx>='0' && mx <='9')
{
return 1;
}
else
{
return 0;
}
}
int isAlphabet(char mx)
{
if((mx >='a'&& mx<='z')&& (mx >='A' && mx <='Z'))
return 1;
else
return 0;
}
int isSpace(char mx)
{
if(mx ==' ')
return 1;
else
return 0;
}
int isSpecial(char mx)
{
if(!((mx >='a'&& mx<='z')||(mx >='A'&& mx<='Z')||(mx >='0'&& mx<='9')))
return 1;
else
return 0;
}
/**********
Write a C program to count digit, spaces, special character, alphabets in string.
using user defined functions
using pointer
*********/
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <ctype.h>
void getData (char msg[80], int *digit,int *space, int *special, int *alpha);
int isDigit(char mx), isSpace(char mx), isSpecial(char mx), isAlphabet(char mx);
int main()
{
char mobilesms[80]={"123how are you? Wish you \'best of luck\'"};
int i, digitcnt=0, spacecnt =0, spcnt=0,alphacnt=0;
clrscr();
printf("Enter message :");
flushall();
//gets(mobilesms);
scanf("%s",mobilesms);
getData(mobilesms, &digitcnt, &spacecnt, &spcnt,&alphacnt);
printf("\n digits %d",digitcnt);
printf("\n spaces %d",spacecnt);
printf("\n alphabets %d",alphacnt);
printf("\n special character %d",spcnt);
getch();
return 0;
}
void getData (char msg[80], int *digit,int *space, int *special, int *alpha)
{ int i;
i=0;
while(msg[i]!='\0')
{
if(isDigit(msg[i])==1)
{ // printf("\n %c",msg[i]);getch();
(*digit)++;
}
if(isSpace(msg[i])==1)
{
(*space)++;
}
if(isAlphabet(msg[i])==1)
{
(*alpha)++;
}
if(isSpecial(msg[i])==1)
{
(*special)++;
}
i=i+1;
}
}
int isDigit(char mx)
{
if(mx>='0' && mx <='9')
{
return 1;
}
else
{
return 0;
}
}
int isAlphabet(char mx)
{
if((mx >='a'&& mx<='z')&& (mx >='A' && mx <='Z'))
return 1;
else
return 0;
}
int isSpace(char mx)
{
if(mx ==' ')
return 1;
else
return 0;
}
int isSpecial(char mx)
{
if(!((mx >='a'&& mx<='z')||(mx >='A'&& mx<='Z')||(mx >='0'&& mx<='9')))
return 1;
else
return 0;
}
/**********
Write a C Program to declare the structure of the book
with data member book, price and pages
*********/
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <ctype.h>
struct book
{
char bookname[80];
int price,pages;
};
void main()
{
struct book b;
clrscr();
printf("Enter bookname ");
flushall();
gets(b.bookname);
printf("Enter price ");
scanf("%d",&b.price);
printf("Enter pages ");
scanf("%d",&b.pages);
printf("\n %s %d %d",b.bookname,b.price,b.pages);
getch();
}
#include <stdio.h>
struct price
{
int num;
};
struct book
{
char name[20];
int code;
struct price m;
};
void input(struct book *p);
void output(struct book *p);
int main()
{
int i;
struct book s[2];
for(i=0;i<2;i++)
{
input(&s[i]);
}
for(i=0;i<2;i++)
{
output(&s[i]);
}
return 0;
}
void input(struct book *p)
{
printf("enter name of book");
scanf("%s",p->name);
printf("enter code");
scanf("%d",&p->code);
printf("enter price");
scanf("%d",&p->m.num);
}
void output(struct book *p)
{
printf("\n %s %d %d",p->name,p->code,p->m.num);
}
/**********
17. Create a structure named company which has
name, address, phone and noOfEmployee as member variables. Read name of 10 companies,
its address, phone and noOfEmployee. Finally display these members value.
*********/
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <ctype.h>
struct employee
{
char companyname[80],add[90];
int phone,noofemp;
};
void main()
{
struct employee b[10];
int i=0;
while(i<2)
{
clrscr();
printf("Enter companyname ");
flushall();
gets(b[i].companyname);
printf("Enter address ");
flushall();
gets(b[i].add);
printf("Enter phone ");
scanf("%d",&b[i].phone);
printf("Enter noofemp ");
scanf("%d",&b[i].noofemp);
i++;
}
i=0;
while(i<2)
{
printf("\n %s %d %d",b[i].companyname,b[i].phone,b[i].noofemp);
i=i+1;
}
getch();
}
/**********
Enter the marks of 5 students in
Chemistry, Mathematics and Physics
using a Structure named Marks
having elements
roll no., name, chem_marks, maths_marks and phy_marks and
then display the percentage of each student
*********/
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <ctype.h>
struct Employee
{
int rollnum;
char name[90];
int chem, maths, phy,sum;
};
int main()
{
struct Employee e[5];
int i;
/* input */
i=0;
while(i<5)
{
printf("Enter Rollno ");
scanf("%d",&e[i].rollnum);
printf("Enter name ");
scanf("%s",e[i].name);
printf("Enter marks in Chemistry ");
scanf("%d",&e[i].chem);
printf("Enter mar in maths ");
scanf("%d",&e[i].maths);
printf("Enter marks in physics :");
scanf("%d",&e[i].phy);
e[i].sum = e[i].chem + e[i].maths + e[i].phy;
i=i+1;
}
i=0;
while(i<5)
{
printf("\n %d %s %d %d %d %d ",e[i].rollnum, e[i].name,e[i].chem,e[i].maths,e[i].phy,e[i].sum);
i=i+1;
}
getch();
}
/**************************
Program to add digits of number
***************************/
#include <stdio.h>
#include <conio.h>
int main()
{
int num, d1,d2,d3,d4,d5;
printf("\nEnter 2digited number :");
scanf("%d",&num);
d1 = num/10;
d2 = num %10;
printf("sum %d",(d1+d2));
getch();
printf("\nEnter 3digited number :");
scanf("%d",&num);
d1 = num/100;
num = num%100;
d2 = num %10;
d3 = num %10;
printf("sum %d",(d1+d2+d3));
printf("\nEnter 4digited number :");
scanf("%d",&num);
d1 = num/1000;
num = num%1000;
d2 = num /100;
num = num %100;
d3 = num /10;
d4 = num %10;
printf("sum %d",(d1+d2+d3+d4));
getch();
return 0;
}
/**************************
Program to add digits of number using loop
***************************/
#include <stdio.h>
#include <conio.h>
int main()
{
int num, sum, digit;
sum =0;
printf("\nEnter number :");
scanf("%d",&num);
while(num>0)
{
digit = num%10;
sum += digit;
num = num/10;
}
printf("\n Sum %d ",sum);
getch();
return 0;
}
/**************************
Program to add digits of number
using loop
using function
***************************/
#include <stdio.h>
#include <conio.h>
int getSumOfDigits(int mnum);
int main()
{
int num, sum, digit;
sum =0;
printf("\nEnter number :");
scanf("%d",&num);
sum = getSumOfDigits(num);
printf("\n sum of digits %d is %d",num,sum);
getch();
return 0;
}
int getSumOfDigits(int mnum)
{
int sum =0,digit;
while(mnum>0)
{
digit = mnum%10;
sum += digit;
mnum = mnum/10;
}
return sum;
}
/**************************
19. Write a program in C to check Armstrong number
between 1 to 500.
***************************/
#include <stdio.h>
#include <conio.h>
int isArmstrong(int mnum);
int main()
{
int cnt;
clrscr();
cnt =1;
while(cnt<=1000)
{
if(isArmstrong(cnt)==1)
{
printf("\n %d ",cnt);
}
cnt=cnt+1;
}
getch();
return 0;
}
int isArmstrong(int mnum)
{
int temp,sum, digit;
temp = mnum;
sum =0;
while(mnum > 0)
{
digit = mnum %10;
sum += (digit*digit *digit);
mnum = mnum /10;
}
if(sum == temp)
{
return 1;
}
else
{
return 0;
}
}
/**************************
function calling itself is called recursive function
show 15 to 10
***************************/
#include <stdio.h>
#include <conio.h>
int show(int high,int low);
int main()
{
clrscr();
show(15,10);
getch();
return 0;
}
int show(int high,int low)
{
if(high<low)
{
return 1;
}
else
{
printf("%d ",high);
high= high-1;
show(high,low);
}
}
/**************************
function calling itself is called recursive function
showTable
***************************/
#include <stdio.h>
#include <conio.h>
int showTable(int mnum,int low,int high);
int main()
{
int num;
clrscr();
printf("\nEnter number :");
scanf("%d",&num);
showTable(num, 1,10);
getch();
return 0;
}
int showTable(int mnum, int low,int high)
{
if(low >high)
{
return 1;
}
else
{
printf("%d ",(mnum * low));
low = low+1;
showTable(mnum,low,high);
}
}
/**************************
function calling itself is called recursive function
show 1 to 5
***************************/
#include <stdio.h>
#include <conio.h>
int show(int low,int high);
int main()
{
clrscr();
show(1,5);
getch();
return 0;
}
int show(int low,int high)
{
if(low>high)
{
return 1;
}
else
{
printf("%d ",low);
low= low+1;
show(low,high);
}
}
/**************************
armstrong : sum of the cubes of the digits of a number if
equal to number itself then
it is called armstrong number
using function
***************************/
#include <stdio.h>
#include <conio.h>
int isArmstrong(int mnum);
int main()
{
int num,sum,digit,temp;
clrscr();
printf("Enter number ");
scanf("%d",&num);
if(isArmstrong(num)==1)
{
printf("\n %d is armstrong",num);
}
else
{
printf("\n %d is not armstrong",num);
}
getch();
return 0;
}
int isArmstrong(int mnum)
{
int temp,sum, digit;
temp = mnum;
sum =0;
while(mnum > 0)
{
digit = mnum %10;
sum += (digit*digit *digit);
mnum = mnum /10;
}
if(sum == temp)
{
return 1;
}
else
{
return 0;
}
}
/**************************
armstrong : sum of the cubes of the digits of a number if
equal to number itself then
it is called armstrong number
***************************/
#include <stdio.h>
#include <conio.h>
int main()
{
int num,sum,digit,temp;
clrscr();
printf("Enter number ");
scanf("%d",&num);
temp = num;
sum =0;
while(num > 0)
{
digit = num %10;
sum += (digit*digit *digit);
num = num /10;
}
if(sum == temp)
{
printf("\n armstrong ");
}
else
{
printf("\n Not a armstrong");
}
getch();
return 0;
}
/**************************
function calling itself is called recursive function
sum of numbers between 1 to 5
***************************/
#include <stdio.h>
#include <conio.h>
int getSum(int low,int high);
int main()
{
clrscr();
printf("\n sum of numbers between 1 to 5 : %d",getSum(1,5));
getch();
return 0;
}
int getSum(int low,int high)
{
int t;
if(low >high)
{
return 0;
}
else
{
t= low+getSum(low+1,high);
return t;
}
}
/**************************
function calling itself is called recursive function
product of numbers between 1 to 5
***************************/
#include <stdio.h>
#include <conio.h>
int getproduct(int low,int high);
int main()
{
clrscr();
printf("\n product of numbers between 1 to 5 : %d",getproduct(1,5));
getch();
return 0;
}
int getproduct(int low,int high)
{
int t;
if(low >high)
{
return 1;
}
else
{
t= low*getproduct(low+1,high);
return t;
}
}
#include <stdio.h>
#include <conio.h>
#include <string.h>
void drawBox(int fromx,int fromy, int width, int ht)
{int i;
textcolor(YELLOW); textbackground(MAGENTA);
gotoxy(fromx,fromy);cprintf("%c",201);
gotoxy(fromx+width,fromy);cprintf("%c",187);
gotoxy(fromx,fromy+ht);cprintf("%c",200);
gotoxy(fromx+width,fromy+ht);cprintf("%c",188);
for(i=fromx+1; i<fromx+width;i++)
{
gotoxy(i,fromy); cprintf("%c",205);
gotoxy(i,fromy+ht);cprintf("%c",205);
}
for(i=fromy+1;i<fromy+ht;i++)
{
gotoxy(fromx,i);cprintf("%c",186);
gotoxy(fromx+width,i);cprintf("%c",186);
}
}
int main()
{
clrscr();
drawBox(1,1,68,3);
drawBox(70,1,9,23);
drawBox(1,21,68,3);
getch();
return 0;
}
#include <stdio.h>
#include <conio.h>
#include <string.h>
void drawBox(int fromx,int fromy, int width, int ht)
{int i;
gotoxy(fromx,fromy);printf("%c",201);
gotoxy(fromx+width,fromy);printf("%c",187);
gotoxy(fromx,fromy+ht);printf("%c",200);
gotoxy(fromx+width,fromy+ht);printf("%c",188);
for(i=fromx+1; i<fromx+width;i++)
{
gotoxy(i,fromy); printf("%c",205);
gotoxy(i,fromy+ht);printf("%c",205);
}
for(i=fromy+1;i<fromy+ht;i++)
{
gotoxy(fromx,i);printf("%c",186);
gotoxy(fromx+width,i);printf("%c",186);
}
}
void showTitle(char *s)
{
drawBox(1,1,79,3);
gotoxy(2,2);textcolor(YELLOW);
//setbground(BLUE);
cprintf("%s",s);
}
void showStatus(char *s)
{
drawBox(1, 22, 78, 3);
gotoxy(2, 23);
textcolor(YELLOW);
cprintf("%s", s);
}
int main()
{
clrscr();
showTitle("Pushpam Computer:");
showStatus("Programming is the best experience in the world");
//drawBox(60,2,8,20);
getch();
return 0;
}
#include <stdio.h>
#include <conio.h>
/* Write a user defined function that reads student information
*/
void main()
{
char Name [80],Address[80],Email[90];
int Eno,Salary;
void inputInformation(char mName[80],char mAddress[80],char mEmail[90],int *mEno, int *mSalary);
void outputInformation(char mName[80],char mAddress[80],char mEmail[90],int mEno,int mSalary);
clrscr();
inputInformation(Name, Address,&Email[0],&Eno,&Salary);
outputInformation(Name, Address,Email, Eno,Salary);
getch();
}
void inputInformation(char mName[80],char mAddress[80],char mEmail[80], int *mEno,int *mSalary)
{
printf("Enter Name :");
//scanf("%s",mName);
gets(mName);
printf("Enter Address :");
//scanf("%s",mAddress);
gets(mAddress);
printf("Enter Email");
gets(mEmail);
printf("Enter Rno:");
scanf("%d",mEno);
printf("Enter Marks :");
scanf("%d",mSalary);
}
void outputInformation(char mName[80],char mAddress[80],char mEmail[80],int mEno,int mSalary)
{
puts(mName);
puts(mAddress);
puts(mEmail);
printf("%d %d ",mEno,mSalary);
}
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
/* comment on function returning multiple values
elaborate with an example
*/
/* let us input month no return days*/
int getDays(int mahina);
int main()
{
int mno;
clrscr();
printf("Enter Month number :");
scanf("%d",&mno);
printf(" It has %d days:",getDays(mno));
getch();
return 0;
}
int getDays(int mahina)
{
switch(mahina)
{
case 1: return 31;
case 2: return 28;
case 3: return 31;
case 4: return 30;
case 5: return 31;
case 6: return 30;
case 7: return 31;
case 8: return 30;
case 9: return 31;
case 10: return 30;
case 11: return 31;
case 12: return 30;
}
}
#include <stdio.h>
#include <conio.h>
/*write a c function to accept two numbers and return addtion of numbers
and multiplication */
int getNumber();
int getOperation(int A,int B,char what);
int main()
{
int Num1, Num2,Ans;
char operation;
clrscr();
Num1 = getNumber();
Num2 = getNumber();
printf("\na] Additon");
printf("\bm] Mulitplication");
printf("Choice please:");
flushall();
scanf("%c",&operation);
switch(operation)
{
case 'a':
case 'A':Ans = getOperation(Num1,Num2,'a');
printf("\n %d",Ans);
break;
case 'm' :
case 'M':Ans = getOperation(Num1,Num2,'m');
printf("%d",Ans);
}
getch(); getch();
return 0;
}
int getNumber()
{
int x;
printf("enter numbers");
scanf("%d",&x);
return x;
}
int getOperation(int A, int B, char what)
{
int ans;
if(what =='a' ||what =='A')
ans= A+B;
if(what =='m' ||what =='M')
ans=A*B;
return ans;
}
#include <stdio.h>
#include <conio.h>
/* what is call by reference , explain with example*/
void exchange(int *mancient, int *mmodern);
void swap(int moldvalue, int newvalue);
int main()
{
int oldvalue, newvalue, ancient, modern;
oldvalue =10;newvalue =20; ancient =15; modern = 40;
clrscr();
printf(" Old value = %d new value = %d\n",oldvalue,newvalue);
printf(" ancient = %d modern = %d\n",ancient, modern);
getch();
swap(oldvalue, newvalue);
exchange(&ancient,&modern);
printf(" Old value = %d new value = %d\n",oldvalue,newvalue);
printf(" ancient = %d modern = %d\n",ancient, modern);
getch();
return 0;
}
void swap(int moldvalue, int mnewvalue)
{
int tempa;
tempa=moldvalue;
moldvalue=mnewvalue;
mnewvalue=tempa;
}
void exchange(int *mancient, int *mmodern)
{
int tempb;
tempb=*mancient;
*mancient=*mmodern;
*mmodern=tempb;
}
#include <stdio.h>
#include <conio.h>
int main()
{
int show(int low,int high);
clrscr();
show(1,3);
getch();
return 0;
}
int show(int low,int high)
{
if(low>high)
return 0;
else
{printf(" %d",low);
low = low+1;
show(low,high);
}
}
#include <stdio.h>
/* factorial of a number using function and
also show actual parameters and formal argument */
#include <conio.h>
int main()
{
int x;
long int ans;
long int findFactorial(int mx);
clrscr();
printf("Enter number ");
scanf("%d",&x);
ans = findFactorial(x);
printf("\n Factorial of %d is %ld",x,ans);
getch();
return 0;
}
long int findFactorial(int mx)
{
long int ans =1;
while(mx>=1)
{ ans = ans * mx--;
}
return ans;
}
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *P;
P=fopen("note.txt","w");
fprintf(P,"file handlig is like database");
fclose(P);
}
#include <conio.h>
int main()
{
int doSum(int low,int high);
int low,high,sum;
clrscr();
printf("Enter low ");
scanf("%d",&low);
printf("Enter high:");
scanf("%d",&high);
sum = doSum(low,high);
printf("\n Sum is %d",sum);
getch();
return 0;
}
int doSum(int low,int high)
{
int t;
if( low >high)
return 0;
else
{
t = low+doSum(low+1,high);
return t;
}
}
#include <stdio.h>
/* factorial of a number using function and
also show actual parameters and formal argument */
#include <conio.h>
int main()
{
int x;
long int ans;
long int findFactorial(int mx);
clrscr();
printf("Enter number ");
scanf("%d",&x);
ans = findFactorial(x);
printf("\n Factorial of %d is %ld",x,ans);
getch();
return 0;
}
long int findFactorial(int mx)
{
long int ans =1;
while(mx>=1)
{ ans = ans * mx--;
}
return ans;
}
#include <stdio.h>
/* factorial of a number using function and
also show actual parameters and formal argument */
#include <conio.h>
int main()
{
int x;
long int ans;
long int findFactorial(int mx);
clrscr();
printf("Enter number ");
scanf("%d",&x);
ans = findFactorial(x);
printf("\n Factorial of %d is %ld",x,ans);
getch();
return 0;
}
long int findFactorial(int mx)
{
long int ans =1;
while(mx>=1)
{ ans = ans * mx--;
}
return ans;
}
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *P;
char str[80];
int i; clrscr();
P=fopen("note.txt","w");
i=1;
while(i<=5)
{
printf("Enter Name :");
scanf("%s",str);
fprintf(P,"%s ",str);
i++;
}
fclose(P);
}
#include<stdio.h>
#include<conio.h>
#include<dos.h>
void main()
{
FILE *f;
char name[70],ch;
clrscr();
printf("enter name of file to read ");
scanf("%s",name);
f=fopen(name,"r");
while(!feof(f))
{
fscanf(f,"%c",&ch);
printf("%c",ch);
delay(300);
}
fclose(f);
}
#include<stdio.h>
#include<conio.h>
void main()
{
char str[80];
FILE *P;
clrscr();
P=fopen("note.txt","r");
while(!feof(P))
{fscanf(P,"%s",str);
printf("\n\t%s",str);
}
getch();
fclose(P);
}
#include<stdio.h>
#include<conio.h>
void main()
{
int n,num;
FILE *fp;
fp = fopen("Number.dat","w");
printf("How many numbers :");
scanf("%d",&n);
while(n-->=1)
{
printf("Enter data :");
scanf("%d",&num);
fprintf(fp,"%d\n",num);
}
fclose(fp);
}