//PROGRAM TO STORE VOWELS OF FILE STRING TO ANOTHER FILE VOWELS
//Downloaded from www.c4cprog.co.nr
#include<stdio.h>
void main()
{
char c;
FILE *f,*f1;
f=fopen("STRING","w");
clrscr();
printf("Enter String :\n ");
while(scanf("%c",&c)!=EOF)
putw(c,f);
fclose(f);
f=fopen("STRING","r");
f1=fopen("VOWELS","w");
while((c=getw(f))!=EOF)
if((c=='a')||(c=='e')||(c=='i')||(c=='o')||(c=='u')||(c=='A')||(c=='E')||(c=='I')||(c=='O')||(c=='U'))
putw(c,f1);
fclose(f);
fclose(f1);
f1=fopen("VOWELS","r");
printf("\nVOWELS : \n");
while((c=getw(f1))!=EOF)
printf(" %c",c);
getch();
}
/*
OUTPUT
Enter String :
Program To Store The Vowels In A Paragraph To A File, Is Successfully Executed
^Z
VOWELS :
o a o o e e o e I A a a a o A i e I u e u E e u e
*/
Programs Can Also Be Downloaded From The Folders Below....[Or Scroll Down]
Showing posts with label Engg. Ist Year. Show all posts
Showing posts with label Engg. Ist Year. Show all posts
Store Vowels from one File to another
Click Here To Download C File Of This Program
Trigonometric Functions
Click Here To Download C File Of This Program
//Triginometric Functions
//Downloaded from www.c4cprog.co.nr
#include<conio.h>
#include<math.h>
void main()
{
float x;
char t;
clrscr();
printf("Enter the Value of X\n");
scanf("%f",&x);
x=(x*3.14)/180;
printf("\n\nEnter \ns For finding sin(x)\nc For finding cos(x)\nt For finding tan(x)\n\n");
scanf(" %c",&t);
switch (t)
{
case 'S':
case 's':
printf("\nThe Value is = %f",sin(x));
break;
case 'C':
case 'c':
printf("\nThe Value is = %f",cos(x));
break;
case 'T':
case 't':
printf("\nThe Value is = %f",tan(x));
break;
default:
printf("\nInvalid Choice");
}
getch();
}
Transpose a Matrix
Click Here To Download C File Of This Program
//TRANSPOSE A MATRIX
//Downloaded from www.c4cprog.co.nr
#include<conio.h>
void trans(int a[][100],int r,int c)
{
int i,j,t;
if(r==c)
{
printf("\n\nEnter Array :\n");
for(i=0;i<r;i++)
for(j=0;j<c;j++)
scanf("%d",&a[i][j]);
for(i=0;i<r;i++)
for(j=0;j<c;j++)
{
if(j>i)
{
t=a[i][j];
a[i][j]=a[j][i];
a[j][i]=t;
}
}
printf("\n\nArray After Transposing :");
for(i=0;i<r;i++)
{
printf("\n");
for(j=0;j<c;j++)
printf("\t%d",a[i][j]);
}
}
else
printf("\n\nUnsymmetrical Array - Transpose IMPOSSIBLE !!!");
}
void main()
{
int a[100][100],r,c,i,j ;
clrscr();
printf("\nEnter Array Row Limit :");
scanf("%d",&r);
printf("\nEnter Array Column Limit :");
scanf("%d",&c);
trans(a,r,c);
getch();
}
Swap using Pointers
Click Here To Download C File Of This Program
//PROGRAM TO SWAP TWO NOS USING POINTERS
//Downloaded from www.c4cprog.co.nr
#include<conio.h>
void swap(int *a,int *b)
{
int p;
p=*a;
*a=*b;
*b=p;
}
void main()
{
int a,b;
clrscr();
printf("\n\nEnter No 1 : ");
scanf("%d",&a);
printf("\n\nEnter No 2 : ");
scanf("%d",&b);
swap(&a,&b);
printf("\n\nSwapped Values");
printf("\n\n\nNo 1 is : %d ",a);
printf("\n\nNo 2 is : %d ",b);
getch();
}
/*
OUTPUT
Enter No 1 : 5
Enter No 2 : 9
Swapped Values
No 1 is : 9
No 2 is : 5
*/
Swap 2 nos. without using third variable
Click Here To Download C File Of This Program
//Program to Swap
//Downloaded from www.c4cprog.co.nr
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("\nEnter Nos. A & B\n");
scanf("%d%d",&a,&b);
c=a;
a=b;
b=c;
printf("\nThe Swapped Val : A=%d , B=%d ",a,b);
printf("\n\nMethod II \n");
printf("\n\n\nEnter Nos. A & B\n");
scanf("%d%d",&a,&b);
a=a-b;
b=a+b;
a=b-a;
printf("\nThe Swapped Val : A=%d , B=%d ",a,b);
getch();
}
Student Record using Structure
Click Here To Download C File Of This Program
//PROGRAM TO IMPLEMENT A STUDENT RECORD USNIG STRUCTURES
//Downloaded from www.c4cprog.co.nr
#include<conio.h>
struct student
{
char name[10],sub1[100],sub2[100],sub3[100];
int marks[3],total,rank;
float avg;
struct address
{
int houseno;
long int pcode,phno;
char city[10];
}addr;
}stu[10],temp;
void main()
{
int n,i,j;
char b;
clrscr();
printf("\n\nEnter Student Limit :\n\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
clrscr();
printf("\n\t\t\t\tStudent %d\n\n",i+1);
printf("\nEnter Student Name :");
scanf(" %s",stu[i].name);
printf("\nEnter House No :");
scanf("%d",&stu[i].addr.houseno);
printf("\nEnter City :");
scanf("%s",stu[i].addr.city);
printf("\nEnter Pincode :");
scanf("%ld",&stu[i].addr.pcode);
printf("\nEnter Phone No :");
scanf("%ld",&stu[i].addr.phno);
for(j=0;j<3;j++)
{
printf("\nEnter Mark Of Subject %d :",j+1);
scanf("%d",&stu[i].marks[j]);
stu[i].total=stu[i].total+stu[i].marks[j];
}
stu[i].avg=stu[i].total/3;
}
for(i=0;i<n;i++)
for(j=0;j<n-1;j++)
if(stu[j].total<stu[j+1].total)
{
temp=stu[j];
stu[j]=stu[j+1];
stu[j+1]=temp;
}
clrscr();
printf("\nRank | Name | H.No | City | P.Code | Ph.No | Mark1 | Mark2 | Mark 3 | Tot | Avg");
for(i=0;i<n;i++)
{
printf("\n\n%d",i+1);
printf("\t%s",stu[i].name);
printf("\t%d",stu[i].addr.houseno);
printf("\t%s",stu[i].addr.city);
printf("\t%ld",stu[i].addr.pcode);
printf("\t%ld",stu[i].addr.phno);
for(j=0;j<3;j++)
printf("\t%d ",stu[i].marks[j]);
printf("\t%d",stu[i].total);
printf(" %.1f",stu[i].avg);
}
getch();
}
/*
OUTPUT
Enter Student Limit : 2
Student 1
Enter Student Name :Sandy
Enter House No :1
Enter City :Mount
Enter Pincode :6854
Enter Phone No :1498
Enter Mark Of Subject 1 :89
Enter Mark Of Subject 2 :86
Enter Mark Of Subject 3 :87
Student 2
Enter Student Name :Steve
Enter House No :2
Enter City :Mount
Enter Pincode :6854
Enter Phone No :1306
Enter Mark Of Subject 1 :87
Enter Mark Of Subject 2 :86
Enter Mark Of Subject 3 :80
Rank | Name | H.No | City | P.Code | Ph.No | Mark1 | Mark2 | Mark 3 | Tot | Avg
1 Sandy 1 Mount 6854 1498 89 86 87 262 87.0
2 Steve 2 Mount 6854 1306 87 86 80 253 84.0
*/
Check for Strong No.
Click Here To Download C File Of This Program
//Check For Strong No.
//Downloaded from www.c4cprog.co.nr
#include<conio.h>
void strong(int n)
{
int i,s,t,p,x,j;
p=n;
s=0;
while(p>0)
{
x=p%10;
t=1;
for(j=1;j<=x;j++)
t=t*j;
s=s+t;
p=p/10;
}
if(s==n)
printf("\nThe No IS STRONG NO.");
else
printf("\nThe No IS NOT STRONG NO.");
}
void main()
{
int n;
clrscr();
printf("Enter The No : ");
scanf("%d",&n);
strong(n);
getch();
}
String Functions - Length, Concatenate, Reverse, Copy, Combine, Compare & Extract
Click Here To Download C File Of This Program
//PROGRAM TO ERFORM STRING FUNCTION - STRING LENGTH, COPY, CONCATENATE, REVERSE, COMBINE, EXTRACT & COMPARE
//Downloaded from www.c4cprog.co.nr
#include<conio.h>
void string_length()
{
int i=0;
char str[100];
gets(str);
printf("\n\nEnter The String : ");
gets(str);
while(str[i]!='\0')
i++;
printf("\n\nLENGTH Of The String is : %d Characters",i);
}
void string_concatenate()
{
int i=0,p=0;
char str1[100],str2[100];
gets(str1);
printf("\n\nEnter The String : ");
gets(str1);
printf("\nEnter The String B : ");
gets(str2);
while(str1[p]!='\0')
p++;
for(i=0;str2[i]!='\0';i++,p++)
str1[p]=str2[i];
printf("\n\nThe CONCATENATED String is : ");
for(i=0;i<p;i++)
printf("%c",str1[i]);
}
void string_reverse()
{
int i=0,p=0,q=0;
char str1[100],str2[100];
gets(str1);
printf("\n\nEnter The String : ");
gets(str1);
while(str1[p]!='\0')
p++;
for(i=p-1;i>=0;i--,q++)
str2[i]=str1[q];
printf("\n\nREVERSED String : ");
for(i=0;i<q;i++)
printf("%c",str2[i]);
}
void string_copy()
{
int i=0,p=0;
char str1[100],str2[100];
gets(str1);
printf("\n\nEnter The String : ");
gets(str1);
while(str1[p]!='\0')
p++;
for(i=0;i<p;i++)
str2[i]=str1[i];
printf("\n\nCOPIED String : ");
for(i=0;i<p;i++)
printf("%c",str2[i]);
}
void string_combine()
{
int i=0,p=0,j;
char str1[100],str2[100],str3[100];
gets(str1);
printf("\n\nEnter The String : ");
gets(str1);
printf("\nEnter The String B : ");
gets(str2);
while(str1[p]!='\0')
p++;
for(i=0;i<p;i++)
str3[i]=str1[i];
for(j=0;str2[j]!='\0';j++,i++)
str3[i]=str2[j];
printf("\n\nThe COMBINED String is : ");
for(j=0;j<i;j++)
printf("%c",str3[j]);
}
void string_compare()
{
int p=0,q=0,d=0,e=0,k=0,i,t;
char str1[100],str2[100];
gets(str1);
printf("\nEnter The String A : ");
gets(str1);
printf("\nEnter The String B : ");
gets(str2);
while(str1[p]!='\0')
p++;
while(str2[q]!='\0')
q++;
if(p>q)
t=p;
else
t=q;
for(i=0;i<t;i++,d=0,e=0)
{
d=str1[i];
e=str2[i];
if(d!=e)
{
k++;
printf("\n\nRESULT = %d | The Strings Are NOT EQUAL",d-e);
break;
}}
if(k==0)
printf("\n\nTHE STRINGS ARE EQUAL");
}
void string_extract()
{
int o,q,j,p=0,i,t;
char str[100],str1[100];
gets(str);
printf("\n\nEnter The String : ");
gets(str);
printf("\n\nEnter The Position From Which Extraction Is To Be Done : ");
scanf("%d",&o);
printf("\n\nEnter The Length Of The String To Be Extracted : ");
scanf("%d",&q);
while(str[p]!='\0')
p++;
if(p-o<q)
t=p-0;
else
t=q;
for(i=0;i<p;i++)
if(i==(o-1))
for(j=0;j<q;j++,i++)
str1[j]=str[i];
printf("\n\nThe EXTRACTED String is : ");
for(j=0;j<t;j++)
printf("%c",str1[j]);
}
void main()
{
int op;
char v;
do{
clrscr();
printf("\nOPTIONS :\n\t1.Length Of String\n\t2.Concatinating String\n\t3.Reversing String\n\t4.Copy String\n\t5.Combine Strings\n\t6.Comparing Strings\n\t7.Extracting String\n\n\nEnter Choice :");
scanf("%d",&op);
switch(op)
{
case 1:
string_length();
break;
case 2:
string_concatenate();
break;
case 3:
string_reverse();
break;
case 4:
string_copy();
break;
case 5:
string_combine();
break;
case 6:
string_compare();
break;
case 7:
string_extract();
break;
default:
printf("\n\nINVALID CHOICE !!!");
break;
}
printf("\n\n\n\nPress 'e' To EXIT & Any Other Key To Continue : ");
scanf(" %c",&v);
}while(v!='e');
}
/*
OUTPUT
OPTIONS :
1.Length Of String
2.Concatinating String
3.Reversing String
4.Copy String
5.Combine Strings
6.Comparing Strings
7.Extracting String
Enter Choice :1
Enter The String : Checking The Length
LENGTH Of The String is : 19 Characters
Press 'e' To EXIT & Any Other Key To Continue : c
OPTIONS :
1.Length Of String
2.Concatinating String
3.Reversing String
4.Copy String
5.Combine Strings
6.Comparing Strings
7.Extracting String
Enter Choice :2
Enter The String : Checking
Enter The String B : Concatination
The CONCATENATED String is : CheckingConcatination
Press 'e' To EXIT & Any Other Key To Continue : c
OPTIONS :
1.Length Of String
2.Concatinating String
3.Reversing String
4.Copy String
5.Combine Strings
6.Comparing Strings
7.Extracting String
Enter Choice :3
Enter The String : Checking String Reverse
REVERSED String : esreveR gnirtS gnikcehC
Press 'e' To EXIT & Any Other Key To Continue : c
OPTIONS :
1.Length Of String
2.Concatinating String
3.Reversing String
4.Copy String
5.Combine Strings
6.Comparing Strings
7.Extracting String
Enter Choice :4
Enter The String : Copying A String
COPIED String : Copying A String
Press 'e' To EXIT & Any Other Key To Continue : c
OPTIONS :
1.Length Of String
2.Concatinating String
3.Reversing String
4.Copy String
5.Combine Strings
6.Comparing Strings
7.Extracting String
Enter Choice :5
Enter The String : Testing
Enter The String B : For Combining Strings
The COMBINED String is : TestingFor Combining Strings
Press 'e' To EXIT & Any Other Key To Continue : c
OPTIONS :
1.Length Of String
2.Concatinating String
3.Reversing String
4.Copy String
5.Combine Strings
6.Comparing Strings
7.Extracting String
Enter Choice :6
Enter The String A : String Comparing
Enter The String B : Is Tested
RESULT = 10 | The Strings Are NOT EQUAL
Press 'e' To EXIT & Any Other Key To Continue : c
OPTIONS :
1.Length Of String
2.Concatinating String
3.Reversing String
4.Copy String
5.Combine Strings
6.Comparing Strings
7.Extracting String
Enter Choice :7
Enter The String : Sting Is To Be Extracted
Enter The Position From Which Extraction Is To Be Done : 2
Enter The Length Of The String To Be Extracted : 6
The EXTRACTED String is : ting I
Press 'e' To EXIT & Any Other Key To Continue : e
*/
Pascal pattern using '*'
Click Here To Download C File Of This Program
//PASCALS TRIANGLE Using STAR
//Downloaded from www.c4cprog.co.nr
#include<conio.h>
void main()
{
int p,g,n,i,m,l,j,q=0;
clrscr();
printf("\n\n\t Enter limit : ");
scanf("%d",&n);
while(q<n)
{
printf("\n");
for(i=40-3f*q;i>=0;i--)
printf(" ");
for(j=0;j<=q;j++)
{
if((j==0)||(q==0))
m=1;
else
m=m*(q-j+1)/j;
printf("* ");
}
q++;
}
getch();
}
String - Sort and Check for Palindrome
Click Here To Download C File Of This Program
//PROGRAM TO SORT GIVEN STRINGS & CHECK FOR PALINDROME
//Downloaded from www.c4cprog.co.nr
#include<conio.h>
#include<string.h>
void sort(char st[50][20],int n)
{ int i,j;
char k[50];
for(i=0;i<n;i++)
for(j=0;j<n-1;j++)
if(strcmp(st[j],st[j+1])>1)
{
strcpy(k,st[j]);
strcpy(st[j],st[j+1]);
strcpy(st[j+1],k);
}
for(i=0;i<n;i++)
{
printf("\nString %d :",i+1);
printf("%s",st[i]);
}
}
void palindrome(char st[50][20],int n)
{
int i,j,r=0;
char k[50];
for(i=0;i<n;i++)
{
strcpy(k,st[i]);
strrev(k);
if(strcmp(st[i],k)==0)
{
printf("\n\nString %d is Palindrome",i+1);
r++;
}}
if(r==0)
printf("\n\nNo Palindromes !!!");
}
void main()
{
int op,n,i;
char st[50][20],k[50],v;
do{
clrscr();
printf("\nEnter The no of Strings : ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nString %d :",i+1);
scanf("%s",&st[i]);
}
printf("\nOptions\n\n1.Sort String\n2.Check For Palindrome\n\nEnter Option :");
scanf("%d",&op);
switch(op)
{
case 1:
sort(st,n);
break;
case 2:
palindrome(st,n);
break;
default:
printf("\n\nWRONG CHOICE !!!");
break;
}
printf("\n\nPress 'e' To EXIT & Any Other Key To Continue : ");
scanf(" %c",&v);
}while(v!='e');
}
/*
OUTPUT
Enter The no of Strings : 3
String 1 :Testing
String 2 :The
String 3 :Program
Options
1.Sort String
2.Check For Palindrome
Enter Option :1
String 1 :Program
String 2 :Testing
String 3 :The
Press 'e' To EXIT & Any Other Key To Continue :c
Enter The no of Strings : 3
String 1 :MALAYALAM
String 2 :IS
String 3 :PALINDROME
Options
1.Sort String
2.Check For Palindrome
Enter Option :2
String 1 is Palindrome
Press 'e' To EXIT & Any Other Key To Continue : e
*/
Sine, Cosine & Exponential Series
Click Here To Download C File Of This Program
//SIN COSIN AND EXPONENTIAL SERIES
//Downloaded from www.c4cprog.co.nr
#include<conio.h>
void main()
{
int n,op,p,i,k,j,x;
float e,sum=0.0,temp=0.0,r;
clrscr();
printf("Enter Value of x :");
scanf("%d",&x);
r=(3.14*x)/180.0;
printf("\nEnter Value of n :");
scanf("%d",&n);
printf("\n\n\n\tEnter Choice :\t\n\n1.Sine Series\t\n2.Cosine Series\t\n3.Exponential Series\n\n");
scanf("%d",&op);
switch(op)
{
case 1:
sum=r;
temp=r;
for(i=3;i<=(2*n)-1;i=i+2)
{
temp=temp*-1.0*((r*r)/(i*(i-1.0)));
sum=sum+temp;
}
printf("\n\nSum = %f",sum);
break;
case 2:
sum=1.0;
temp=1.0;
for(i=2;i<=(2*n)-1;i=i+2)
{
temp=temp*-1.0*((r*r)/(i*(i-1.0)));
sum=sum+temp;
}
printf("\n\nSum = %f",sum);
break;
case 3:
temp=1.0;
sum=1.0;
e=1.0;
for(i=1;i<n;i++)
{
temp=temp*(x/e);
sum=sum+temp;
e++;
}
printf("\n\nSum = %f",sum);
break;
default :
printf("\n\n\t\t\t Invald Choice");
}
getch();
}
/*
Enter Value of x :5
Enter Value of n :2
Enter Choice :
1.Sine Series
2.Cosine Series
3.Exponential Series
1
Sum = 0.087112
2
Sum = 0.99616
3
Sum = 6.00000
*/
Series
Click Here To Download C File Of This Program
//1-1/(2*3)+1/(3*4)......
//Downloaded from www.c4cprog.co.nr
#include<conio.h>
#include<math.h>
void main()
{
int i,n;
float sum=1;
clrscr();
printf("Enter The Value Of N :");
scanf("%d",&n);
for(i=2;i<=n;i++)
sum=sum+(1/(i*(i+1.0))*(pow(-1,(i+1))));
printf("\n\n\tSum = %f",sum);
getch();
}
Compute Quadratic Equation
Click Here To Download C File Of This Program
//Program to Compute Quadratic Equations
//Downloaded from www.c4cprog.co.nr
#include<conio.h>
#include<math.h>
void main()
{
int a,b,c,d;
float r1,r2;
clrscr();
printf("\nEnter the Values of the coefficients a,b,c : \n");
scanf("%d%d%d",&a,&b,&c);
d=(b*b)-(4*a*c);
if(d==0)
{
printf("\nThe Roots are REAL & EQUAL\nRoots Are : \n");
r1=(-b)/(2.0*a);
r2=r1;
printf("1)%f 2)%f",r1,r2);
}
else
{
if(d>0)
{
printf("\nThe Roots are REAL & DISTINCT\nRoots are : \n");
r1=((-b)+sqrt(d))/(2.0*a);
r2=((-b)-sqrt(d))/(2.0*a);
printf("1)%f 2)%f",r1,r2);
}
else
{
printf("\nThe Roots are IMAGINARY\nRoots Are : \n");
d=-d;
r1=(-b)/(2.0*a);
r2=(sqrt(d))/(2.0*a);
printf("1)%f+i%f",r1,r2);
printf("2)\n%f-i%f",r1,r2);
}
}
getch();
}
/*
Enter the Values of the coefficients a,b,c :
1
-4
4
The Roots are REAL & EQUAL
Roots Are :
1)2.000000 2)2.000000
*/
Prime Nos. till limit
Click Here To Download C File Of This Program
//Prime Nos Till Limit
//Downloaded from www.c4cprog.co.nr
#include<conio.h>
void main()
{
int n,i,p=0,j;
clrscr();
printf("Enter Limit :");
scanf("%d",&n);
printf("\n Prime Nos are : ");
for(i=2;i<=n;i++)
{ p=0;
for(j=2;j<=i/2;j++)
{
if((i%j)==0)
p++;
r}
if(p==0)
printf("%d ",i);
}
getch();
}
Sort & Search using Pointers
Click Here To Download C File Of This Program
//PROGRAM TO SORT GIVEN ARRAY OF NUMBERS & SEARCH GIVEN NO USING POINTERS
//Downloaded from www.c4cprog.co.nr
#include<conio.h>
void sort(int *g,int n)
{
int i,j,b;
printf("\nSorted Array :");
for(i=0;i<n;i++)
for(j=0;j<n-1;j++)
if(*(g+j)>*((g+j)+1))
{
b=*(g+j);
*(g+j)=*((g+j)+1);
*((g+j)+1)=b;
}
for(i=0;i<n;i++)
printf("\n%d",*(g+i));
}
void search(int *g,int n)
{
int u,mid,l,k=0,x;
printf("\n\nEnter Element To Be Searched For :");
scanf("%d",&x);
u=n-1;
l=0;
while(l<=u)
{
mid=((u+l)/2);
if(*(g+mid)>x)
u=mid-1;
if(*(g+mid)<x)
l=mid+1;
if(*(g+mid)==x)
{
printf("\n\nElement Is Found At Position %d",mid+1);
k++;
break;}
}
if(k==0)
printf("\nElemnt NOT FOUND !!!");
}
void main()
{
int x,a[100],*g,i,n,k,op;
char v;
clrscr();
do{
printf("\n\nEnter Limit :");
scanf("%d",&n);
printf("\nEnter Array :\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
g=&a[0];
sort(g,n);
search(g,n);
printf("\n\nPress 'e' To EXIT & Any Other Key To CONTINUE :");
scanf(" %c",&v);
}while(v!='e');
}
/*
OUTPUT
Enter Limit :5
Enter Array :
4
1
5
7
4
Sorted Array :
1
4
4
5
7
Enter Element To Be Searched For :4
Element Is Found At Position 4
Press 'e' To EXIT & Any Other Key To CONTINUE :e
*/
Floyds Triangle
Click Here To Download C File Of This Program
//Floyds Triangle Pattern
//1
//23
//456
//Downloaded from www.c4cprog.co.nr
#include<conio.h>
void main()
{
int i,j,k=1,n;
clrscr();
printf("Enter Limit :");
scanf("%d",&n);
printf("\n\n\tFLOYDS TRAINGLE :\n");
for(i=1;i<=n;i++)
{
printf("\n");
for(j=1;j<=i;j++,k++)
printf("\t%d",k);
}
getch();
}
/*
Enter Limit : 4
FLOYDS TRAINGLE :
1
1 2
4 5 6
7 8 9 10
*/
Pattern
Click Here To Download C File Of This Program
//Pattern
//1
//12
//1
//Downloaded from www.c4cprog.co.nr
#include<conio.h>
void main()
{
int n,i,j,k;
clrscr();
printf("\nEnter Limit :");
scanf("%d",&n);
k=n-1;
for(i=1;i<=(2*n)-1;i++)
{
printf("\n");
if(i<=n)
{
for(j=1;j<=i;j++)
printf("%d ",j);
}
if(i>n)
{
for(j=1;j<=k;j++)
{printf("%d ",j);}
k--;
}
}
getch();}
Pascals Triangle
Click Here To Download C File Of This Program
//PASCALS TRIANGLE
//Downloaded from www.c4cprog.co.nr
#include<conio.h>
void main()
{
int p,g,n,i,m,l,j,q=0;
clrscr();
printf("\n\n\t Enter limit : ");
scanf("%d",&n);
while(q<n)
{
printf("\n");
for(i=40-3*q;i>=0;i--)
printf(" ");
for(j=0;j<=q;j++)
{
if((j==0)||(q==0))
m=1;
else
m=m*(q-j+1)/j;
printf("%6d",m);
}
q++;
}
getch();
}
Check For Palindrome
Click Here To Download C File Of This Program
//Check For Palindrome
//Downloaded from www.c4cprog.co.nr
#include<conio.h>
#include<math.h>
void main()
{
long int a,i=0,n,s,g,sum;
clrscr();
printf("Enter The No. : ");
scanf("%ld",&a);
n=a;
g=a;
while(a>0)
{ a=a/10;
i++; }
sum=0;
while(n>0)
{
s=n%10;
sum=sum+s;
s=s*(pow(10,i-1));
a=a+s;
i--;
n=n/10;
}
if(a==g)
printf("\nThe No.is Palindrome");
else
printf("\nThe No.is not Palindrome");
printf("\nThe Reverse of No is %ld",a);
printf("\nThe Sum of Digits is %ld",sum);
getch();
}
Predict Output
Click Here To Download C File Of This Program
//Output of Integers
//Downloaded from www.c4cprog.co.nr
#include<conio.h>
void main()
{
int m=12345;
long int n=9876543;
clrscr();
printf("%d\n",m);
printf("%10d\n",m);
printf("%010d\n",m);
printf("%-10d\n",m);
printf("%10ld\n",n);
printf("%10ld\n",-n);
getch();
}
Subscribe to:
Posts (Atom)
