Stop Thinking Start Learning.
Home
Archives for July 2019
Wednesday, July 31, 2019
Monday, July 29, 2019
Sunday, July 28, 2019
Saturday, July 27, 2019
Revers String without strrev() function
Author Saumil Rana
publish July 27, 2019
Revers String without strrev() function:
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k;
char str[100];
char rev[100];
clrscr();
printf("Enter A String:-");
gets(str);
for(i=0;str[i]!='\0';i++)
{
}
// printf("The Original String is%d\n",i);
k = i;
for(j=0;j<=k;j++ , i--)
{
rev[j]=str[i];
printf("%c" , str[i]);
}
printf("The Revers String is %s\n",rev);
getch();
}
Output:
String in strcpy() function
Author Saumil Rana
publish July 27, 2019
String in strcpy() function:
The strcpy() function is defined in <string.h> header file.
The strcpy() function copies the string pointed by source
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[20]="cprograms";
char b[20];
char c[20];
clrscr();
strcpy(b,a);
strcpy(c,"hii");
puts(b);
puts(c);
getch();
}
Output:
String in strcmp() function
Author Saumil Rana
publish July 27, 2019
String in strcmp() function:
in cproframs strcmp() function are Depended Ascii Value.
0:if both strings are identical (equal)
negative: if the ASCII value of first unmatched character is less than second.
positive integer:if the ASCII value of first unmatched character is greater than second.
#include<stdio.h>
#include<conio.h>
void main()
{
char name[]="abcd",name1[]="abcD",name2[]="abcd";
int result;
clrscr();
result=strcmp(name,name1);
printf("strcmp(name and name1)=%d\n",result);
result=strcmp(name,name2);
printf("strcmp(name and name2)=%d\n",result);
getch();
}
Output:
string len()function find length
Author Saumil Rana
publish July 27, 2019
string len()function find length:
#include<conio.h>
void displaylen(char length[]);
void main()
{
char name[20];
clrscr();
printf("Enter Your Name :- ");
gets(name);
displaylen(name);
getch();
}
void displaylen(char length[])
{
int len;
len=strlen(length);
printf("length is %d",len);
}
Output:
passing string to a function print the name
Author Saumil Rana
publish July 27, 2019
passing string to a function print the name.
#include<stdio.h>
#include<conio.h>
void displayname(char name1[]);
void main()
{
char string[20];
clrscr();
printf("Enter Your Name:-");
gets(string);
displayname(string); // Passing The Function..
getch();
}
void displayname(char name1[])
{
puts(name1); //
}
Output:
string print the name
Author Saumil Rana
publish July 27, 2019
String print the name.
// Include<string.h> including header file.
#include<stdio.h>
#include<conio.h>
void main()
{
char name1[20];
clrscr();
printf("Enter Your Name :-");
scanf("%s",&name1);
puts(name1);
getch();
}
Output:
print the name with puts() and gets().
gets() and scanf() both are used to received input from the users.but gets() are show full string.
#include<stdio.h>
#include<conio.h>
void main()
{
char name1[20];
clrscr();
printf("Enter Your Name :-");
gets(name1);
puts(name1);
getch();
}
Output:
Thursday, July 25, 2019
Find HCF(gcd) of two number
Author Saumil Rana
publish July 25, 2019
Tags
Find HCF(gcd) of two number:
#include<stdio.h>
#include<conio.h>
void main()
{
int i,num1,num2,temp,HCF=1;
clrscr();
printf("Enter Any Two Numbers To Find HCF:- ");
scanf("%d%d",&num1,&num2);
temp=(num1<num2)?num1:num2;
for(i=1;i<=temp;i++)
{
if(num1%i==0 && num2%i==0)
{
HCF=i;
}
}
printf("HCF of %d and %d=%d\n",num1,num2,HCF);
getch();
}
Output:
Find LCM of two number
Author Saumil Rana
publish July 25, 2019
Tags
Find LCM of Two Number:
#include<stdio.h>
#include<conio.h>
void main()
{
int i,num1,num2,max,LCM;
clrscr();
printf("Enter Any Two Numbers To Find LCM:- ");
scanf("%d%d",&num1,&num2);
max=(num1>num2)?num1:num2;
for(i=0;i<max;i++)
{
if(max%num1==0 && max%num2==0)
{
LCM=max;
break;
}
max++;
}
printf("\n LCM of The Two Number=%d",LCM);
getch();
}
Output:
c program to uppercase and lowercase.
Author Saumil Rana
publish July 25, 2019
Tags
c program to uppercase and lowercase:
//check the number uppercase or lower case
#include<stdio.h>
#include<conio.h>
void main()
{
char no;
clrscr();
printf("Enter Your Number :- ");
scanf("%c",&no);
if(no>='A'&& no<='Z')
{
printf("Upper Case %c",no);
}
else if(no>='a' && no<='z')
{
printf("Lower Case %c",no);
}
else
{
printf("Not Alphabet.");
}
getch();
}
Output:
input any character and check whether is alphabet,digit,or special character.
Author Saumil Rana
publish July 25, 2019
Tags
input any character and check whether is alphabet,digit,or special character:
//check Your Number Is alphabet,numeric And Special Character.
#include<stdio.h>
#include<conio.h>
void main()
{
char no;
clrscr();
printf("Enter Your Number:-");
scanf("%c",&no);
if((no>= 'a' && no<='z') ||(no>='A' && no<='Z'))
{
printf("Your Number Is Alphabet %c",no);
}
else if(no>='0' && no<='9')
{
printf("Your Number is Numeric %c",no);
}
else
{
printf("Your Number is Special Character");
}
getch();
}
Output:
c programing in Enter your marks to know your grade.
Author Saumil Rana
publish July 25, 2019
Tags
C programing in Enter your marks to know your grade:
//Enter Your Marks And know to your grade.
#include<stdio.h>
#include<conio.h>
void main()
{
int marks;
clrscr();
printf("Enter marks to know your grade:-");
scanf("%d",&marks);
if(marks<35)
{
printf("Fail");
}
else if(marks>=35 && marks<40)
{
printf("grade C");
}
else if(marks>=40 && marks<60)
{
printf("grad B");
}
else if(marks>=60 && marks<80)
{
printf("grad A");
}
else
{
printf("grade A+");
}
getch();
}
Output:
c program to your age is eligable for vote or not.
Author Saumil Rana
publish July 25, 2019
Tags
c program to your age is eligable for vote or not.
//check your age is aligable for vote.
#include<stdio.h>
#include<conio.h>
void main()
{
int age;
clrscr();
printf("Enter Your Age :-");
scanf("%d",&age);
if(age>=18)
{
printf("Your Age is Eligible for vote..");
}
else
{
printf("!lSorry You are not eligible for vote");
}
getch();
}
Output:
write a c program to check gender male or female.
Author Saumil Rana
publish July 25, 2019
Tags
write a c program to check gender male or female.
//check gender are you male or femaleusing or(||) Operator.
#include<stdio.h>
#include<conio.h>
void main()
{
char gen;
clrscr();
printf("Are You is a Male(y/n):");
scanf("%c",&gen);
if(gen=='y' || gen=='Y')
{
printf("Male");
}
else if(gen=='n' || gen=='N')
{
printf("Female");
}
else
{
printf("Invalid Choice");
}
getch();
}
Output:
Subscribe to:
Posts (Atom)