C PROG
# include
# include
main()
{
clrscr();
printf(“DSNR HYD”);
getch();
}
# include
# include
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();
}
3. Program To Accept Student Roll No, Marks in 3 Subjects and Calculate Total, Average and Print it.
# include
# include
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(“\n\n\t\t VIDYARTHI COMPUTERS – HANAMAKONDA \n\n”);
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 AVERAGE MARKS ; %d”, avg);
getch();
}
4. Program To Read Three Numbers And Print The Biggest Of Given Three Numbers
# include
# include
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( );}
# include
# include
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();
}
# include
# include
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();}
# include
# include
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 id %”, d);
8. Program to accept a three digit number and print the sum of individual digits.
# include
# include
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( );
# include
# include
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
printf (“The Given Number is Not Armstrong number”);
getch( );
10. Program to print ODD numbers from 1 to 10
# include
# include
main( )
{
int i;
clrscr( );
for (i=1; i<=10; i+=2)
printf(“%d\n”,i);
getch( );
# include
# include
main( )
{
int i;
clrscr( );
for (i=10; i>=1; i--)
printf(“%d\n”,i);
getch( );
}
# include
# include
main( )
{
int n,sum=0,i;
clrscr( );
for (i=1; i<=10; i++)
sum=sum+i;
printf(“sum of natural numbers from 1 to 10 is %d\n”,sum);
getch( );
}
# include
# include
main( )
{
int i,t;
clrscr( );
printf(“which table u want:”);
scanf(“%d”,&t);
for (i=1; i<=10; i++)
printf(“\n%d*%d=%d”,t,i,i*t);
getch( );
# include
# include
main( )
{
int i,j;
clrscr( );
for (i=1; i<=10; i++)
for(j=1;j<=10;j++)
printf(“\n%d*%d=%d”,i,j,i*j);
getch( );
}
# include
# include
main( )
{
int a=0,b=1,c=0,i;
clrscr( );
printf(“%d”,a);
printf(“\n%d”,b);
for (i=1; i<=10; i++)
{
c=a+b;
printf(“\n%d”,c);
a=b;
b=c;
}getch( );
}
# include
# include
main()
{int i,j;
clrscr( );
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
printf(“%d”,j);
printf(“\n”);
}
getch();
}
123451234123121#include <stdio.h>int main(){ int i, j; for(i=5;i>=1;i--) { for(j=1;j<=i;j++) { printf("%d",j); } printf("\n"); } return 0;}
17. Program to print numerical pyramid.
1
2 4
1 3 5
2 4 6 8
1 3 5 7 9
#include<stdio.h>
int main()
{
int i,j,k;
for(i=1;i<=5;i++)
{
if(i%2==0)
{
k=2;
}
else
{
k=1;
}
for(j=1;j<=i;j++,k+=2)
{
printf("%d ", k);
}
printf("\n");
}
return 0;
}
# include
# include
main( )
{int i,j ,l,k=40;
clrscr( );
for(i=1;i<=9;i+=2)
{for(l=1;l<=k;l++)
printf(“ “ );
for(j=1;j<=i;j++);
printf(“%d”,j);
printf(“\n”);
k=k-2;
}getch( );}
# include
# include
main( )
{int i,j,l,n,s,k=40;
clrscr( );
for(i=1;i<=9;i+=2)
{for(l=1;l<=k;l++)
printf(“ “);
for(j=1;j<=i;j++)
printf(“\n”);
k=k-2;
}k=k+4;
for(n=7;n>=1;n-=2)
{for(i=1;i<=k;i++)
printf(“ “);
for(s=1;s
printf(“%d”,s);
printf(“\n”);
k=k+2;
}getch( );}
# include
# include
main( )
{char i,j;
clrscr();
for(i=65;i<=70;i++)
{for(j=65;j<=i;j++)
printf(“%c”,j);
printf(“\n”);
}getch( );
}
# include
# include
main( )
{
char i,j,n,r;
int s,sp=40;
clrscr( );
for(i=65;i<=75;i+=2)
{for(s=1;s<=sp;s++)
printf(“ “);
for(j=65;j
printf(“%c”,j);
printf(“\n”);
sp=sp-2;
}sp=sp+4;
for(n=73;n>=65;n-=2)
{for(s=1;s<=sp;s++)
printf(“ “);
for(r=65;r<=n;r++)
printf(“%c”,r);
sp=sp+2;
}
getch( );
}
# include
# include
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();}
# include
# include
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);
printf(“enter the value of d”);
scanf(“%d”,&d);
big=(a>b)?(a>c)?(a>d)?a:d:(c>d)?c:d:(b>c)?(b>d)?b:d:(c>d)?c:d;
printf(“biggest of the given 4 numbers IS %d”,big);
getch();}
# include
# include
main( )
{int a,b,c,d,small;
clrscr( );
printf(“enter value a”);
scanf(“%d”,&a);
printf(“enter the value of b”);
scanf(“%d”,&b);
printf(“enter the value of c”);
printf(“enter the value of d”);
scanf(“%d”,&d);
small=(a
printf(“biggest of the given 4 numbers IS %d”,small);
getch();}
# include
# include
main( )
{int y,leap;
clrscr( );
printf(“enter any yr”);
scanf(“%d”,&y);
leap=(y%400= =0)?:(y%100!=0)?(y%4= =0)?1:0:0;
if(leap= =1)
printf(“ the given year is leap year”);
else
printf(“given year is not leap year);
getch( );
}
# include
# include
main( )
{char ch,c1;
clrscr( );
prntf(“enter a cha in uppercase”);
ch=getchar();
c1=ch+32;
prntf(“the given char in lowercasecase is”);
putchar(c1);
getch();}
# include
# include
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();
}
# include
# include
main( )
{int a=0;
clrscr();
while( a<10 o:p="">10>
{a=a+1;
printf(“%d\n”,a);
}getch();}
# include
# include
main( )
{char ch;
clrscr();
printf(“enter a string”);
while(( ch=getchar( ))!=’\n’)
putchar(ch);
getch();}
# include
# include
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( );
}
# include
# include
main( )
{
char ch;
clrscr( );
printf(“enter a string :”);
while(( ch=getchar( ))!=’\n’)
{
if(ch>=’A’ && ch<=’Z’)
putchar(ch+32);
else
if(ch>=’a’ && ch<=’z’)
putchar(ch-32);
else
putchar(ch);
}
printf(“ is the string”);
getch( );
}
# include
# include
main( )
{
char ch;
clrscr( );
printf(“enter a string :”);
while(( ch=getchar( ))!=’\n’)
{
putchar(ch);
if(ch= =’ ‘)
printf(“\n”);
}
getch( );
}
32. Program to accept a string and count no of capital letters, no. of small letters and no. of special characters
# include
# include
main( )
{
char ch;
int c=0,s=0,s1=0;
clrscr( );
printf(“enter a string :”);
while(( ch=getchar( ))!=’\n’)
{
if(ch>=’A’&& ch>=’Z’)
c=c+1;
else
if(ch>=’a’&& ch>=’z’)
s=s+1;
else
s1=s1+1;}
printf(“ no of capital letters are %d”,c);
printf(“ no of smal1 letters are %d”,s);
printf(“ no of special characters are %d”,s1);
getch( );
}
# include
# include
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( );
}
# include
# include
main( )
{
int n, i, check;
clrscr();
for(i=1;i<=100;i++)
{
check=1;
for(n=2;n<=i/2;n++)
if(i%n= =0)
{
check=0;
break;
}
if(check= =1)
printf(“\n %d is a prime”,i);
else
printf(“\n %d is not a prime”,i);
}
getch( );
}
35. Program to accept two numbers and print sum of two numbers by using functions
# include
# include
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;
}
# include
# include
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;
}
# include
# include
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;
}
# include
# include
main( )
{
int a,b,n;
clrscr( );
printf(“enter a number:”)
scanf(“%d”,&n);
a=rev(n);
printf(“REVERSE OF A GIVEN NUMBER IS %d”,a);
b=add(n,a);
printf(“\n sum of a given and reverse number is %d”,b);
getch( );
}
int rev( int n)
{
int r,rev=0,s;
while(n>0)
{
r=n%10;
rev=rev*10+r;
n=n/10;
}
return rev;
}
int add(int n, int a)
{
return n+a;
}
39. Program to accept 10 numbers and print first five numbers in original order and print last five numbers in reverse order.
# include
# include
main( )
{
int i,a[10];
for(i=0;i<10 i="" o:p="">10>
{
printf(“enter value for a[%d]”,i);
scanf(“%d”,&a[i]);
}
for(i=0;i<=4;i++)
printf(“\nA[%d]=%d”,i,a[i]);
for(i=9;i>=5;i--)
printf(“\nA[%d]=%d”,i,a[i]);
getch( );
}
# include
# include
main( )
{
int i,j;
char name[80];
clrscr( );
printf(“ enter a string”);
gets(name);
for(i=0;i<80 amp="" getchar="" i="" n="" name="" o:p="">80>
if(name[i]= =’\n’)
name[i]=’\0’;
for(j=i;j>=0;j--)
putchar(name[j]);
printf(“is the reverse of given string”);
getch( );
}
# include
# include
main( )
{
int i,lim,c,check=1;
char word[80];
clrscr( );
printf(“ enter a string”);
for(i=0;i<80 amp="" getchar="" i="" n="" o:p="" word="">80>
lim=i-1;
c=lim/2;
for(i=0;i<=0;i++,lim--)
if(word[i]!= word[lim])
{
check=0;
break;
}
if(check= =1)
printf(“the given string is palindrome “);
else
printf(“ not palindrome”);
getch( );
}
42.Program to accept values into 3 dimensional array and print .
# include
# include
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( );
}
# include
# include
main( )
{
int a[4][4],i,j,c;
clrscr( );
printf(“ enter which no u want”);
scanf(“%d”,&c);
for(i=0;i<4 i="" o:p="">4>
for(j=0;j<4 j="" o:p="">4>
if(i
a[i][j]=c;
else
a[i][j]=0;
for(i=0;i<4 i="" o:p="">4>
for(j=0;j<4 j="" o:p="">4>
{
printf(“ %d:”,a[i][j]);
printf(‘\n”);
}
getch( );
}
44. Program to accept two 3 dimensional array and store addition of those into arrays into the third array .
# include
# include
main( )
{
int a[3][3],b[3][3],c[3][3],i,j;
clrscr( );
for(i=0;i<3 i="" o:p="">3>
for(j=0;j<3 j="" o:p="">3>
{
printf(“enter the two values for a[%d][%d] & b[%d][%d]”, i,j,i,j);
scanf(“%d%d”,&a[i][j],&b[i][j]);
}
for(i=0;i<3 i="" o:p="">3>
{
for(j=0;j<3 j="" o:p="">3>
{
c[i][j]=a[i][j]+b[i][j];
printf(“%d”,c[i][j]);
}
printf(“\n”);
}
getch( );
}
# include
# include
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 amp="" getchar="" i="" n="" o:p="" str="">80>
if(str[i]= =’\n’)
str[i]=’\0’;
return i;
}
46. Program to count the number of words, characters, alphabets, vowels, consonants and digit in a line of text.
#include
#include
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="" o:p="">1>
{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( );
}
# include
# include
int getline (char line[ ], int lim );
int strc(char str1[ ], char str2[] );
main( )
{
char str1[80],str2[80];
int comp;
clrscr( );
printf(“enter first string:”);
getline(str1,80);
printf(“enter second string:”);
getline(str2,80);
comp=strc(str1,str2);
if(comp>0)
printf(“first string is bigger”);
else
if(comp==0)
printf(“both the strings are equal”);
getch( );
}
int getline(char str[], int lin)
{
int i;
for(i=0;i
if(str[i]=’\0’)
return i;
}
int strc(char str1[],char str2[])
{
int i;
for(i=0;str1[i];i++)
if(str1[i]!=str2[i])
return str1[i]-str2[i];
return str1[i]-str2[i];
}
# include
# include
main( )
{
int a[100],i,j,n,t;
clrscr( );
printf(“enter the array size”);
scanf(“%d”,&n);
for(i=1;i
scanf(“%d”,&a[i]);
for(i=1;i<=n;i++)
for(j=i+1;j
if(a[i]>a[j])
{
t=a[i]
a[i]=a[j];
a[j]=t;
}
printf(“the sorted elements are “);
for(i=1;i<=n;i++)
print(“%d”,a[i]);
getch( );
}
# include
# include
main( )
{
int month[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int d,m,y,nd,nm,ny,ndays;
clrscr( );
printf(“enter the date,month,year”);
scanf(“%d%d%d”,&d,&m,&y);
ndays=month[m-1];
if(m==2)
{
if(y%100==0)
{
if(y%400==0)
ndays=29;
}
else
if(y%4==0)
ndays=29;
}
nd=nd+1;
nm=m;
ny=y;
if(nd>ndays)
{
nd=1;
nm++;
}
if(nm>12)
{
nm=1;
ny++;
}
printf(“Given date is %d:%d:%d\n”,d,m,y);
printf(“next days date is %d:%d:%d”,nd,nm,ny);
getch( );
}
# include
# include
void interchange(int *x,int *y);
main( )
{int a,b;
clrscr( );
printf(“enter values of a and b”);
scanf(“%d%d”,&a,&b);
interchange(&a,&b);
}
void interchange(x,y)
int *x,*y;
{
int t;
t=*x;
*x=*y;
*y=t;
printf(“%d=x, %d=y”,*x,*y);
getch( );
}
Comments
Post a Comment