Elab 111
Elab 111
Elab 111
#include <stdio.h>
int main()
{
int i,a[10],sum=0;
for(i=0;i<3;i++)
scanf("%d",&a[i]);
sum=sum+(a[0]*60*60);
sum=sum+(a[1]*60);
sum=sum+(a[2]);
printf("%d",sum);
return 0;
}
Program which will accept string from the user and find the length of the string
#include <stdio.h>
#include<string.h>
int main()
{
char ch[20];
int i=0;
scanf("%s",ch);
while(ch[i]!='\0')
i++;
printf("%d",i);
return 0;
}
Swetha has a doubt in Mathematics. She has to find the sum value for the following
series. Your task is to write a code to find the sum of the following series
1+(1+2)+ (1+2+3)+ (1+2+3+4)++n
#include <stdio.h>
int main()
{
int i,j,x,sum,sum1;
scanf("%d",&x);
for(i=1;i<=x;i++)
{
sum1=0;
for(j=1;j<=i;j++)
sum1=sum1+j;
sum=sum+sum1;
}
printf("%d",sum);
return 0;
}
When parents take their kids for Engineering Counselling, they always go with a
preconceived notion that older the college, better will be the quality of education
offered. There is a help desk in front of the counselling hall to tell out of the
colleges in which seats are available, which college is the older one.
#include <stdio.h>
int main()
{
int c1,c2;
scanf("%d",&c1);
scanf("%d",&c2);
if(c1<c2)
printf("College 1 is older");
else
printf("College 2 is older");
return 0;
}
Selvan from SRM Public school is studying 3r grade in school, her maths mam gave
her a problem to convert the decimal number in octal and hexadecimal . Since her
mam gave so much problems to solves.She went to his brother who is computer
programmer and requested to create a program that converts automatically given
integer to decimal, octal and hexadecimal equivalent. Let us help an programmer to
do program?
#include <stdio.h>
int main()
{
int x;
scanf("%d",&x);
printf("Decimal value:%d\n",x);
printf("Octal value:%o\n",x);
printf("Hexadecimal value:%x\n",x);
return 0;
}
#include <stdio.h>
int main()
{
int x,i,sum,a=0,b=1;
scanf("%d",&x);
printf("%d ",a);
printf("%d",b);
for(i=0;i<(x-2);i++)
{
sum=a+b;
printf(" %d",sum);
a=b;
b=sum;
}
return 0;
}
The mathematics teacher has recently taught the formula for computing the distance
between 2 points to her students. She gave them an asssignment on calculating the
distance between the points. In order to prevent copying, she gave each student a
different set of questions. But she found it very difficult to correct all 100
assignments. She seeks your help. Can you please help her out?
#include <stdio.h>
#include<math.h>
int main()
{
int a[5],b[5],c[5],i;
float sum;
scanf("%d %d",&a[0],&a[1]);
scanf("%d %d",&b[0],&b[1]);
scanf("%d %d",&c[0],&c[1]);
sum=sqrt(((b[0]-a[0])*(b[0]-a[0]))+((b[1]-a[1])*(b[1]-a[1])));
printf("Length of side AB is %.1f\n",sum);
sum=sqrt(((c[0]-b[0])*(c[0]-b[0]))+((c[1]-b[1])*(c[1]-b[1])));
printf("Length of side BC is %.1f\n",sum);
sum=sqrt(((c[0]-a[0])*(c[0]-a[0]))+((c[1]-a[1])*(c[1]-a[1])));
printf("Length of side AC is %.1f",sum);
return 0;
}
#include <stdio.h>
int main()
{
float x,y;
scanf("%f",&x);
y=(x-32)*0.555556;
printf("%.2fC",y);
return 0;
}
Kamalas teacher give her mobile number in reverse order. She asks kamala to
rearrange the number using c program. Now kamala needs your help to write a c code
for reversing the number.
#include <stdio.h>
int main()
{
int sum=0,x,a;
scanf("%d",&x);
while(x!=0)
{
sum=sum*10;
a=x%10;
sum=sum+a;
x=x/10;
}
printf("%d",sum);
return 0;
}
Write a program that asks a user for their birth year encoded as two digits (like
"62") and for the current year, also encoded as two digits (like "99"). The program
is to correctly write out the users age in years.
#include <stdio.h>
int main()
{
int a[2];
scanf("%d",&a[0]);
scanf("%d",&a[1]);
if(a[0]>a[1])
{
printf("Your age is %d",((2000+a[1])-(1900+a[0])));
}
else
printf("Your age is %d",a[1]-a[0]);
return 0;
}
#include <stdio.h>
#include<string.h>
int main()
{
char ch[3];
scanf("%s",ch);
if(strcmp(ch,"A+")==0)
printf("4.0");
else if(strcmp(ch,"A")==0)
printf("4.0");
else if(strcmp(ch,"A-")==0)
printf("3.7");
else if(strcmp(ch,"B+")==0)
printf("3.3");
else if(strcmp(ch,"B")==0)
printf("3.0");
else if(strcmp(ch,"B-")==0)
printf("2.7");
else if(strcmp(ch,"C+")==0)
printf("2.3");
else if(strcmp(ch,"C")==0)
printf("2.0");
else if(strcmp(ch,"C-")==0)
printf("1.7");
else if(strcmp(ch,"D+")==0)
printf("1.3");
else if(strcmp(ch,"D")==0)
printf("1.0");
else
printf("0");
return 0;
}
John joined in his new college in chennai. The College is rated as one of the best
private university in India. On first day of his college, John teacher have asked
his personal details for data purposes. Kindly help john to perform the task using
coding.
#include <stdio.h>
int main()
{
int age,yp;
float per;
char name[10];
scanf("%s %d %f %d",name,&age,&per,&yp);
printf("Name:%s\n",name);
printf("Age:%d\n",age);
printf("Percentage:%.1f\n",per);
printf("Year of Passing:%d",yp);
return 0;
}
#include <stdio.h>
int main()
{
int n,x,i,j,flag;
scanf("%d",&n);
for(i=0;i<n;i++)
{
flag=0;
scanf("%d",&x);
for(j=2;j<x;j++)
{
if(x%j==0)
flag=1;
}
if(flag==0)
printf("yes\n");
else
printf("no\n");
}
return 0;
}
Raju maths teacher gave him a task of identifying the number name. If the number is
greater than 0 then he should utter to the teacher as "I am waiting". If the number
is less than 0 then he should utter the word as "I am not waiting".
#include <stdio.h>
int main()
{
int n;
scanf("%d",&n);
if(n>0)
printf("I am waiting");
else
printf("I am Not waiting");
return 0;
}
Puck, the trickster, has again started troubling people in your city. The people
have turned on to you for getting rid of Puck.
#include <stdio.h>
int main()
{
int n,x=0,a;
scanf("%d",&n);
while(n!=0)
{
x++;
n=n/10;
}
printf("%d",x);
return 0;
}
Jennys home work for Second day is to find subtraction of two numbers, help jenny
to solve the problem.
#include <stdio.h>
int main()
{
int a,b;
scanf("%d %d",&a,&b);
printf("The Subtraction of two number is:%d",a-b);
return 0;
}
Write a C Program to swap two variables without using third or temp variable
#include <stdio.h>
int main()
{
int a,b;
scanf("%d %d",&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf("Values after Swapping\n");
printf("value of a is:%d\n",a);
printf("value of b is:%d",b);
return 0;
}
Harinis home work for third day is to multiplication of two numbers, help Harini to
solve the problem
#include <stdio.h>
int main()
{
float a,b;
float x;
scanf("%f %f",&a,&b);
x=a*b;
printf("The Multiplication of two number is:%f\n",x);
printf("The Multiplication of two number is:%.2f",x);
return 0;
}