Notes
Notes - notes.io |
#include <stdio.h>
int main()
{
int a[50],sum=0,i,n;
float avg;
printf("enter the number of elements in the array:");
scanf("%d",&n);
printf("enter the elements:n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
sum=sum+a[i];
}
avg=sum/n;
printf("sum is %dn",sum);
printf("average is %fn",avg);
return (0);
}
2) LINEAR SEARCH
#include <stdio.h>
void main()
{
int i,num, search, found = 0, a[15];
printf("Enter the number of elements: ");
scanf("%d", &num);
printf("Enter the elements n");
for (i = 0; i < num; i++)
{
scanf("%d", &a[i]);
}
printf("Enter the element to be searched ");
scanf("%d", &search);
for (i = 0; i < num ; i++)
{
if (search == a[i] )
{
found = 1;
break;
}
}
if (found == 1)
printf("Element is present in the array at position %d",i+1);
else
printf("Element is not present in the arrayn");
}
3) STRING COMPARISON
#include <stdio.h>
#include<string.h>
int main()
{
char str1[20];
char str2[20];
int value;
printf("Enter the first string : ");
scanf("%s",str1);
printf("Enter the second string : ");
scanf("%s",str2);
value=strcmp(str1,str2);
if(value==0)
printf("strings are same");
else
printf("strings are not same");
return 0;
}
4) NUMBER PALINDROME
#include <stdio.h>
int main()
{
int r,n,sum=0,temp;
printf("enter the number =");
scanf("%d",&n);
temp=n;
while(n>0)
{
r=n%10;
sum=(sum*10)+r;
n=n/10;
}
if(temp==sum)
printf("palindrome number");
else
printf("not palindrome");
return 0;
}
5) STRING PALINDROME WITHOUT STRING
#include<stdio.h>
int main()
{
char string[40];
int length=0, flag=1,i;
printf("Enter string:n");
scanf("%s",string);
for(i=0;string[i]!=' ';i++)
{
length++;
}
for(i=0;i<length/2;i++)
{
if( string[i] != string[length-1-i] )
{
flag=0;
break;
}
}
if(flag==1)
{
printf("PALINDROME");
}
else
{
printf("NOT PALINDROME");
}
return 0;
}
6) STRING CONCATENATION WITHOUT STRING FUNC
#include <stdio.h>
int main()
{
char str1[50], str2[50], i, j;
printf("nEnter first string: ");
scanf("%s",str1);
printf("nEnter second string: ");
scanf("%s",str2);
for(i=0; str1[i]!=' '; i++);
for(j=0; str2[j]!=' '; j++, i++)
{
str1[i]=str2[j];
}
str1[i]=' ';
printf("n Concatenated String is: %s",str1);
return 0;
}
7) EUCLIDEAN SUM
#include <stdio.h>
#include <math.h>
struct point
{
int x,y;
};
void main()
{
struct point p1,p2;
float distance,x,y;
printf("Enter the X coordinate of Point 1 :");
scanf("%d",&p1.x);
printf("Enter the Y coordinate of Point 1 :");
scanf("%d",&p1.y);
printf("Enter the X coordinate of Point 2 :");
scanf("%d",&p2.x);
printf("Enter the Y coordinate of Point 2 :");
scanf("%d",&p2.y);
x=p2.x-p1.x;
y=p2.y-p1.y;
printf("%f%f",x,y);
distance=sqrt((x*x)+(y*y));
printf("Distance : %2f",distance);
}
8) EMPLOYEE DETAILS
#include <stdio.h>
struct employee
{
char name[30];
int empid;
float salary;
};
void main ()
{
struct employee emp;
printf("nEnter details:n");
printf("Enter name:");
scanf("%s",emp.name);
printf("enetr ID:");
scanf("%d",&emp.empid);
printf("Enter salary:");
scanf("%f",&emp.salary);
printf("nEntered details is:n");
printf("Name:%sn",emp.name);
printf("ID:%dn",emp.empid);
printf("Salary:%fn",emp.salary);
}
9) PERSONAL DETAILS USING UNION
#include <stdio.h>
#include <string.h>
#define C_SIZE 20
union test
{
char name[C_SIZE];
char house[C_SIZE];
char city[C_SIZE];
char state[C_SIZE];
char pincode[C_SIZE];
};
void main()
{
union test t;
printf("Enter the name of person :n");
scanf("%s",t.name);
printf("The name of the person is : n");
puts(t.name);
printf("Enter the house name of person :n");
scanf("%s",t.house);
printf("The house of the person is : n");
puts(t.house);
printf("Enter the city of person :n");
scanf("%s",t.city);
printf("The city of the person is : n");
puts(t.city);
printf("Enter the state of person :n");
scanf("%s",t.state);
printf("The state of the person is : n");
puts(t.state);
printf("Enter the pincode of person :n");
scanf("%s",t.pincode);
printf("The pincode of the person is : n");
puts(t.pincode);
}
10) StRING REVERSE
#include <stdio.h>
void stringreverse(char* s)
{
char r[100];
int begin, end, count = 0;
printf("Input a stringn:n");
scanf("%s",s);
while (s[count] != ' ')
count++;
end = count - 1;
for (begin = 0; begin < count; begin++)
{
r[begin] = s[end];
end--;
}
r[begin] = ' ';
printf("Reverse of entered string is %sn",r);
}
void main()
{
char s[100];
stringreverse(s);
}
11) FACTORIAL OF NUMBER USING LOOP
#include <stdio.h>
int main()
{
int num, i, fact = 1;
printf("Enter a number to find factorialn");
scanf("%d",&num);
for(i = 1; i <= num; i++)
{
fact = fact * i;
}
printf("Factorial of %d is %dn", num, fact);
return 0;
}
|
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team