Proggramming Tutorials & Web Development Technologies - Tutorials for PHP,Laravel,Codeigniter,Yii,Bootstrap,Ajax,JQuery
Wednesday, 15 January 2014
Wednesday, 8 January 2014
C Program to print Product of Digits of a given number
/*
eg. 212=2*1*2=4
eg. 313=3*1*3=9
*/
eg. 212=2*1*2=4
eg. 313=3*1*3=9
*/
#include<stdio.h>
#include<conio.h>
void main()
{
int no,r,pt=1;
clrscr();
printf("Enter a no:");
scanf("%d",&no);
while(no>0)
{
r=no%10;
pt=pt*r;
no=no/10;
}
printf("Product of Digits= %d",pt);
getch();
}
C program to sort 10 Array elements in descending order Using Array
# include<stdio.h>
# include<conio.h>
void main()
{
int arr[10];
int i,j,temp;
clrscr();
for(i=0;i<10;i++)
scanf("%d",&arr[i]);
for(i=0;i<9;i++)
{
for(j=i+1;j<10;j++)
{
if(arr[i]<arr[j])
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
printf("\nSorted array elements :\n");
for(i=0;i<10;i++)
printf("%d ",arr[i]) ;
getch();
}
# include<conio.h>
void main()
{
int arr[10];
int i,j,temp;
clrscr();
for(i=0;i<10;i++)
scanf("%d",&arr[i]);
for(i=0;i<9;i++)
{
for(j=i+1;j<10;j++)
{
if(arr[i]<arr[j])
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
printf("\nSorted array elements :\n");
for(i=0;i<10;i++)
printf("%d ",arr[i]) ;
getch();
}
C Program to Reverse print an array
# include<stdio.h>
# include<conio.h>
void main()
{
int arr[10];
int i,j,temp;
clrscr();
for(i=0;i<10;i++)
scanf("%d",&arr[i]);
printf("\nPrinting an sorted array\n");
for(i=9;i>=0;i--)
printf("%d ",arr[i]) ;
getch();
}
C Program to Print Alternate Using Array
# include<stdio.h>
# include<conio.h>
void main()
{
int arr[10];
int i,j,temp;
clrscr();
for(i=0;i<10;i++)
scanf("%d",&arr[i]);
for(i=0;i<10;i+=2)
printf("%d ",arr[i]) ;
getch();
}
# include<conio.h>
void main()
{
int arr[10];
int i,j,temp;
clrscr();
for(i=0;i<10;i++)
scanf("%d",&arr[i]);
for(i=0;i<10;i+=2)
printf("%d ",arr[i]) ;
getch();
}
C Program print alternate element of an array
/*C Program to print alternate element of an array*/
# include<stdio.h>
# include<conio.h>
void main()
{
int arr[10];
int i,j,temp;
clrscr();
for(i=0;i<10;i++)
scanf("%d",&arr[i]);
for(i=0;i<10;i+=2)
printf("%d ",arr[i]) ;
getch();
}
# include<stdio.h>
# include<conio.h>
void main()
{
int arr[10];
int i,j,temp;
clrscr();
for(i=0;i<10;i++)
scanf("%d",&arr[i]);
for(i=0;i<10;i+=2)
printf("%d ",arr[i]) ;
getch();
}
C Program Accept 10 numbers and no. to search, print its occurrence Using Array
/* Accept 10 numbers and no. to search, print its occurence
Write a program to accept 10 no’s and a number to search and print how many times it occurs in array */
# include<stdio.h>
# include<conio.h>
void main()
{
int arr[10];
int i,cnt=0,tosearch;
clrscr();
/* accepting an array*/
for(i=0;i<10;i++)
{
printf("\n Enter %d number-",i);
scanf("%d",&arr[i]);
}
printf("\nEnter a number to be search-");
scanf("%d",&tosearch);
for(i=0;i<10;i++)
{
if(arr[i]==tosearch)
cnt++;
}
printf("\n Number occurs %d times",cnt);
getch();
}
Write a program to accept 10 no’s and a number to search and print how many times it occurs in array */
# include<stdio.h>
# include<conio.h>
void main()
{
int arr[10];
int i,cnt=0,tosearch;
clrscr();
/* accepting an array*/
for(i=0;i<10;i++)
{
printf("\n Enter %d number-",i);
scanf("%d",&arr[i]);
}
printf("\nEnter a number to be search-");
scanf("%d",&tosearch);
for(i=0;i<10;i++)
{
if(arr[i]==tosearch)
cnt++;
}
printf("\n Number occurs %d times",cnt);
getch();
}
Subscribe to:
Posts (Atom)