Professional Documents
Culture Documents
1. Program To Read Two Numbers And Print The Sum Of Given Two Numbers.
# include <stdio.h>
# include <conio.h>
main()
{
int a,b, sum;
clrscr ();
printf (ENTER VALUE FOR A ; );
scanf (%d,&a);
printf(ENTER VALUE FOR B ;);
scanf(%d,&b);
sum=a+b;
printf(Sum Of Given Two Numbers are %d, sum);
getch();
}
2. Program To Accept Student Roll No, Marks in 3 Subjects and Calculate Total, Average and
Print it.
# include <stdio.h>
# include <conio.h>
main()
{ int r,b,c,d, tot, avg;
clrscr();
printf (ENTER STUDENT RNO ; );
scanf (%d,&r);
printf(ENTER FIRST SUBJECT MARKS ;);
scanf(%d,&b);
printf(ENTER SECOND SUBJECT MARKS;);
scanf(%d,&c);
printf(ENTER THIRD SUBJECT MARKS ;);
scanf(%d,&d);
tot=b+c+d;
avg=tot/3;
printf(\t STUDENT RNO ; %d ,r);
printf(\t FIRST SUBJECT MARKS ;%d ,b);
printf(\t SECOND SUBJECT MARKS ;%d ,C);
printf(\t THIRD SUBJECT MARKS ;%d ,d);
printf(\t TOTAL :%d,tot);
printf(\t AVERAGE MARKS ; %d, avg);
getch();
}
3. Program To Read Three Numbers And Print The Biggest Of Given Three Numbers(**)
# include <stdio.h>
# include <conio.h>
main( )
{
int a,b,c,big=0;
clrscr( );
printf(ENTER VALUE FOR A:);
scanf(%d,&a);
printf(ENTER VALUE FOR B:);
scanf(%d,&b);
print(ENTER VALUE FOR C:);
scanf(%d,&c);
if (a>big)
big=a ;
if(b>big)
big=b;
if (c>big)
big=c;
printf (BIGGEST OF ABOVE GIVEN THREE NUMBER IS %d,big)
getch( );
}
4.Program To Read A Number And Find Whether The Given Number Is Even Or Odd.(**)
# include <stdio.h>
# include <conio.h>
main()
{
int n,r;
clrscr();
printf(ENTER A NUMBER ;);
scanf(%d, &n);
r=n%2;
if(r= = 0)
printf(the above given number is even number);
else
printf(the above given number is odd number);
getch();
}
5. Program to accept a year and check whether the given year is Leap Year or not.
# include <stdio.h>
# include <conio.h>
main( )
{
int y;
clrscr( );
printf(enter a year:);
scanf(%d,&y);
if(y%4= =0&&y%100!=0|| y%400= =0);
printf(the above given year is a Leap Year);
else
printf(the above given year is Not a Leap Year);
getch();
}
6. Program to accept a two digit number and print the sum of individual digits.
# include <stdio.h>
# include <conio.h>
main( )
{ int a,b,c,d;
clrscr( );
printf ( Enter a two digit number :);
scanf ( %d, &a);
b=a/10;
c=a%10;
d=b+c;
printf (sum of individual digits of given numbers is: %d, d);
getch( );
}
OUTPUT:
Enter a two digit number :45
sum of individual digits of given numbers is:9
7. Program to accept a three digit number and print the sum of individual digits.
# include <stdio.h>
# include <conio.h>
main( )
{
int a,b,c,n, sum;
clrscr( );
printf ( Enter a Three Digit Number:);
scanf (%d,&n);
a=n/100;
b=( (n%100)/10);
c=n%10;
sum=a+b+c;
printf ( Sum of Individual Digits of Given Numbers is: %d, Sum);
getch( );
}
OUTPUT:
Enter a Three Digit Number:165
Sum of Individual Digits of Given Numbers is:11
8. Program to accept a number and check the given number is Armstrong or not.
# include <stdio.h>
# include <conio.h>
main( )
{
int n, a, b, c, d;
clrscr( );
printf ( Enter a Three Digit Number: );
scanf (%d, &n);
a=n/100;
b=((n/10)%10);
c=n%10;
d=a*a*a*+b*b*b +c*c*c;
if (n= =d)
printf (The Given Number is Armstrong number);
else
13. Program to accept a string and print the reverse of the given string by using for loop.
# include <stdio.h>
# include <conio.h>
main( )
{
int i,j;
char name[80];
clrscr( );
printf( Enter a string);
gets(name);
for(i=0;i<80 && ((name [i]= getchar())!=\n);i++);
if(name[i]= =\n)
name[i]=\0;
for(j=i;j>=0;j--)
putchar(name[j]);
printf(is the reverse of given string);
getch( );
}
OUTPUT
Enter a string
ram
mar is the reverse of given string
IF
Program to find whether given no is prime or not
#include <stdio.h>
#include <math.h>
void main( )
{
int i, n, prime=1;
printf("Enter a number");
scanf("%d", &n);
for( i=2; i<= n-1; i++)
{
if( n % i = =0 ) {
prime =0;
break;
}
}
if( prime )
printf("%d is prime number !\n", n);
else
printf("%d isnt prime number!\n", n);
}
14. Program to find biggest of two no by using ternary operator( ternary operator ? : )
# include <stdio.h>
# include <conio.h>
main( )
{
int a,b,big;
clrscr( );
printf(enter value a);
scanf(%d,&a);
printf(enter the value of b);
scanf(%d,&b);
big=(a>b)?a:b;
printf(biggest of the given numbers is %d,big);
getch();
}
15. Program to find biggest of four no by using ternary operator
# include <stdio.h>
# include <conio.h>
main( )
{
int a,b,c,d,big;
clrscr( );
printf(enter value a);
scanf(%d,&a);
printf(enter the value of b);
scanf(%d,&b);
printf(enter the value of c);
scanf(%d,&c);
17. Program to accept a character in any case and print in another case.
# include <stdio.h>
# include <conio.h>
main( )
{
char ch,c1;
clrscr( );
printf(enter a char in anycase);
ch=getchar();
if(ch>=65 && ch<=90)
c1=ch+32;
else
if(ch>=97 && ch<=122)
c1=ch-32;
printf(the given char in anothercase is);
putchar(c1);
getch();
}
19. Program to accept a string and print it by using the while loop.
# include <stdio.h>
# include <conio.h>
main( )
{
char ch;
clrscr();
printf(enter a string);
while(( ch=getchar( ))!=\n)
putchar(ch);
getch();
}
20.C Program to accept a string in upper case and print it by lower case.
# include <stdio.h>
# include <conio.h>
main( )
{
char ch,c;
clrscr();
printf(enter a string in upper case:);
while(( ch=getchar( ))!=\n)
{
c=ch+32;
putchar(c);
}
printf( is in lower case);
getch( );
}
SWITCH CASE
21. Program to accept any single digit number and print it in words .
# include <stdio.h>
# include <conio.h>
main( )
{
int n;
clrscr( );
printf(enter a number :);
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;
case 9: printf(NINE);
break;
default:
printf(please enter the number between 0 and 9);
}
getch( );
}
21. b Program to count the number of words, characters, alphabets, vowels, consonants and
digit in a line
of text.
#include<stdio.h>
#include<conio.h>
main( )
{
int noa=0,nob=0,noc=0,nov=0,now=0,noch=0,l,I;
char ch,s[100];
clrscr( );
printf(enter 2 lines of text);
gets(s);
l=strlen(s);
for(i=0;i<1;i++)
{
switch(s[i])
{
case a:
case e:
case i:
case o:
case u:
case A:
case E:
case I:
case O:
case U:
nov++;
break;
}
if(isalpha(s[i]))
noa++;
if(isdigit(s[i]))
nod++;
if(noa[i]== ) && (noa[i+1]!= )
now++;
}
noch=l-nob;
noc=noa-nov;
printf(total no of words %d,now);
printf(total no of characters(without blanks)%d,noch);
printf(total no of characters(including blanks)%d,l);
printf(total no of alphabets %d,noa);
printf(total no of vowels %d,nov);
printf(total no of characters %d,noc);
printf(total no of digits %d,nod);
getch( );
}
FUNCTIONS
22. Program to accept two numbers and print sum of two numbers by using functions
# include <stdio.h>
# include <conio.h>
main( )
{ int a,b,c;
clrscr();
printf(enter the value for a:)
scanf(%d,&a);
printf(enter the value for b:)
scanf(%d,&b);
c=add(a,b);
printf(sum of two numbers is %d,c);
getch( );
}
int add(int x, int y)
{
int z;
z=x+y;
return z;
}
23. Program to accept a number and find factorial of given number using Function
# include <stdio.h>
# include <conio.h>
main( )
{
int n,f;
clrscr( );
printf(enter a number:)
scanf(%d,&n);
f= fact(n);
printf(factorial value is %d,f);
getch();
}
int fact(int n)
{
int i, fa=1;
for(i=n;i>=1;i--)
fa=fa*i;
return fa;
}
24. Program to accept a number and check the given number Armstrong or not using Functions
# include <stdio.h>
# include <conio.h>
main( )
{
int n,arm;
clrscr();
printf(enter any 3 digit number:)
scanf(%d,&n);
arm= armstrong(n);
if(arm= =n)
printf(%d is Armstrong number,n);
else
printf(%d not a Armstrong number,n);
getch( );
}
int Armstrong (int n)
{
int a,b,c,d;
a=n/100;
b=((n/10)%10);
c=n%10;
d=a*a*a+b*b*b+c*c*c;
return d;
}
25. Program to accept a string and find the length of the given string by using functions
# include <stdio.h>
# include <conio.h>
int getline(char str[]);
main( )
{
char str[80];
int length;
clrscr( );
printf( enter a string);
length=getline(str);
printf(length of the given string is %d,length);
getch ( );
}
int getline(char str[])
{
int i;
for(i=0;i<80&&((str[i]=getchar( ))!=\n); i++);
if(str[i]= =\n)
str[i]=\0;
return i;
}
ARRAYS
26. Program to accept values into two dimensional array and print .
# include <stdio.h>
# include <conio.h>
main( )
{
int a[3][3],i,j;
clrscr( );
for(i=0;i<=2;i++)
for(j=0;j<=2;j++)
{
printf( enter the value for a[%d][%d] :,i,j);
scanf(%d,&a[i][j]);
}
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
printf( %d:,a[i][j]);
printf(\n);
}
getch( );
}
31. Program to accept two numbers and print the sum of given two numbers by using pointers
# include <stdio.h>
# include <conio.h>
main( )
{
int a, b,c;
clrscr( );
a=10;
b=20;
c=*(&a)+*(&b);
printf(%d,c);
getch( );
}
32. C Program for printing book Details(like book name,quantity& price) using structures
# include<stdio.h>
# include<conio.h>
main( )
{
struct book
{
char name[50];
int quantity;
float price;
};
struct book b1,b2,b3;
main( )
{ clrscr( );
printf(enter name,quantity,price);
scanf(%s%d%f,&b1.name,&b1.quantity,&b1.price);
printf(enter name,quantity,price);
scanf(%s%d%f,&b1.name,&b1.quantity,&b1.price);
printf(enter name,quantity,price);
scanf(%s%d%f,&b3.name,&b3.quantity,&b3.price);
printf(the details are);
printf(\n %s%d%f,b1.name,b1.quantity,b1.price);
printf(\n %s%d%f,b2.name,e,b2.quantity,b2.price);
printf(\n %s%d%f,b3.name,b3.quanity,b3.price);
getch( );
}