In: Computer Science
IN C LANGUAGE ONLY PLEASE!
First Program:
Second Program:
Third program:
First Program -
Code -
#include <stdio.h>
int main( int argc, char *argv[] ) {
//print name 10 time using for loop
for(int i = 0 ; i < 10; i++)
//argv[1] is first name and argv[2] is last name
printf("%s %s\n", argv[1],argv[2]);
//count character in first name
int firstNameCharCount = 0;
//using for loop iterate till argv[1][i] not equal to '\0'
for (int i = 0; argv[1][i] != '\0'; ++i)
//incremenet firstNameCharCount
firstNameCharCount++;
//similarly count char in second name
int secondNameCharCount = 0;
for (int i = 0; argv[2][i] != '\0'; ++i)
secondNameCharCount++;
//compare character count , if firstNameCharCount is greater than
secondNameCharCount
//then print my first name is bigger than my last name
if(firstNameCharCount>secondNameCharCount){
printf("my first name is bigger than my last name");
}
//compare character count , if secondNameCharCount is greater than
firstNameCharCount
//then print my last name is bigger than my first name
else if(firstNameCharCount<secondNameCharCount){
printf("my last name is bigger than my first name");
}
//if both are equal
else if(firstNameCharCount==secondNameCharCount){
printf("my first and last name have the same number of
characters.");
}
}
Screenshots -
pls ask multiple question in different part , we are told to answer first only in case of multiple question , pls do give a like ,thank you