1. Write a c program to reverse any number.
2. Write a c program to find out sum of digit of given number.
2. Write a c program to find out sum of digit of given number.
10. Write a c program to find out NCR factor of given number.
11. How to convert string to int without using library functions in c
12. Program in c to print 1 to 100 without using loop
13. C program for swapping of two numbers
14. Program to find largest of n numbers in c
15. Split number into digits in c programming
16. C program to count number of digits in a number
11. How to convert string to int without using library functions in c
12. Program in c to print 1 to 100 without using loop
13. C program for swapping of two numbers
14. Program to find largest of n numbers in c
15. Split number into digits in c programming
16. C program to count number of digits in a number
12 comments:
while(str[i]!='\0'){
if(str[i]< 48 || str[i] > 57){
printf("Unable to convert it into integer.\n");
return 0;
}
else{
sum = sum*10 + (str[i] - 48);
i++;
}
for this part, i do not understand the str[i] is smaller than 48 and larger than 57?
Can you explain it again?
str[i] will return ASCII value of that character. ASCII value of '0' is 48 and '9' is 57.
can any one write the full c program for day number for example 04-feb-2012 must be printed as 35 2012
means jan as 31 days so 31+4=35
how can i print prime number in if else condition with out using loop;
may i put
sum = sum*10 + (str[i] );
instead of
sum = sum*10 + (str[i] - 48); ?
and here 48 means 0?
c++ please?
Space thakle sehulo ashhbe kivabe?
#include
int prime(int y);
int main()
{
int n,x;
printf("enter number");
scanf("%d",&n);
x=prime(n);
if(x==1)
printf("%d is a prime number",n);
else
printf("%d is not a prime number",n);
}
int prime(int y)
{
static int count=0,i=2;
if(y>=i)
{
if(y%i==0)
count++;
i++;
prime(y);
}
return(count);
}
OUTPUT:-
enter number 5
5 is a prime number
#include
int prime(int y);
int main()
{
int n,x;
printf("enter number");
scanf("%d",&n);
x=prime(n);
if(x==1)
printf("%d is a prime number",n);
else
printf("%d is not a prime number",n);
}
int prime(int y)
{
static int count=0,i=2;
if(y>=i)
{
if(y%i==0)
count++;
i++;
prime(y);
}
return(count);
}
OUTPUT:-
enter number 5
5 is a prime number
#include
int main()
{
char a[12]={'jan','feb','mar','april','may','june','july','aug','sep','oct','nov','dec'};
int sum=0,month,day,year,i;
printf("enter day");
scanf("%d",&day);
printf("enter month");
scanf("%d",&month);
printf("enter year");
scanf("%d",&year);
printf("%d-%d-%d",day,month,year);
for(i=1;i<=month-1;i++)
{
switch(i)
{
case 1:if(i==1)
sum+=31;
break;
case 2:if(i==2)
{
if(year%4==0)
sum+=29;
else
sum+=28;
}
break;
case 3:if(i==3)
sum+=31;
break;
case 4:if(i==4)
sum+=30;
break;
case 5:if(i==5)
sum+=31;
break;
case 6:if(i==6)
sum+=30;
break;
case 7:if(i==7)
sum+=31;
break;
case 8:if(i==8)
sum+=31;
break;
case 9:if(i==9)
sum+=30;
break;
case 10:if(i==10)
sum+=31;
break;
case 11:if(i==11)
sum+=30;
break;
case 12:if(i==12)
sum+=31;
break;
default :
break;
}
}
sum+=day;
printf("sum of days:%d",sum);
}
/*OUTPUT:-
enter day 06
enter month 04
enter year 1996
sum of days:97*/
#include
int main()
{
char a[12]={'jan','feb','mar','april','may','june','july','aug','sep','oct','nov','dec'};
int sum=0,month,day,year,i;
printf("enter day");
scanf("%d",&day);
printf("enter month");
scanf("%d",&month);
printf("enter year");
scanf("%d",&year);
printf("%d-%d-%d",day,month,year);
for(i=1;i<=month-1;i++)
{
switch(i)
{
case 1:if(i==1)
sum+=31;
break;
case 2:if(i==2)
{
if(year%4==0)
sum+=29;
else
sum+=28;
}
break;
case 3:if(i==3)
sum+=31;
break;
case 4:if(i==4)
sum+=30;
break;
case 5:if(i==5)
sum+=31;
break;
case 6:if(i==6)
sum+=30;
break;
case 7:if(i==7)
sum+=31;
break;
case 8:if(i==8)
sum+=31;
break;
case 9:if(i==9)
sum+=30;
break;
case 10:if(i==10)
sum+=31;
break;
case 11:if(i==11)
sum+=30;
break;
case 12:if(i==12)
sum+=31;
break;
default :
break;
}
}
sum+=day;
printf("sum of days:%d",sum);
}
/*OUTPUT:-
enter day 06
enter month 04
enter year 1996
sum of days:97*/
Post a Comment