1. Program to multiply 2 number without using * operator
#include<stdio.h>#include<conio.h> // Linux user - Remove this int main() { // Variable for 2 numbers, and for result int a, b, r=0; // Inputting 2 integers printf("Enter two integers:"); scanf("%d %d",&a,&b); // Multiplying 2 numbers if(a>b) { while(b) { r=r+a; b--; } } else { while(a) { r=r+b; a--; } } // Displaying result printf("Product of two number:%d",r); getch(); // Linux user - Remove this return 0; }
2. Program to determine armstrong number
#include<stdio.h>#include<conio.h> // Linux user - Remove this int main() { // variable for a=numbern, n=to copy number, d=digit int a,n,d=0,sum=0; // Inputting number printf("Enter any number to determine whether it is armstorng or not:"); scanf("%d",&a); // copying number in n n=a; // Determining whether number is armstrong or not while(n!=0) { d=n%10; sum=sum+d*d*d; n=n/10; } // Displaying Whether number is armstrong or not if(a==sum) printf("Armstron no"); else printf("not armstrong"); getch(); // Linux user - Remove this return 0; }
3. Program to input time in seconds and convert them into hours, minutes and seconds and display it
#include<stdio.h> #include<conio.h> // Linux user - Remove this int main() { /* Variable for time in second, converted in hour, converted in minutes and converted in seconds, r for remainder */ int ts, ch=0, cm=0, cs, r=0; // Inputting time in second printf("Enter time in seconds:"); scanf("%d", &ts); // Converting in hours, minutes and seconds if(ts<60) cs=ts; else if(ts<3600) { cm=ts/60; cs=ts%60; } else if(ts>3600) { ch=ts/3600; r=ts%3600; if(r>60) { cm=r/60; r=r%60; } if(r<60) cs=r; } // Displaying seconds in hour, minutes and seconds printf("Time in hour minutes and seconds: %d/%d/%d",ch,cm,cs);
getch(); // Linux user - Remove this return 0; }
4. Program to determine palindrome number
#include<stdio.h>#include<conio.h> // Linux user - Remove this int main() { // variable for a=number, n=to copy number, d=digit, rev=reverse of number int a,n,d=0,rev=0; // Inputting number printf("Enter any number to determine whether it is Palindrome or not:"); scanf("%d",&a); // copying number in n n=a; // Determining whether number is palindrome or not while(n!=0) { d=n%10; rev=rev*10+d; n=n/10; } // Displaying Whether number is palindrome or not if(a==rev) printf("Palindrome number"); else printf("Not a Palindrome Number"); getch(); // Linux user - Remove this return 0; }
#include<stdio.>#include<conio.h> // Linux user - Remove this int main() { int i=0;
goto a; na: printf("Not allowed = %d\n",i); a: for(i=i+1;i<=35;i++) { if(i==15||i==30) goto na; else printf("Allowed =%d\n",i); } getch(); // Linux user - Remove this return 0; }
2 comments
commentsDesign a program that converts Celsius temperatures to Fahrenheit temperatures. The formula is as follows:
ReplyF = 9/5 C + 32
The program should ask the user to enter a temperature in Celsius, and then display the temperature converted to Fahrenheit.
(How would you do it in pseudocode?)
#include
Replyint main()
{
float c, f;
printf("Enter temperature in celcius : ");
scanf("%f",&c);
f=((9.0/5.0)*c)+32;
// %.2f means that only 2 digits should be displayed after decimal
printf("Temperature in fahrenheight : %.2f",f);
return 0;
}
PSEUDOCODE:
start
input degree in celcius
convert celcius to fahrenheight by formula f=((9.0/5.0)*c)+32;
display the converted value ( i.e f)
end
OR
start
declare variable c, f of float type
input c
f=((9.0/5.0)*c)+32;
display f
end